From be507421b1a0a7107fb9a6653129e21812d9b6cd Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Mon, 15 Apr 2024 15:24:57 +0000 Subject: [PATCH] . --- package.json | 4 +- .../__tests__/upload-artifact.test.ts | 57 +++++++++++++++---- packages/http-client/package-lock.json | 2 +- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 88034664..d394979b 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "lint": "eslint packages/**/*.ts", "lint-fix": "eslint packages/**/*.ts --fix", "new-package": "scripts/create-package", - "test": "jest --testTimeout 60000" + "test": "jest --testTimeout 70000" }, "devDependencies": { "@types/jest": "^29.5.4", @@ -33,4 +33,4 @@ "ts-jest": "^29.1.1", "typescript": "^5.2.2" } -} +} \ No newline at end of file diff --git a/packages/artifact/__tests__/upload-artifact.test.ts b/packages/artifact/__tests__/upload-artifact.test.ts index c98114d6..afe4bca6 100644 --- a/packages/artifact/__tests__/upload-artifact.test.ts +++ b/packages/artifact/__tests__/upload-artifact.test.ts @@ -9,8 +9,8 @@ import {uploadArtifact} from '../src/internal/upload/upload-artifact' import {noopLogs} from './common' import {FilesNotFoundError} from '../src/internal/shared/errors' import {BlockBlobClient} from '@azure/storage-blob' -import fs from 'fs' -import {Readable} from 'stream' +import * as fs from 'fs' +import * as path from 'path' describe('upload-artifact', () => { beforeEach(() => { @@ -357,14 +357,47 @@ describe('upload-artifact', () => { it('should throw an error uploading blob chunks get delayed', async () => { const mockDate = new Date('2020-01-01') + // const root = path.join('/home/user/files/') + const dirPath = path.join(__dirname, `plz-upload`) - // Mock fs.createReadStream to return a mock stream - fs.createReadStream = jest.fn().mockImplementation(() => { - const mockStream = new Readable() - mockStream.push('file content') - mockStream.push(null) - return mockStream - }) + // const filePath = path.join(dirPath, 'file1.txt') + // const root = '/home/user/files' + if (!fs.existsSync(dirPath)) { + fs.mkdirSync(dirPath, {recursive: true}) + // fs.mkdirSync(path.join(dirPath, 'file1.txt'), {recursive: true}) + } + + // Now write the file + // eslint-disable-next-line @typescript-eslint/await-thenable + await fs.writeFile( + path.join(dirPath, 'file1.txt'), + 'test file content', + err => { + if (err) { + throw err + } + } + ) + // eslint-disable-next-line @typescript-eslint/await-thenable + await fs.writeFile( + path.join(dirPath, 'file2.txt'), + 'test file content', + err => { + if (err) { + throw err + } + } + ) + // eslint-disable-next-line @typescript-eslint/await-thenable + await fs.writeFile( + path.join(dirPath, 'file3.txt'), + 'test file content', + err => { + if (err) { + throw err + } + } + ) jest .spyOn(uploadZipSpecification, 'validateRootDirectory') @@ -373,15 +406,15 @@ describe('upload-artifact', () => { .spyOn(uploadZipSpecification, 'getUploadZipSpecification') .mockReturnValue([ { - sourcePath: '/home/user/files/plz-upload/file1.txt', + sourcePath: path.join(dirPath, 'file1.txt'), destinationPath: 'file1.txt' }, { - sourcePath: '/home/user/files/plz-upload/file2.txt', + sourcePath: path.join(dirPath, 'file2.txt'), destinationPath: 'file2.txt' }, { - sourcePath: '/home/user/files/plz-upload/dir/file3.txt', + sourcePath: path.join(dirPath, 'file3.txt'), destinationPath: 'dir/file3.txt' } ]) diff --git a/packages/http-client/package-lock.json b/packages/http-client/package-lock.json index ea3d7951..52038ad3 100644 --- a/packages/http-client/package-lock.json +++ b/packages/http-client/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@actions/http-client", - "version": "2.2.0", + "version": "2.2.1", "license": "MIT", "dependencies": { "tunnel": "^0.0.6",