diff --git a/.vscode/settings.json b/.vscode/settings.json index 23fd35f..7db2f33 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "editor.formatOnSave": true -} \ No newline at end of file + "editor.formatOnSave": true, + "jest.autoEnable": false, +} diff --git a/Common/Node/ParametersBase.ts b/Common/Node/ParametersBase.ts index 2a4e669..d73d76b 100644 --- a/Common/Node/ParametersBase.ts +++ b/Common/Node/ParametersBase.ts @@ -5,7 +5,7 @@ export class ParametersBase { public digitalRegion: string public digitalBucket: string public digitalTargetFolder?: string - private digitalCredentials: string + public digitalCredentials: string constructor() { try { diff --git a/Common/Node/Spaces.ts b/Common/Node/Spaces.ts index 0fa4f7c..187dfd3 100644 --- a/Common/Node/Spaces.ts +++ b/Common/Node/Spaces.ts @@ -1,16 +1,16 @@ -import { Endpoint, S3 } from 'aws-sdk' -import { ParametersBase } from './ParametersBase'; +import AWS from 'aws-sdk' +import { ParametersBase } from './ParametersBase' export class Spaces { - public endpoint: Endpoint - public s3Connection: S3 + public endpoint: AWS.Endpoint + public s3Connection: AWS.S3 - constructor(protected params: ParametersBase & T){ - this.endpoint = new Endpoint( + constructor(protected params: ParametersBase & T) { + this.endpoint = new AWS.Endpoint( `${this.params.digitalRegion.toLowerCase()}.digitaloceanspaces.com` ) - this.s3Connection = new S3({ + this.s3Connection = new AWS.S3({ endpoint: this.endpoint.host, accessKeyId: this.params.digitalEndpoint.parameters.username, secretAccessKey: this.params.digitalEndpoint.parameters.password, diff --git a/Tasks/DigitalOceanSpacesDelete/utils/Delete.ts b/Tasks/DigitalOceanSpacesDelete/utils/Delete.ts index f15433e..bb9e2c9 100644 --- a/Tasks/DigitalOceanSpacesDelete/utils/Delete.ts +++ b/Tasks/DigitalOceanSpacesDelete/utils/Delete.ts @@ -1,4 +1,4 @@ -import { S3 } from 'aws-sdk' +import AWS from 'aws-sdk' import { isEmpty, sortedUniq, dropRight, includes } from 'lodash' import * as matcher from 'matcher' import * as semver from 'semver' @@ -36,7 +36,7 @@ export class Delete extends Spaces { if (this.params.digitalEnableSemver) filtedObjects = this.filterSemanticVersion(listedObjects) - const deleteParams: S3.DeleteObjectsRequest = { + const deleteParams: AWS.S3.DeleteObjectsRequest = { Bucket: this.params.digitalBucket, Delete: { Objects: filtedObjects, @@ -69,11 +69,11 @@ export class Delete extends Spaces { * Get all files that match the glob pattern filter and return */ private filterFiles( - listedObjects: S3.ListObjectsV2Output - ): S3.ObjectIdentifier[] { + listedObjects: AWS.S3.ListObjectsV2Output + ): AWS.S3.ObjectIdentifier[] { console.log(tl.loc('FilteringFiles', this.params.digitalGlobExpressions)) - const result: S3.ObjectIdentifier[] = listedObjects.Contents.map( + const result: AWS.S3.ObjectIdentifier[] = listedObjects.Contents.map( ({ Key }) => { return { Key } } @@ -102,7 +102,7 @@ export class Delete extends Spaces { /** * Get all files in the target folder and return */ - private async searchFiles(): Promise { + private async searchFiles(): Promise { console.log( tl.loc( 'SearchingFiles', @@ -112,7 +112,7 @@ export class Delete extends Spaces { ) ) - const parameters: S3.ListObjectsV2Request = { + const parameters: AWS.S3.ListObjectsV2Request = { Bucket: this.params.digitalBucket, Prefix: this.params.digitalTargetFolder, } @@ -133,8 +133,8 @@ export class Delete extends Spaces { * Making sure that only 'v1.0.0.exe' was deleted from the bucket */ private filterSemanticVersion( - listedObjects: S3.ListObjectsV2Output - ): S3.ObjectIdentifier[] { + listedObjects: AWS.S3.ListObjectsV2Output + ): AWS.S3.ObjectIdentifier[] { console.log(tl.loc('SemverActive')) // Get version from Key and insert in a ordened list @@ -172,7 +172,7 @@ export class Delete extends Spaces { } // Compare to the list, if not present, remove it from listedObjects to prevent from being deleted - const filteredListObjects: S3.ObjectIdentifier[] = listedObjects.Contents.map( + const filteredListObjects: AWS.S3.ObjectIdentifier[] = listedObjects.Contents.map( ({ Key }) => { return { Key } } diff --git a/Tasks/DigitalOceanSpacesUpload/utils/Upload.ts b/Tasks/DigitalOceanSpacesUpload/utils/Upload.ts index 8473e0a..c6c32bb 100644 --- a/Tasks/DigitalOceanSpacesUpload/utils/Upload.ts +++ b/Tasks/DigitalOceanSpacesUpload/utils/Upload.ts @@ -1,4 +1,4 @@ -import { S3 } from 'aws-sdk' +import AWS from 'aws-sdk' import * as fs from 'fs' import { isEmpty } from 'lodash' import * as path from 'path' @@ -234,7 +234,7 @@ export class Upload extends Spaces { console.log(tl.loc('UploadingFile', file, targetPath, contentType)) - const params: S3.PutObjectRequest = { + const params: AWS.S3.PutObjectRequest = { Bucket: this.params.digitalBucket, ACL: this.params.digitalAcl, Key: targetPath, @@ -242,20 +242,8 @@ export class Upload extends Spaces { ContentType: contentType, } - const request: S3.ManagedUpload = this.s3Connection.upload(params) + await this.uploadFiles(params) - request.on('httpUploadProgress', (progress) => { - console.log( - tl.loc( - 'FileUploadProgress', - prettyBytes(progress.loaded), - prettyBytes(progress.total), - Math.floor((progress.loaded / progress.total) * 100).toFixed(1) - ) - ) - }) - - const response: S3.ManagedUpload.SendData = await request.promise() console.log(tl.loc('FileUploadCompleted', file, targetPath)) } catch (err) { console.error(tl.loc('FileUploadFailed'), err) @@ -266,7 +254,28 @@ export class Upload extends Spaces { console.log(tl.loc('TaskCompleted')) } - private normalizeKeyPath(file: string): string { + async uploadFiles( + objectRequest: AWS.S3.PutObjectRequest + ): Promise { + const request: AWS.S3.ManagedUpload = this.s3Connection.upload( + objectRequest + ) + + request.on('httpUploadProgress', (progress) => { + console.log( + tl.loc( + 'FileUploadProgress', + prettyBytes(progress.loaded), + prettyBytes(progress.total), + Math.floor((progress.loaded / progress.total) * 100).toFixed(1) + ) + ) + }) + + return request.promise() + } + + normalizeKeyPath(file: string): string { let relativePath = file.substring(this.params.digitalSourceFolder.length) if (relativePath.startsWith(path.sep)) { diff --git a/Tests/DigitalOceanSpacesUpload/utils/Upload.spec.ts b/Tests/DigitalOceanSpacesUpload/utils/Upload.spec.ts new file mode 100644 index 0000000..2e851aa --- /dev/null +++ b/Tests/DigitalOceanSpacesUpload/utils/Upload.spec.ts @@ -0,0 +1,51 @@ +import { Upload } from '@DOSUpload/utils/Upload.ts' +// tslint:disable-next-line: no-var-requires +const AWS = require('aws-sdk') + +describe('DOSUpload utils', () => { + afterEach(() => AWS.clearAllMocks()) + it('Upload init', async () => { + const uploadFiles: jest.Mock = AWS.spyOn('S3', 'upload').mockReturnValue({ + promise: () => Promise.resolve(), + on: () => Promise.resolve(), + }) + + const test = new Upload({ + digitalSourceFolder: './Tests/fixtures/', + digitalGlobExpressions: ['**'], + digitalAcl: 'test', + digitalFlattenFolders: false, + digitalEndpoint: { + parameters: { username: 'test', password: 'test' }, + scheme: 'test', + }, + digitalRegion: 'test', + digitalBucket: 'test', + digitalCredentials: 'test', + }) + + const normalizePaths = jest.spyOn(test, 'normalizeKeyPath') + + await test.init() + + expect(uploadFiles.mock.calls).toMatchSnapshot() + expect(normalizePaths).toHaveBeenCalledTimes(3) + expect(normalizePaths).toHaveBeenNthCalledWith( + 1, + 'Tests/fixtures/file-v1.0.1.txt' + ) + expect(normalizePaths).toHaveBeenNthCalledWith( + 2, + 'Tests/fixtures/file1-v1.2.1.txt' + ) + expect(normalizePaths).toHaveBeenNthCalledWith( + 3, + 'Tests/fixtures/file2-v1.3.1.json' + ) + expect(normalizePaths.mock.results).toEqual([ + { type: 'return', value: 'file-v1.0.1.txt' }, + { type: 'return', value: 'file1-v1.2.1.txt' }, + { type: 'return', value: 'file2-v1.3.1.json' }, + ]) + }) +}) diff --git a/Tests/DigitalOceanSpacesUpload/utils/__snapshots__/Upload.spec.ts.snap b/Tests/DigitalOceanSpacesUpload/utils/__snapshots__/Upload.spec.ts.snap new file mode 100644 index 0000000..ca2cac1 --- /dev/null +++ b/Tests/DigitalOceanSpacesUpload/utils/__snapshots__/Upload.spec.ts.snap @@ -0,0 +1,723 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`DOSUpload utils Upload init 1`] = ` +Array [ + Array [ + Object { + "ACL": "test", + "Body": ReadStream { + "_events": Object { + "end": [Function], + }, + "_eventsCount": 1, + "_maxListeners": undefined, + "_readableState": ReadableState { + "autoDestroy": false, + "awaitDrainWriters": null, + "buffer": BufferList { + "head": null, + "length": 0, + "tail": null, + }, + "decoder": null, + "defaultEncoding": "utf8", + "destroyed": false, + "emitClose": false, + "emittedReadable": false, + "encoding": null, + "endEmitted": false, + "ended": false, + "flowing": null, + "highWaterMark": 65536, + "length": 0, + "multiAwaitDrain": false, + "needReadable": false, + "objectMode": false, + "pipes": null, + "pipesCount": 0, + "readableListening": false, + "reading": false, + "readingMore": false, + "resumeScheduled": false, + "sync": true, + Symbol(kPaused): null, + }, + "autoClose": true, + "bytesRead": 0, + "closed": false, + "end": Infinity, + "fd": null, + "flags": "r", + "mode": 438, + "path": "Tests/fixtures/file-v1.0.1.txt", + "pos": undefined, + "readable": true, + "start": undefined, + Symbol(kFs): Object { + "Dir": [Function], + "Dirent": [Function], + "F_OK": 0, + "FileReadStream": [Function], + "FileWriteStream": [Function], + "R_OK": 4, + "ReadStream": [Function], + "Stats": [Function], + "W_OK": 2, + "WriteStream": [Function], + "X_OK": 1, + "_toUnixTimestamp": [Function], + "access": [Function], + "accessSync": [Function], + "appendFile": [Function], + "appendFileSync": [Function], + "chmod": [Function], + "chmodSync": [Function], + "chown": [Function], + "chownSync": [Function], + "close": [Function], + "closeSync": [Function], + "constants": Object { + "COPYFILE_EXCL": 1, + "COPYFILE_FICLONE": 2, + "COPYFILE_FICLONE_FORCE": 4, + "F_OK": 0, + "O_APPEND": 1024, + "O_CREAT": 64, + "O_DIRECT": 16384, + "O_DIRECTORY": 65536, + "O_DSYNC": 4096, + "O_EXCL": 128, + "O_NOATIME": 262144, + "O_NOCTTY": 256, + "O_NOFOLLOW": 131072, + "O_NONBLOCK": 2048, + "O_RDONLY": 0, + "O_RDWR": 2, + "O_SYNC": 1052672, + "O_TRUNC": 512, + "O_WRONLY": 1, + "R_OK": 4, + "S_IFBLK": 24576, + "S_IFCHR": 8192, + "S_IFDIR": 16384, + "S_IFIFO": 4096, + "S_IFLNK": 40960, + "S_IFMT": 61440, + "S_IFREG": 32768, + "S_IFSOCK": 49152, + "S_IRGRP": 32, + "S_IROTH": 4, + "S_IRUSR": 256, + "S_IRWXG": 56, + "S_IRWXO": 7, + "S_IRWXU": 448, + "S_IWGRP": 16, + "S_IWOTH": 2, + "S_IWUSR": 128, + "S_IXGRP": 8, + "S_IXOTH": 1, + "S_IXUSR": 64, + "UV_DIRENT_BLOCK": 7, + "UV_DIRENT_CHAR": 6, + "UV_DIRENT_DIR": 2, + "UV_DIRENT_FIFO": 4, + "UV_DIRENT_FILE": 1, + "UV_DIRENT_LINK": 3, + "UV_DIRENT_SOCKET": 5, + "UV_DIRENT_UNKNOWN": 0, + "UV_FS_COPYFILE_EXCL": 1, + "UV_FS_COPYFILE_FICLONE": 2, + "UV_FS_COPYFILE_FICLONE_FORCE": 4, + "UV_FS_O_FILEMAP": 0, + "UV_FS_SYMLINK_DIR": 1, + "UV_FS_SYMLINK_JUNCTION": 2, + "W_OK": 2, + "X_OK": 1, + }, + "copyFile": [Function], + "copyFileSync": [Function], + "createReadStream": [Function], + "createWriteStream": [Function], + "exists": [Function], + "existsSync": [Function], + "fchmod": [Function], + "fchmodSync": [Function], + "fchown": [Function], + "fchownSync": [Function], + "fdatasync": [Function], + "fdatasyncSync": [Function], + "fstat": [Function], + "fstatSync": [Function], + "fsync": [Function], + "fsyncSync": [Function], + "ftruncate": [Function], + "ftruncateSync": [Function], + "futimes": [Function], + "futimesSync": [Function], + "lchmod": undefined, + "lchmodSync": undefined, + "lchown": [Function], + "lchownSync": [Function], + "link": [Function], + "linkSync": [Function], + "lstat": [Function], + "lstatSync": [Function], + "mkdir": [Function], + "mkdirSync": [Function], + "mkdtemp": [Function], + "mkdtempSync": [Function], + "open": [Function], + "openSync": [Function], + "opendir": [Function], + "opendirSync": [Function], + "promises": Object { + "access": [Function], + "appendFile": [Function], + "chmod": [Function], + "chown": [Function], + "copyFile": [Function], + "lchmod": [Function], + "lchown": [Function], + "link": [Function], + "lstat": [Function], + "mkdir": [Function], + "mkdtemp": [Function], + "open": [Function], + "opendir": [Function], + "readFile": [Function], + "readdir": [Function], + "readlink": [Function], + "realpath": [Function], + "rename": [Function], + "rmdir": [Function], + "stat": [Function], + "symlink": [Function], + "truncate": [Function], + "unlink": [Function], + "utimes": [Function], + "writeFile": [Function], + }, + "read": [Function], + "readFile": [Function], + "readFileSync": [Function], + "readSync": [Function], + "readdir": [Function], + "readdirSync": [Function], + "readlink": [Function], + "readlinkSync": [Function], + "readv": [Function], + "readvSync": [Function], + "realpath": [Function], + "realpathSync": [Function], + "rename": [Function], + "renameSync": [Function], + "rmdir": [Function], + "rmdirSync": [Function], + "stat": [Function], + "statSync": [Function], + "symlink": [Function], + "symlinkSync": [Function], + "truncate": [Function], + "truncateSync": [Function], + "unlink": [Function], + "unlinkSync": [Function], + "unwatchFile": [Function], + "utimes": [Function], + "utimesSync": [Function], + "watch": [Function], + "watchFile": [Function], + "write": [Function], + "writeFile": [Function], + "writeFileSync": [Function], + "writeSync": [Function], + "writev": [Function], + "writevSync": [Function], + }, + Symbol(kCapture): false, + Symbol(kIsPerformingIO): false, + }, + "Bucket": "test", + "ContentType": "text/plain", + "Key": "file-v1.0.1.txt", + }, + ], + Array [ + Object { + "ACL": "test", + "Body": ReadStream { + "_events": Object { + "end": [Function], + }, + "_eventsCount": 1, + "_maxListeners": undefined, + "_readableState": ReadableState { + "autoDestroy": false, + "awaitDrainWriters": null, + "buffer": BufferList { + "head": null, + "length": 0, + "tail": null, + }, + "decoder": null, + "defaultEncoding": "utf8", + "destroyed": false, + "emitClose": false, + "emittedReadable": false, + "encoding": null, + "endEmitted": false, + "ended": false, + "flowing": null, + "highWaterMark": 65536, + "length": 0, + "multiAwaitDrain": false, + "needReadable": false, + "objectMode": false, + "pipes": null, + "pipesCount": 0, + "readableListening": false, + "reading": false, + "readingMore": false, + "resumeScheduled": false, + "sync": true, + Symbol(kPaused): null, + }, + "autoClose": true, + "bytesRead": 0, + "closed": false, + "end": Infinity, + "fd": null, + "flags": "r", + "mode": 438, + "path": "Tests/fixtures/file1-v1.2.1.txt", + "pos": undefined, + "readable": true, + "start": undefined, + Symbol(kFs): Object { + "Dir": [Function], + "Dirent": [Function], + "F_OK": 0, + "FileReadStream": [Function], + "FileWriteStream": [Function], + "R_OK": 4, + "ReadStream": [Function], + "Stats": [Function], + "W_OK": 2, + "WriteStream": [Function], + "X_OK": 1, + "_toUnixTimestamp": [Function], + "access": [Function], + "accessSync": [Function], + "appendFile": [Function], + "appendFileSync": [Function], + "chmod": [Function], + "chmodSync": [Function], + "chown": [Function], + "chownSync": [Function], + "close": [Function], + "closeSync": [Function], + "constants": Object { + "COPYFILE_EXCL": 1, + "COPYFILE_FICLONE": 2, + "COPYFILE_FICLONE_FORCE": 4, + "F_OK": 0, + "O_APPEND": 1024, + "O_CREAT": 64, + "O_DIRECT": 16384, + "O_DIRECTORY": 65536, + "O_DSYNC": 4096, + "O_EXCL": 128, + "O_NOATIME": 262144, + "O_NOCTTY": 256, + "O_NOFOLLOW": 131072, + "O_NONBLOCK": 2048, + "O_RDONLY": 0, + "O_RDWR": 2, + "O_SYNC": 1052672, + "O_TRUNC": 512, + "O_WRONLY": 1, + "R_OK": 4, + "S_IFBLK": 24576, + "S_IFCHR": 8192, + "S_IFDIR": 16384, + "S_IFIFO": 4096, + "S_IFLNK": 40960, + "S_IFMT": 61440, + "S_IFREG": 32768, + "S_IFSOCK": 49152, + "S_IRGRP": 32, + "S_IROTH": 4, + "S_IRUSR": 256, + "S_IRWXG": 56, + "S_IRWXO": 7, + "S_IRWXU": 448, + "S_IWGRP": 16, + "S_IWOTH": 2, + "S_IWUSR": 128, + "S_IXGRP": 8, + "S_IXOTH": 1, + "S_IXUSR": 64, + "UV_DIRENT_BLOCK": 7, + "UV_DIRENT_CHAR": 6, + "UV_DIRENT_DIR": 2, + "UV_DIRENT_FIFO": 4, + "UV_DIRENT_FILE": 1, + "UV_DIRENT_LINK": 3, + "UV_DIRENT_SOCKET": 5, + "UV_DIRENT_UNKNOWN": 0, + "UV_FS_COPYFILE_EXCL": 1, + "UV_FS_COPYFILE_FICLONE": 2, + "UV_FS_COPYFILE_FICLONE_FORCE": 4, + "UV_FS_O_FILEMAP": 0, + "UV_FS_SYMLINK_DIR": 1, + "UV_FS_SYMLINK_JUNCTION": 2, + "W_OK": 2, + "X_OK": 1, + }, + "copyFile": [Function], + "copyFileSync": [Function], + "createReadStream": [Function], + "createWriteStream": [Function], + "exists": [Function], + "existsSync": [Function], + "fchmod": [Function], + "fchmodSync": [Function], + "fchown": [Function], + "fchownSync": [Function], + "fdatasync": [Function], + "fdatasyncSync": [Function], + "fstat": [Function], + "fstatSync": [Function], + "fsync": [Function], + "fsyncSync": [Function], + "ftruncate": [Function], + "ftruncateSync": [Function], + "futimes": [Function], + "futimesSync": [Function], + "lchmod": undefined, + "lchmodSync": undefined, + "lchown": [Function], + "lchownSync": [Function], + "link": [Function], + "linkSync": [Function], + "lstat": [Function], + "lstatSync": [Function], + "mkdir": [Function], + "mkdirSync": [Function], + "mkdtemp": [Function], + "mkdtempSync": [Function], + "open": [Function], + "openSync": [Function], + "opendir": [Function], + "opendirSync": [Function], + "promises": Object { + "access": [Function], + "appendFile": [Function], + "chmod": [Function], + "chown": [Function], + "copyFile": [Function], + "lchmod": [Function], + "lchown": [Function], + "link": [Function], + "lstat": [Function], + "mkdir": [Function], + "mkdtemp": [Function], + "open": [Function], + "opendir": [Function], + "readFile": [Function], + "readdir": [Function], + "readlink": [Function], + "realpath": [Function], + "rename": [Function], + "rmdir": [Function], + "stat": [Function], + "symlink": [Function], + "truncate": [Function], + "unlink": [Function], + "utimes": [Function], + "writeFile": [Function], + }, + "read": [Function], + "readFile": [Function], + "readFileSync": [Function], + "readSync": [Function], + "readdir": [Function], + "readdirSync": [Function], + "readlink": [Function], + "readlinkSync": [Function], + "readv": [Function], + "readvSync": [Function], + "realpath": [Function], + "realpathSync": [Function], + "rename": [Function], + "renameSync": [Function], + "rmdir": [Function], + "rmdirSync": [Function], + "stat": [Function], + "statSync": [Function], + "symlink": [Function], + "symlinkSync": [Function], + "truncate": [Function], + "truncateSync": [Function], + "unlink": [Function], + "unlinkSync": [Function], + "unwatchFile": [Function], + "utimes": [Function], + "utimesSync": [Function], + "watch": [Function], + "watchFile": [Function], + "write": [Function], + "writeFile": [Function], + "writeFileSync": [Function], + "writeSync": [Function], + "writev": [Function], + "writevSync": [Function], + }, + Symbol(kCapture): false, + Symbol(kIsPerformingIO): false, + }, + "Bucket": "test", + "ContentType": "text/plain", + "Key": "file1-v1.2.1.txt", + }, + ], + Array [ + Object { + "ACL": "test", + "Body": ReadStream { + "_events": Object { + "end": [Function], + }, + "_eventsCount": 1, + "_maxListeners": undefined, + "_readableState": ReadableState { + "autoDestroy": false, + "awaitDrainWriters": null, + "buffer": BufferList { + "head": null, + "length": 0, + "tail": null, + }, + "decoder": null, + "defaultEncoding": "utf8", + "destroyed": false, + "emitClose": false, + "emittedReadable": false, + "encoding": null, + "endEmitted": false, + "ended": false, + "flowing": null, + "highWaterMark": 65536, + "length": 0, + "multiAwaitDrain": false, + "needReadable": false, + "objectMode": false, + "pipes": null, + "pipesCount": 0, + "readableListening": false, + "reading": false, + "readingMore": false, + "resumeScheduled": false, + "sync": true, + Symbol(kPaused): null, + }, + "autoClose": true, + "bytesRead": 0, + "closed": false, + "end": Infinity, + "fd": null, + "flags": "r", + "mode": 438, + "path": "Tests/fixtures/file2-v1.3.1.json", + "pos": undefined, + "readable": true, + "start": undefined, + Symbol(kFs): Object { + "Dir": [Function], + "Dirent": [Function], + "F_OK": 0, + "FileReadStream": [Function], + "FileWriteStream": [Function], + "R_OK": 4, + "ReadStream": [Function], + "Stats": [Function], + "W_OK": 2, + "WriteStream": [Function], + "X_OK": 1, + "_toUnixTimestamp": [Function], + "access": [Function], + "accessSync": [Function], + "appendFile": [Function], + "appendFileSync": [Function], + "chmod": [Function], + "chmodSync": [Function], + "chown": [Function], + "chownSync": [Function], + "close": [Function], + "closeSync": [Function], + "constants": Object { + "COPYFILE_EXCL": 1, + "COPYFILE_FICLONE": 2, + "COPYFILE_FICLONE_FORCE": 4, + "F_OK": 0, + "O_APPEND": 1024, + "O_CREAT": 64, + "O_DIRECT": 16384, + "O_DIRECTORY": 65536, + "O_DSYNC": 4096, + "O_EXCL": 128, + "O_NOATIME": 262144, + "O_NOCTTY": 256, + "O_NOFOLLOW": 131072, + "O_NONBLOCK": 2048, + "O_RDONLY": 0, + "O_RDWR": 2, + "O_SYNC": 1052672, + "O_TRUNC": 512, + "O_WRONLY": 1, + "R_OK": 4, + "S_IFBLK": 24576, + "S_IFCHR": 8192, + "S_IFDIR": 16384, + "S_IFIFO": 4096, + "S_IFLNK": 40960, + "S_IFMT": 61440, + "S_IFREG": 32768, + "S_IFSOCK": 49152, + "S_IRGRP": 32, + "S_IROTH": 4, + "S_IRUSR": 256, + "S_IRWXG": 56, + "S_IRWXO": 7, + "S_IRWXU": 448, + "S_IWGRP": 16, + "S_IWOTH": 2, + "S_IWUSR": 128, + "S_IXGRP": 8, + "S_IXOTH": 1, + "S_IXUSR": 64, + "UV_DIRENT_BLOCK": 7, + "UV_DIRENT_CHAR": 6, + "UV_DIRENT_DIR": 2, + "UV_DIRENT_FIFO": 4, + "UV_DIRENT_FILE": 1, + "UV_DIRENT_LINK": 3, + "UV_DIRENT_SOCKET": 5, + "UV_DIRENT_UNKNOWN": 0, + "UV_FS_COPYFILE_EXCL": 1, + "UV_FS_COPYFILE_FICLONE": 2, + "UV_FS_COPYFILE_FICLONE_FORCE": 4, + "UV_FS_O_FILEMAP": 0, + "UV_FS_SYMLINK_DIR": 1, + "UV_FS_SYMLINK_JUNCTION": 2, + "W_OK": 2, + "X_OK": 1, + }, + "copyFile": [Function], + "copyFileSync": [Function], + "createReadStream": [Function], + "createWriteStream": [Function], + "exists": [Function], + "existsSync": [Function], + "fchmod": [Function], + "fchmodSync": [Function], + "fchown": [Function], + "fchownSync": [Function], + "fdatasync": [Function], + "fdatasyncSync": [Function], + "fstat": [Function], + "fstatSync": [Function], + "fsync": [Function], + "fsyncSync": [Function], + "ftruncate": [Function], + "ftruncateSync": [Function], + "futimes": [Function], + "futimesSync": [Function], + "lchmod": undefined, + "lchmodSync": undefined, + "lchown": [Function], + "lchownSync": [Function], + "link": [Function], + "linkSync": [Function], + "lstat": [Function], + "lstatSync": [Function], + "mkdir": [Function], + "mkdirSync": [Function], + "mkdtemp": [Function], + "mkdtempSync": [Function], + "open": [Function], + "openSync": [Function], + "opendir": [Function], + "opendirSync": [Function], + "promises": Object { + "access": [Function], + "appendFile": [Function], + "chmod": [Function], + "chown": [Function], + "copyFile": [Function], + "lchmod": [Function], + "lchown": [Function], + "link": [Function], + "lstat": [Function], + "mkdir": [Function], + "mkdtemp": [Function], + "open": [Function], + "opendir": [Function], + "readFile": [Function], + "readdir": [Function], + "readlink": [Function], + "realpath": [Function], + "rename": [Function], + "rmdir": [Function], + "stat": [Function], + "symlink": [Function], + "truncate": [Function], + "unlink": [Function], + "utimes": [Function], + "writeFile": [Function], + }, + "read": [Function], + "readFile": [Function], + "readFileSync": [Function], + "readSync": [Function], + "readdir": [Function], + "readdirSync": [Function], + "readlink": [Function], + "readlinkSync": [Function], + "readv": [Function], + "readvSync": [Function], + "realpath": [Function], + "realpathSync": [Function], + "rename": [Function], + "renameSync": [Function], + "rmdir": [Function], + "rmdirSync": [Function], + "stat": [Function], + "statSync": [Function], + "symlink": [Function], + "symlinkSync": [Function], + "truncate": [Function], + "truncateSync": [Function], + "unlink": [Function], + "unlinkSync": [Function], + "unwatchFile": [Function], + "utimes": [Function], + "utimesSync": [Function], + "watch": [Function], + "watchFile": [Function], + "write": [Function], + "writeFile": [Function], + "writeFileSync": [Function], + "writeSync": [Function], + "writev": [Function], + "writevSync": [Function], + }, + Symbol(kCapture): false, + Symbol(kIsPerformingIO): false, + }, + "Bucket": "test", + "ContentType": "application/octet-stream", + "Key": "file2-v1.3.1.json", + }, + ], +] +`; diff --git a/Tests/DigitalOceanSpacesUpload/utils/utils.spec.ts b/Tests/DigitalOceanSpacesUpload/utils/utils.spec.ts index 9204a65..c7c00f6 100644 --- a/Tests/DigitalOceanSpacesUpload/utils/utils.spec.ts +++ b/Tests/DigitalOceanSpacesUpload/utils/utils.spec.ts @@ -1,4 +1,4 @@ -import { findFiles } from '@DOSUpload/utils/utils' +import { findFiles } from '@DOSUpload/utils/utils.ts' describe('DOSUpload utils', () => { describe('FindFiles', () => { diff --git a/Tests/__mocks__/aws-sdk.ts b/Tests/__mocks__/aws-sdk.ts new file mode 100644 index 0000000..0da2702 --- /dev/null +++ b/Tests/__mocks__/aws-sdk.ts @@ -0,0 +1,4 @@ +'use strict' + +// tslint:disable-next-line: no-var-requires +module.exports = require('@mapbox/aws-sdk-jest') diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c626422..8fa8471 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -63,6 +63,12 @@ steps: condition: ne(variables['CacheRestored'], 'true') # Finish tasks that should be reworked + - task: Bash@3 + inputs: + targetType: 'inline' + script: 'yarn build' + displayName: 'yarn build' + - task: Bash@3 inputs: targetType: 'inline' diff --git a/jest.config.js b/jest.config.js index e4fdfed..04c4e0a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -11,4 +11,7 @@ module.exports = { moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '/', }), + collectCoverage: true, + coverageDirectory: '/Tests/coverage', + collectCoverageFrom: ['./Tasks/**/*.ts', '!**/*.d.ts'], } diff --git a/package.json b/package.json index 0651932..536ef08 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "azure-pipelines-task-lib": "^2.11.2" }, "devDependencies": { + "@mapbox/aws-sdk-jest": "^0.0.1", "@semantic-release/changelog": "^5.0.1", "@semantic-release/git": "^9.0.0", "@types/jest": "^26.0.14", @@ -43,7 +44,7 @@ "typescript": "^4.0.3" }, "lint-staged": { - "{Tasks,Tests}/**/*.ts": [ + "{Tasks,Tests,Common}/**/*.ts": [ "prettier --write", "git add" ] diff --git a/tsconfig.json b/tsconfig.json index bc43f20..17a6b25 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,9 @@ "sourceMap": false, "inlineSourceMap": true, "declaration": true, + "newLine": "lf", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, "baseUrl": ".", "paths": { "@DOSUpload/*": ["Tasks/DigitalOceanSpacesUpload/*"], diff --git a/tslint.json b/tslint.json index 873c77f..f8f70c7 100644 --- a/tslint.json +++ b/tslint.json @@ -1,6 +1,7 @@ { "extends": ["tslint:latest", "tslint-config-prettier"], "rules": { + "prettier": true, "curly": false, "interface-name": [true, "never-prefix"], "ordered-imports": false, diff --git a/yarn.lock b/yarn.lock index 312c996..ed2a659 100644 --- a/yarn.lock +++ b/yarn.lock @@ -477,6 +477,13 @@ "@types/yargs" "^15.0.0" chalk "^4.0.0" +"@mapbox/aws-sdk-jest@^0.0.1": + version "0.0.1" + resolved "https://registry.yarnpkg.com/@mapbox/aws-sdk-jest/-/aws-sdk-jest-0.0.1.tgz#452608a31f7bf6795758d3fb7ee887d7953590ef" + integrity sha512-7qmhXJUisxs6E/ygaBygDD8QBwv1H1+F/x/lR351PF6slmHieCKn3fQaMCGZ1xCD6K9hYhEmGA4SHUtXg+avQA== + dependencies: + traverse "^0.6.6" + "@nodelib/fs.scandir@2.1.3": version "2.1.3" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b" @@ -7849,7 +7856,7 @@ tracer@0.7.4: dateformat "1.0.11" tinytim "0.1.1" -traverse@~0.6.6: +traverse@^0.6.6, traverse@~0.6.6: version "0.6.6" resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"