Skip to content

Commit

Permalink
refactor: strip <rootDir> from collectCoverageFrom values (#5524)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
StephanBijzitter authored and cpojer committed Feb 11, 2018
1 parent e9bf143 commit 2d2fb5b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<rootDir>` to be used with `collectCoverageFrom` ([#5524](https://github.com/facebook/jest/pull/5524))

## jest 22.2.2

### Fixes
Expand Down
25 changes: 25 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,31 @@ describe('collectCoverageOnlyFrom', () => {
});
});

describe('collectCoverageFrom', () => {
it('substitutes <rootDir> tokens', () => {
const barBaz = 'bar/baz';
const quxQuux = 'qux/quux/';
const notQuxQuux = `!${quxQuux}`;

const {options} = normalize(
{
collectCoverageFrom: [
barBaz,
notQuxQuux,
`<rootDir>/${barBaz}`,
`!<rootDir>/${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(
Expand Down
6 changes: 6 additions & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ const normalizeCollectCoverageFrom = (options: InitialOptions, key: string) => {
value = options[key];
}

if (value) {
value = value.map(filePath => {
return filePath.replace(/^(!?)(<rootDir>\/)(.*)/, '$1$3');
});
}

return value;
};

Expand Down

0 comments on commit 2d2fb5b

Please sign in to comment.