Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jest-config)!: remove undocumented collectCoverageOnlyFrom option #13156

Merged
merged 3 commits into from
Aug 22, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- `[expect]` [**BREAKING**] Differentiate between `MatcherContext` `MatcherUtils` and `MatcherState` types ([#13141](https://github.com/facebook/jest/pull/13141))
- `[jest-circus]` Add support for `test.failing.each` ([#13142](https://github.com/facebook/jest/pull/13142))
- `[jest-config]` [**BREAKING**] Make `snapshotFormat` default to `escapeString: false` and `printBasicPrototype: false` ([#13036](https://github.com/facebook/jest/pull/13036))
- `[jest-config]` [**BREAKING**] Remove undocumented `collectCoverageOnlyFrom` option ([#13156](https://github.com/facebook/jest/pull/13156))
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade to `jsdom@20` ([#13037](https://github.com/facebook/jest/pull/13037), [#13058](https://github.com/facebook/jest/pull/13058))
- `[@jest/globals]` Add `jest.Mocked`, `jest.MockedClass`, `jest.MockedFunction` and `jest.MockedObject` utility types ([#12727](https://github.com/facebook/jest/pull/12727))
- `[jest-mock]` [**BREAKING**] Refactor `Mocked*` utility types. `MaybeMockedDeep` and `MaybeMocked` became `Mocked` and `MockedShallow` respectively; only deep mocked variants of `MockedClass`, `MockedFunction` and `MockedObject` are exported ([#13123](https://github.com/facebook/jest/pull/13123), [#13124](https://github.com/facebook/jest/pull/13124))
Expand Down
1 change: 0 additions & 1 deletion docs/WatchPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ For stability and safety reasons, only part of the global configuration keys can
- [`changedSince`](cli#--changedsince)
- [`collectCoverage`](configuration#collectcoverage-boolean)
- [`collectCoverageFrom`](configuration#collectcoveragefrom-array)
- [`collectCoverageOnlyFrom`](configuration#collectcoverageonlyfrom-array)
- [`coverageDirectory`](configuration#coveragedirectory-string)
- [`coverageReporters`](configuration#coveragereporters-arraystring)
- [`notify`](configuration#notify-boolean)
Expand Down
6 changes: 3 additions & 3 deletions e2e/__tests__/coverageReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ test('collects coverage only from specified files avoiding dependencies', () =>
[
'--no-cache',
'--coverage',
'--collectCoverageOnlyFrom',
'--collectCoverageFrom',
'sum.js',
'--',
'sum.test.js',
Expand Down Expand Up @@ -164,9 +164,9 @@ test('collects coverage from duplicate files avoiding shared cache', () => {
// Ensure the exitCode is non-zero if super edge case with coverage triggers
'--coverageThreshold',
'{"global": {"lines": 100}}',
'--collectCoverageOnlyFrom',
'--collectCoverageFrom',
'cached-duplicates/a/identical.js',
'--collectCoverageOnlyFrom',
'--collectCoverageFrom',
'cached-duplicates/b/identical.js',
'--',
'identical.test.js',
Expand Down
8 changes: 4 additions & 4 deletions e2e/transform/babel-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"@babel/preset-flow": "^7.0.0"
},
"jest": {
"collectCoverageOnlyFrom": {
"<rootDir>/this-directory-is-covered/covered.js": true,
"<rootDir>/this-directory-is-covered/excludedFromCoverage.js": true
},
"collectCoverageFrom": [
"<rootDir>/this-directory-is-covered/covered.js",
"<rootDir>/this-directory-is-covered/excludedFromCoverage.js"
],
"coveragePathIgnorePatterns": [
"excludedFromCoverage"
],
Expand Down
8 changes: 4 additions & 4 deletions e2e/transform/no-babel-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"jest": {
"collectCoverageOnlyFrom": {
"<rootDir>/this-directory-is-covered/covered.js": true,
"<rootDir>/this-directory-is-covered/excludedFromCoverage.js": true
},
"collectCoverageFrom": [
"<rootDir>/this-directory-is-covered/covered.js",
"<rootDir>/this-directory-is-covered/excludedFromCoverage.js"
],
"coveragePathIgnorePatterns": [
"excludedFromCoverage"
],
Expand Down
8 changes: 4 additions & 4 deletions e2e/transform/transformer-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"@babel/preset-flow": "^7.0.0"
},
"jest": {
"collectCoverageOnlyFrom": {
"<rootDir>/this-directory-is-covered/Covered.js": true,
"<rootDir>/this-directory-is-covered/ExcludedFromCoverage.js": true
},
"collectCoverageFrom": [
"<rootDir>/this-directory-is-covered/Covered.js",
"<rootDir>/this-directory-is-covered/ExcludedFromCoverage.js"
],
"coveragePathIgnorePatterns": [
"ExcludedFromCoverage"
],
Expand Down
5 changes: 0 additions & 5 deletions packages/jest-cli/src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,6 @@ export const options: {[key: string]: Options} = {
'info needs to be collected from.',
type: 'string',
},
collectCoverageOnlyFrom: {
description: 'Explicit list of paths coverage will be restricted to.',
string: true,
type: 'array',
},
color: {
description:
'Forces test results output color highlighting (even if ' +
Expand Down
8 changes: 8 additions & 0 deletions packages/jest-config/src/Deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const deprecatedOptions: DeprecatedOptions = {
'"browser"',
)} has been deprecated. Please install "browser-resolve" and use the "resolver" option in Jest configuration as shown in the documentation: https://jestjs.io/docs/configuration#resolver-string`,

collectCoverageOnlyFrom: (_options: {
collectCoverageOnlyFrom?: Record<string, boolean>;
}) => ` Option ${chalk.bold(
'"collectCoverageOnlyFrom"',
)} was replaced by ${chalk.bold('"collectCoverageFrom"')}.

Please update your configuration.`,

extraGlobals: (_options: {extraGlobals?: string}) => ` Option ${chalk.bold(
'"extraGlobals"',
)} was replaced by ${chalk.bold('"sandboxInjectedGlobals"')}.
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-config/src/ValidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const initialOptions: Config.InitialOptions = {
clearMocks: false,
collectCoverage: true,
collectCoverageFrom: ['src', '!public'],
collectCoverageOnlyFrom: {
'<rootDir>/this-directory-is-covered/Covered.js': true,
},
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: [NODE_MODULES_REGEXP],
coverageProvider: 'v8',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,30 @@ exports[`logs a deprecation warning when 'browser' option is passed 1`] = `
}
`;

exports[`logs a deprecation warning when 'collectCoverageOnlyFrom' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</intensity><bold> Deprecation Warning</intensity>:</color>
<yellow></color>
<yellow> Option <bold>"collectCoverageOnlyFrom"</intensity> was replaced by <bold>"collectCoverageFrom"</intensity>.</color>
<yellow></color>
<yellow> Please update your configuration.</color>
<yellow></color>
<yellow> <bold>Configuration Documentation:</intensity></color>
<yellow> https://jestjs.io/docs/configuration</color>
<yellow></color>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`logs a deprecation warning when 'extraGlobals' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Expand Down
73 changes: 15 additions & 58 deletions packages/jest-config/src/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,65 +161,8 @@ describe('automock', () => {
});
});

describe('collectCoverageOnlyFrom', () => {
it('normalizes all paths relative to rootDir', async () => {
const {options} = await normalize(
{
collectCoverageOnlyFrom: {
'bar/baz': true,
'qux/quux/': true,
},
rootDir: '/root/path/foo/',
},
{} as Config.Argv,
);

const expected = Object.create(null);
expected[expectedPathFooBar] = true;
expected[expectedPathFooQux] = true;

expect(options.collectCoverageOnlyFrom).toEqual(expected);
});

it('does not change absolute paths', async () => {
const {options} = await normalize(
{
collectCoverageOnlyFrom: {
'/an/abs/path': true,
'/another/abs/path': true,
},
rootDir: '/root/path/foo',
},
{} as Config.Argv,
);

const expected = Object.create(null);
expected[expectedPathAbs] = true;
expected[expectedPathAbsAnother] = true;

expect(options.collectCoverageOnlyFrom).toEqual(expected);
});

it('substitutes <rootDir> tokens', async () => {
const {options} = await normalize(
{
collectCoverageOnlyFrom: {
'<rootDir>/bar/baz': true,
},
rootDir: '/root/path/foo',
},
{} as Config.Argv,
);

const expected = Object.create(null);
expected[expectedPathFooBar] = true;

expect(options.collectCoverageOnlyFrom).toEqual(expected);
});
});

describe('collectCoverageFrom', () => {
it('substitutes <rootDir> tokens', async () => {
it('ignores <rootDir> tokens', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const barBaz = 'bar/baz';
const quxQuux = 'qux/quux/';
const notQuxQuux = `!${quxQuux}`;
Expand Down Expand Up @@ -2014,6 +1957,20 @@ describe('logs a deprecation warning', () => {
expect(console.warn).toMatchSnapshot();
});

test("when 'collectCoverageOnlyFrom' option is passed", async () => {
await normalize(
{
collectCoverageOnlyFrom: {
'<rootDir>/this-directory-is-covered/Covered.js': true,
},
rootDir: '/root/',
},
{} as Config.Argv,
);

expect(console.warn).toMatchSnapshot();
});

test("when 'extraGlobals' option is passed", async () => {
await normalize(
{
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-config/src/__tests__/setFromArgv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ test('maps special values to valid options', () => {
test('maps regular values to themselves', () => {
const options = {} as Config.InitialOptions;
const argv = {
collectCoverageOnlyFrom: ['a', 'b'],
collectCoverageFrom: '**/*.{js,jsx}',
coverageDirectory: 'covDir',
watchman: true,
} as Config.Argv;

expect(setFromArgv(options, argv)).toMatchObject({
collectCoverageOnlyFrom: ['a', 'b'],
collectCoverageFrom: '**/*.{js,jsx}',
coverageDirectory: 'covDir',
watchman: true,
});
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ const groupOptions = (
ci: options.ci,
collectCoverage: options.collectCoverage,
collectCoverageFrom: options.collectCoverageFrom,
collectCoverageOnlyFrom: options.collectCoverageOnlyFrom,
coverageDirectory: options.coverageDirectory,
coverageProvider: options.coverageProvider,
coverageReporters: options.coverageReporters,
Expand Down
25 changes: 0 additions & 25 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,27 +254,6 @@ const setupBabelJest = (options: Config.InitialOptionsWithRootDir) => {
}
};

const normalizeCollectCoverageOnlyFrom = (
options: Config.InitialOptionsWithRootDir &
Required<Pick<Config.InitialOptions, 'collectCoverageOnlyFrom'>>,
key: keyof Pick<Config.InitialOptions, 'collectCoverageOnlyFrom'>,
) => {
const initialCollectCoverageFrom = options[key];
const collectCoverageOnlyFrom: Array<string> = Array.isArray(
initialCollectCoverageFrom,
)
? initialCollectCoverageFrom // passed from argv
: Object.keys(initialCollectCoverageFrom); // passed from options
return collectCoverageOnlyFrom.reduce((map, filePath) => {
filePath = path.resolve(
options.rootDir,
replaceRootDirInPath(options.rootDir, filePath),
);
map[filePath] = true;
return map;
}, Object.create(null));
};

const normalizeCollectCoverageFrom = (
options: Config.InitialOptions &
Required<Pick<Config.InitialOptions, 'collectCoverageFrom'>>,
Expand Down Expand Up @@ -530,7 +509,6 @@ export default async function normalize(
deprecatedConfig: DEPRECATED_CONFIG,
exampleConfig: VALID_CONFIG,
recursiveDenylist: [
'collectCoverageOnlyFrom',
// 'coverageThreshold' allows to use 'global' and glob strings on the same
// level, there's currently no way we can deal with such config
'coverageThreshold',
Expand Down Expand Up @@ -627,9 +605,6 @@ export default async function normalize(
Required<Pick<Config.InitialOptions, typeof key>>;
let value;
switch (key) {
case 'collectCoverageOnlyFrom':
value = normalizeCollectCoverageOnlyFrom(oldOptions, key);
break;
case 'setupFiles':
case 'setupFilesAfterEnv':
case 'snapshotSerializers':
Expand Down
1 change: 0 additions & 1 deletion packages/jest-core/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ describe('Watch mode flows', () => {
${'✔︎'} | ${'changedSince'}
${'✔︎'} | ${'collectCoverage'}
${'✔︎'} | ${'collectCoverageFrom'}
${'✔︎'} | ${'collectCoverageOnlyFrom'}
${'✔︎'} | ${'coverageDirectory'}
${'✔︎'} | ${'coverageReporters'}
${'✖︎'} | ${'coverageThreshold'}
Expand Down
4 changes: 0 additions & 4 deletions packages/jest-core/src/lib/updateGlobalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ export default function updateGlobalConfig(
newConfig.collectCoverageFrom = options.collectCoverageFrom;
}

if (options.collectCoverageOnlyFrom !== undefined) {
newConfig.collectCoverageOnlyFrom = options.collectCoverageOnlyFrom;
}

if (options.coverageDirectory !== undefined) {
newConfig.coverageDirectory = options.coverageDirectory;
}
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export default async function watch(
changedSince,
collectCoverage,
collectCoverageFrom,
collectCoverageOnlyFrom,
coverageDirectory,
coverageReporters,
findRelatedTests,
Expand All @@ -134,7 +133,6 @@ export default async function watch(
changedSince,
collectCoverage,
collectCoverageFrom,
collectCoverageOnlyFrom,
coverageDirectory,
coverageReporters,
findRelatedTests,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-phabricator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ final class JestUnitTestEngine extends ArcanistUnitTestEngine {
if (count($paths) < self::TOO_MANY_FILES_TO_COVER) {
$options[] = '--findRelatedTests ' . join(' ', $paths);
$options[] = '--coverage';
$options[] = '--collectCoverageOnlyFrom '. join(' ', $paths);
$options[] = '--collectCoverageFrom '. join(' ', $paths);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. Not sure how to try this out.

}

return $options;
Expand Down
1 change: 0 additions & 1 deletion packages/jest-repl/src/cli/runtime-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export async function run(
changedFiles: undefined,
collectCoverage: false,
collectCoverageFrom: [],
collectCoverageOnlyFrom: undefined,
coverageProvider: 'v8',
sourcesRelatedToTestsInChangedFiles: undefined,
},
Expand Down
1 change: 0 additions & 1 deletion packages/jest-reporters/src/generateEmptyCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default async function generateEmptyCoverage(
changedFiles,
collectCoverage: globalConfig.collectCoverage,
collectCoverageFrom: globalConfig.collectCoverageFrom,
collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom,
coverageProvider: globalConfig.coverageProvider,
sourcesRelatedToTestsInChangedFiles,
};
Expand Down
1 change: 0 additions & 1 deletion packages/jest-runner/src/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ async function runTestInternal(
changedFiles: context.changedFiles,
collectCoverage: globalConfig.collectCoverage,
collectCoverageFrom: globalConfig.collectCoverageFrom,
collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom,
coverageProvider: globalConfig.coverageProvider,
sourcesRelatedToTestsInChangedFiles:
context.sourcesRelatedToTestsInChangedFiles,
Expand Down
1 change: 0 additions & 1 deletion packages/jest-runtime/src/__mocks__/createRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ module.exports = async function createRuntime(filename, projectConfig) {
changedFiles: undefined,
collectCoverage: false,
collectCoverageFrom: [],
collectCoverageOnlyFrom: undefined,
coverageProvider: 'v8',
sourcesRelatedToTestsInChangedFiles: undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,6 @@ function getCoverageOptions(
return {
collectCoverage: globalConfig.collectCoverage,
collectCoverageFrom: globalConfig.collectCoverageFrom,
collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom,
coverageProvider: globalConfig.coverageProvider,
supportsDynamicImport: false,
supportsExportNamespaceFrom: false,
Expand Down
Loading