Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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