diff --git a/CHANGELOG.md b/CHANGELOG.md index 55b6745861e6..16319cd3e275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ * `[docs]` Add documentation for interactive snapshot mode ([#5291](https://github.com/facebook/jest/pull/5291)) * `[jest-editor-support]` Add watchAll flag ([#5523](https://github.com/facebook/jest/pull/5523)) +### Chore & Maintenance + +* `[jest-config]` Allow `` to be used with `collectCoverageFrom` ([#5524](https://github.com/facebook/jest/pull/5524)) + ## jest 22.2.2 ### Fixes diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index b15b7eed0c4c..c9ff36d29d38 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -186,6 +186,31 @@ describe('collectCoverageOnlyFrom', () => { }); }); +describe('collectCoverageFrom', () => { + it('substitutes tokens', () => { + const barBaz = 'bar/baz'; + const quxQuux = 'qux/quux/'; + const notQuxQuux = `!${quxQuux}`; + + const {options} = normalize( + { + collectCoverageFrom: [ + barBaz, + notQuxQuux, + `/${barBaz}`, + `!/${quxQuux}`, + ], + rootDir: '/root/path/foo/', + }, + {}, + ); + + const expected = [barBaz, notQuxQuux, barBaz, notQuxQuux]; + + expect(options.collectCoverageFrom).toEqual(expected); + }); +}); + function testPathArray(key) { it('normalizes all paths relative to rootDir', () => { const {options} = normalize( diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 6cf845e3fff1..8a7acc71e365 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -160,6 +160,12 @@ const normalizeCollectCoverageFrom = (options: InitialOptions, key: string) => { value = options[key]; } + if (value) { + value = value.map(filePath => { + return filePath.replace(/^(!?)(\/)(.*)/, '$1$3'); + }); + } + return value; };