Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmjoseph committed Apr 15, 2024
1 parent 5d943d4 commit be50742
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -33,4 +33,4 @@
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
}
}
}
59 changes: 46 additions & 13 deletions packages/artifact/__tests__/upload-artifact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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')

// 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 root = path.join('/home/user/files/')
const dirPath = path.join(__dirname, `plz-upload`)

// 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')
Expand All @@ -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'
}
])
Expand Down
2 changes: 1 addition & 1 deletion packages/http-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be50742

Please sign in to comment.