Skip to content

Commit 2d2fb5b

Browse files
StephanBijzittercpojer
authored andcommitted
refactor: strip <rootDir> from collectCoverageFrom values (#5524)
* refactor: strip <rootDir> from collectCoverageFrom values All values given to collectCoverageFrom are relative to the root directory, so usage of <rootDir> results in invalid file paths. With these changes, <rootDir> will be silently replaced. ISSUES CLOSED: #5499 * chore: ignore JetBrains configuration files * refactor: wrap mapping in a nullcheck * Update .gitignore
1 parent e9bf143 commit 2d2fb5b

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
* `[docs]` Add documentation for interactive snapshot mode ([#5291](https://github.com/facebook/jest/pull/5291))
1010
* `[jest-editor-support]` Add watchAll flag ([#5523](https://github.com/facebook/jest/pull/5523))
1111

12+
### Chore & Maintenance
13+
14+
* `[jest-config]` Allow `<rootDir>` to be used with `collectCoverageFrom` ([#5524](https://github.com/facebook/jest/pull/5524))
15+
1216
## jest 22.2.2
1317

1418
### Fixes

packages/jest-config/src/__tests__/normalize.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,31 @@ describe('collectCoverageOnlyFrom', () => {
186186
});
187187
});
188188

189+
describe('collectCoverageFrom', () => {
190+
it('substitutes <rootDir> tokens', () => {
191+
const barBaz = 'bar/baz';
192+
const quxQuux = 'qux/quux/';
193+
const notQuxQuux = `!${quxQuux}`;
194+
195+
const {options} = normalize(
196+
{
197+
collectCoverageFrom: [
198+
barBaz,
199+
notQuxQuux,
200+
`<rootDir>/${barBaz}`,
201+
`!<rootDir>/${quxQuux}`,
202+
],
203+
rootDir: '/root/path/foo/',
204+
},
205+
{},
206+
);
207+
208+
const expected = [barBaz, notQuxQuux, barBaz, notQuxQuux];
209+
210+
expect(options.collectCoverageFrom).toEqual(expected);
211+
});
212+
});
213+
189214
function testPathArray(key) {
190215
it('normalizes all paths relative to rootDir', () => {
191216
const {options} = normalize(

packages/jest-config/src/normalize.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ const normalizeCollectCoverageFrom = (options: InitialOptions, key: string) => {
160160
value = options[key];
161161
}
162162

163+
if (value) {
164+
value = value.map(filePath => {
165+
return filePath.replace(/^(!?)(<rootDir>\/)(.*)/, '$1$3');
166+
});
167+
}
168+
163169
return value;
164170
};
165171

0 commit comments

Comments
 (0)