From 8c1d0e18fe761ee540166c138e0e93a20cff88f5 Mon Sep 17 00:00:00 2001 From: Mitchell Borrego Date: Tue, 28 Sep 2021 12:59:12 -0400 Subject: [PATCH 1/6] Negate paths --- src/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 025284a16..8fc9c17e7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,7 +74,9 @@ function dryRun( export async function main( args: UploaderArgs, ): Promise> { - + + console.debug({ args }); + // Did user asking for changelog? if (args.changelog) { webHelpers.displayChangelog() @@ -149,9 +151,18 @@ export async function main( coverageFilePaths = args.file } } + const isNegated = (path: string) => path.startsWith('!') coverageFilePaths = coverageFilePaths.concat(await getCoverageFiles( args.dir || projectRoot, - coverageFilePaths.length > 0 ? coverageFilePaths : coverageFilePatterns(), + (() => { + const numOfNegatedPaths = coverageFilePaths.filter(isNegated).length + + if (coverageFilePaths.length > numOfNegatedPaths) { + return coverageFilePaths + } else { + return coverageFilePaths.concat(coverageFilePatterns()) + } + })(), )) // Remove invalid and duplicate file paths From 11db53bcefc94b58428b83766aa85ea141e8d3e2 Mon Sep 17 00:00:00 2001 From: Mitchell Borrego Date: Tue, 28 Sep 2021 14:38:59 -0400 Subject: [PATCH 2/6] Support globstar patterns --- src/helpers/files.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/helpers/files.ts b/src/helpers/files.ts index 5f10f68b2..718739521 100644 --- a/src/helpers/files.ts +++ b/src/helpers/files.ts @@ -168,6 +168,10 @@ export function coverageFilePatterns(): string[] { ] } +const EMPTY_STRING = '' as const + +const isNegated = (path: string) => path.startsWith('!') + /** * * @param {string} projectRoot @@ -180,7 +184,18 @@ export async function getCoverageFiles( ): Promise { const globstar = (pattern: string) => `**/${pattern}` - return glob(coverageFilePatterns.map(globstar), { + return glob(coverageFilePatterns.map((pattern: string) => { + const parts = [] + + if (isNegated(pattern)) { + parts.push('!') + parts.push(globstar(pattern.substr(1))) + } else { + parts.push(globstar(pattern)) + } + + return parts.join(EMPTY_STRING) + }), { cwd: projectRoot, ignore: [...manualBlacklist(), ...globBlacklist()], }) From 8056554efd27ddf1a4d24ed93446f107b3085ff0 Mon Sep 17 00:00:00 2001 From: Mitchell Borrego Date: Tue, 28 Sep 2021 14:43:00 -0400 Subject: [PATCH 3/6] Remove temporary statements --- src/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8fc9c17e7..f5b9f3ff8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,9 +74,7 @@ function dryRun( export async function main( args: UploaderArgs, ): Promise> { - - console.debug({ args }); - + // Did user asking for changelog? if (args.changelog) { webHelpers.displayChangelog() From 6c491a992c2a4ac2b59d1e2a2accfa3a04f65dbc Mon Sep 17 00:00:00 2001 From: Mitchell Borrego Date: Tue, 28 Sep 2021 14:54:26 -0400 Subject: [PATCH 4/6] Update glob test case --- test/index.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/index.test.ts b/test/index.test.ts index e5f600f83..375379049 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -227,6 +227,7 @@ describe('Uploader Core', () => { dryRun: 'true', file: [ 'cover*.txt', + '!fixtures/other' ], name: 'customname', token: 'abcdefg', @@ -236,7 +237,7 @@ describe('Uploader Core', () => { expect(log).toHaveBeenCalledWith( expect.stringMatching(/Processing.*test\/fixtures\/coverage\.txt\.\.\./), ) - expect(log).toHaveBeenCalledWith( + expect(log).not.toHaveBeenCalledWith( expect.stringMatching(/Processing.*test\/fixtures\/other\/coverage\.txt\.\.\./), ) expect(log).not.toHaveBeenCalledWith( From abd52d777a0afda406808d2b7e00638a6480b05d Mon Sep 17 00:00:00 2001 From: Mitchell Borrego Date: Tue, 28 Sep 2021 14:57:57 -0400 Subject: [PATCH 5/6] Update files.test.ts --- test/helpers/files.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/helpers/files.test.ts b/test/helpers/files.test.ts index c5737b629..1ea244651 100644 --- a/test/helpers/files.test.ts +++ b/test/helpers/files.test.ts @@ -113,8 +113,8 @@ describe('File Helpers', () => { it('can return a list of coverage files with a pattern', async () => { expect( - await fileHelpers.getCoverageFiles('.', ['index.test.ts']), - ).toStrictEqual(['test/index.test.ts', 'test/providers/index.test.ts']) + await fileHelpers.getCoverageFiles('.', ['index.test.ts', '!test/providers']), + ).toStrictEqual(['test/index.test.ts']) }) describe('coverage file patterns', () => { it('contains `jacoco*.xml`', () => { From 620e58846311971851f8d567401e5faa8bc4c54f Mon Sep 17 00:00:00 2001 From: Mitchell Borrego Date: Tue, 28 Sep 2021 14:59:40 -0400 Subject: [PATCH 6/6] Reimplement original test --- test/helpers/files.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/helpers/files.test.ts b/test/helpers/files.test.ts index 1ea244651..0a214eeb3 100644 --- a/test/helpers/files.test.ts +++ b/test/helpers/files.test.ts @@ -112,6 +112,11 @@ describe('File Helpers', () => { }) it('can return a list of coverage files with a pattern', async () => { + expect( + await fileHelpers.getCoverageFiles('.', ['index.test.ts']), + ).toStrictEqual(['test/index.test.ts', 'test/providers/index.test.ts']) + }) + it('can return a list of coverage files with a negated pattern', async () => { expect( await fileHelpers.getCoverageFiles('.', ['index.test.ts', '!test/providers']), ).toStrictEqual(['test/index.test.ts'])