From 287aad44d14c83367a0748568c0c6a9dd37b1446 Mon Sep 17 00:00:00 2001 From: feng Date: Thu, 31 Mar 2022 22:35:09 +0800 Subject: [PATCH 01/12] Add `--ignoreProjects` CLI argument to ignore test suites by project name --- docs/CLI.md | 6 +++- packages/jest-cli/src/cli/args.ts | 9 +++++- packages/jest-core/src/cli/index.ts | 9 +++--- .../src/getConfigsOfProjectsToRun.ts | 32 +++++++++++++++++-- packages/jest-types/src/Config.ts | 1 + 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 7263a4676883..da957a0ed4e6 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -224,6 +224,10 @@ This feature is an escape-hatch. If Jest doesn't exit at the end of a test run, Show the help information, similar to this page. +### `--igoreProjects ... ` + +Ignore the tests of the specified projects. Jest uses the attribute `displayName` in the configuration to identify each project. If you use this option, you should provide a `displayName` to all your projects. + ### `--init` Generate a basic configuration file. Based on your project, Jest will ask you a few questions that will help to generate a `jest.config.js` file with a short description for each option. @@ -332,7 +336,7 @@ The default regex matching works fine on small runs, but becomes slow if provide ### `--selectProjects ... ` -Run only the tests of the specified projects. Jest uses the attribute `displayName` in the configuration to identify each project. If you use this option, you should provide a `displayName` to all your projects. +Run the tests of the specified projects. Jest uses the attribute `displayName` in the configuration to identify each project. If you use this option, you should provide a `displayName` to all your projects. ### `--setupFilesAfterEnv ... ` diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index 57c55a59f129..ea95567ca101 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -301,6 +301,13 @@ export const options = { 'A JSON string with map of variables for the haste module system', type: 'string', }, + ignoreProjects: { + description: + 'Ignore the tests of the specified projects.' + + 'Jest uses the attribute `displayName` in the configuration to identify each project.', + string: true, + type: Array, + }, init: { description: 'Generate a basic configuration file', type: 'boolean', @@ -502,7 +509,7 @@ export const options = { }, selectProjects: { description: - 'Run only the tests of the specified projects.' + + 'Run the tests of the specified projects.' + 'Jest uses the attribute `displayName` in the configuration to identify each project.', string: true, type: 'array', diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index 61bdb12d8d8f..8563be024371 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -71,16 +71,15 @@ export async function runCLI( exit(0); } - let configsOfProjectsToRun = configs; + const configsOfProjectsToRun = getConfigsOfProjectsToRun(configs, { + ignoreProjects: argv.ignoreProjects, + selectProjects: argv.selectProjects, + }); if (argv.selectProjects) { const namesMissingWarning = getProjectNamesMissingWarning(configs); if (namesMissingWarning) { outputStream.write(namesMissingWarning); } - configsOfProjectsToRun = getConfigsOfProjectsToRun( - argv.selectProjects, - configs, - ); outputStream.write(getSelectProjectsMessage(configsOfProjectsToRun)); } diff --git a/packages/jest-core/src/getConfigsOfProjectsToRun.ts b/packages/jest-core/src/getConfigsOfProjectsToRun.ts index b8b8288ccc68..104708ee8f8d 100644 --- a/packages/jest-core/src/getConfigsOfProjectsToRun.ts +++ b/packages/jest-core/src/getConfigsOfProjectsToRun.ts @@ -9,12 +9,38 @@ import type {Config} from '@jest/types'; import getProjectDisplayName from './getProjectDisplayName'; export default function getConfigsOfProjectsToRun( - namesOfProjectsToRun: Array, projectConfigs: Array, + opts: { + ignoreProjects: Array | undefined; + selectProjects: Array | undefined; + }, ): Array { - const setOfProjectsToRun = new Set(namesOfProjectsToRun); + const projectFilter = createProjectFilter(opts); return projectConfigs.filter(config => { const name = getProjectDisplayName(config); - return name && setOfProjectsToRun.has(name); + return projectFilter(name); }); } + +function createProjectFilter(opts: { + ignoreProjects: Array | undefined; + selectProjects: Array | undefined; +}) { + const {selectProjects, ignoreProjects} = opts; + + const always = () => true; + + const selected = selectProjects + ? (name: string | undefined) => name && selectProjects.includes(name) + : always; + + const notIgnore = ignoreProjects + ? (name: string | undefined) => !name || !ignoreProjects.includes(name) + : always; + + function test(name: string | undefined) { + return selected(name) && notIgnore(name); + } + + return test; +} diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index 80243eb45512..dd26c13e0bab 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -468,6 +468,7 @@ export type Argv = Arguments< roots: Array; runInBand: boolean; selectProjects: Array; + ignoreProjects: Array; setupFiles: Array; setupFilesAfterEnv: Array; shard: string; From 9d2e091afbb4d3e1c6909275941b6a46c35c0ed2 Mon Sep 17 00:00:00 2001 From: feng Date: Thu, 31 Mar 2022 22:55:38 +0800 Subject: [PATCH 02/12] add test --- e2e/__tests__/selectProjects.test.ts | 40 ++++++++++++++++++++++++++++ packages/jest-core/src/cli/index.ts | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/e2e/__tests__/selectProjects.test.ts b/e2e/__tests__/selectProjects.test.ts index 2e48085b6cf1..81ed72ade57d 100644 --- a/e2e/__tests__/selectProjects.test.ts +++ b/e2e/__tests__/selectProjects.test.ts @@ -111,6 +111,46 @@ describe('Given a config with two named projects, first-project and second-proje ); }); }); + + describe('when Jest is started with `--ignoreProjects first-project', () => { + let result: RunJestJsonResult; + beforeAll(() => { + result = runWithJson('select-projects', [ + '--ignoreProjects', + 'first-project', + ]); + }); + it('runs the tests in the second project only', () => { + expect(result.json).toHaveProperty('success', true); + expect(result.json).toHaveProperty('numTotalTests', 1); + expect(result.json.testResults.map(({name}) => name)).toEqual([ + resolve(dir, '__tests__/second-project.test.js'), + ]); + }); + it('prints that only second-project will run', () => { + expect(result.stderr).toMatch(/^Running one project: second-project/); + }); + }); + + describe('when Jest is started with `--ignoreProjects second-project', () => { + let result: RunJestJsonResult; + beforeAll(() => { + result = runWithJson('select-projects', [ + '--ignoreProjects', + 'second-project', + ]); + }); + it('runs the tests in the first project only', () => { + expect(result.json).toHaveProperty('success', true); + expect(result.json).toHaveProperty('numTotalTests', 1); + expect(result.json.testResults.map(({name}) => name)).toEqual([ + resolve(dir, '__tests__/first-project.test.js'), + ]); + }); + it('prints that only first-project will run', () => { + expect(result.stderr).toMatch(/^Running one project: first-project/); + }); + }); }); describe('Given a config with two projects, first-project and an unnamed project', () => { diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index 8563be024371..fc95edd3c3f4 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -75,7 +75,7 @@ export async function runCLI( ignoreProjects: argv.ignoreProjects, selectProjects: argv.selectProjects, }); - if (argv.selectProjects) { + if (argv.selectProjects || argv.ignoreProjects) { const namesMissingWarning = getProjectNamesMissingWarning(configs); if (namesMissingWarning) { outputStream.write(namesMissingWarning); From 7f9090f9ab55e9580c83d367d477a2e1b51716f6 Mon Sep 17 00:00:00 2001 From: feng Date: Thu, 31 Mar 2022 23:08:27 +0800 Subject: [PATCH 03/12] args check --- packages/jest-cli/src/__tests__/cli/args.test.ts | 6 ++++++ packages/jest-cli/src/cli/args.ts | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/packages/jest-cli/src/__tests__/cli/args.test.ts b/packages/jest-cli/src/__tests__/cli/args.test.ts index f40f37aeb873..89593f889ebd 100644 --- a/packages/jest-cli/src/__tests__/cli/args.test.ts +++ b/packages/jest-cli/src/__tests__/cli/args.test.ts @@ -81,6 +81,12 @@ describe('check', () => { ); }); + it('raises an exception if ignoreProjects is not provided any project names', () => { + expect(() => check(argv({ignoreProjects: []}))).toThrow( + 'The --ignoreProjects option requires the name of at least one project to be specified.\n', + ); + }); + it('raises an exception if config is not a valid JSON string', () => { expect(() => check(argv({config: 'x:1'}))).toThrow( 'The --config option requires a JSON string literal, or a file path with one of these extensions: .js, .ts, .mjs, .cjs, .json', diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index ea95567ca101..0aca0b106142 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -68,6 +68,13 @@ export function check(argv: Config.Argv): true { ); } + if (argv.ignoreProjects && argv.ignoreProjects.length === 0) { + throw new Error( + 'The --ignoreProjects option requires the name of at least one project to be specified.\n' + + 'Example usage: jest --ignoreProjects my-first-project my-second-project', + ); + } + if ( argv.config && !isJSONString(argv.config) && From 6f7f542ccea7f3720c51a66205da4d31dacbc40f Mon Sep 17 00:00:00 2001 From: feng Date: Thu, 31 Mar 2022 23:20:46 +0800 Subject: [PATCH 04/12] fix type --- packages/jest-cli/src/cli/args.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index 0aca0b106142..e2e0520f30a3 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import type {Options} from 'yargs'; import type {Config} from '@jest/types'; import {constants, isJSONString} from 'jest-config'; @@ -102,7 +103,7 @@ export const usage = export const docs = 'Documentation: https://jestjs.io/'; // The default values are all set in jest-config -export const options = { +export const options: {[key: string]: Options} = { all: { description: 'The opposite of `onlyChanged`. If `onlyChanged` is set by ' + @@ -313,7 +314,7 @@ export const options = { 'Ignore the tests of the specified projects.' + 'Jest uses the attribute `displayName` in the configuration to identify each project.', string: true, - type: Array, + type: 'array', }, init: { description: 'Generate a basic configuration file', @@ -709,4 +710,4 @@ export const options = { '--no-watchman.', type: 'boolean', }, -} as const; +}; From 185b732f07dbfcc4f0fff340d6263c60ec96b77c Mon Sep 17 00:00:00 2001 From: feng Date: Thu, 31 Mar 2022 23:29:39 +0800 Subject: [PATCH 05/12] add more test --- e2e/__tests__/selectProjects.test.ts | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/e2e/__tests__/selectProjects.test.ts b/e2e/__tests__/selectProjects.test.ts index 81ed72ade57d..b1ed9b942a59 100644 --- a/e2e/__tests__/selectProjects.test.ts +++ b/e2e/__tests__/selectProjects.test.ts @@ -151,6 +151,49 @@ describe('Given a config with two named projects, first-project and second-proje expect(result.stderr).toMatch(/^Running one project: first-project/); }); }); + + describe('when Jest is started with `--ignoreProjects third-project`', () => { + let result: RunJestJsonResult; + beforeAll(() => { + result = runWithJson('select-projects', [ + '--ignoreProjects', + 'third-project', + ]); + }); + it('runs the tests in the first and second projects', () => { + expect(result.json).toHaveProperty('success', true); + expect(result.json).toHaveProperty('numTotalTests', 2); + expect(result.json.testResults.map(({name}) => name).sort()).toEqual([ + resolve(dir, '__tests__/first-project.test.js'), + resolve(dir, '__tests__/second-project.test.js'), + ]); + }); + it('prints that both first-project and second-project will run', () => { + expect(result.stderr).toMatch( + /^Running 2 projects:\n- first-project\n- second-project/, + ); + }); + }); + + describe('when Jest is started with `--ignoreProjects first-project second-project`', () => { + let result: RunJestResult; + beforeAll(() => { + result = run('select-projects', [ + '--ignoreProjects', + 'first-project', + 'second-project', + ]); + }); + it('fails', () => { + expect(result).toHaveProperty('failed', true); + }); + // FIXME(F3n67u) + it.skip('prints that no project was found', () => { + expect(result.stdout).toMatch( + /^You provided values for --selectProjects but no projects were found matching the selection/, + ); + }); + }); }); describe('Given a config with two projects, first-project and an unnamed project', () => { @@ -225,4 +268,31 @@ describe('Given a config with two projects, first-project and an unnamed project ); }); }); + + describe('when Jest is started with `--ignoreProjects first-project`', () => { + let result: RunJestJsonResult; + beforeAll(() => { + result = runWithJson('select-projects-missing-name', [ + '--ignoreProjects', + 'first-project', + ]); + }); + it('runs the tests in the second project only', () => { + expect(result.json.success).toBe(true); + expect(result.json.numTotalTests).toBe(1); + expect(result.json.testResults.map(({name}) => name)).toEqual([ + resolve(dir, '__tests__/second-project.test.js'), + ]); + }); + // FIXME(F3n67u) + it('prints that a project does not have a name', () => { + expect(result.stderr).toMatch( + /^You provided values for --selectProjects but a project does not have a name/, + ); + }); + it('prints that only second-project will run', () => { + const stderrThirdLine = result.stderr.split('\n')[2]; + expect(stderrThirdLine).toMatch(/^Running one project: second-project/); + }); + }); }); From 6942a8ef28b9c438bd2e91a4ded17ae59be4f69f Mon Sep 17 00:00:00 2001 From: feng Date: Thu, 31 Mar 2022 23:57:51 +0800 Subject: [PATCH 06/12] adjust warning --- e2e/__tests__/selectProjects.test.ts | 3 +-- packages/jest-core/src/cli/index.ts | 5 ++++- .../jest-core/src/getProjectNamesMissingWarning.ts | 13 ++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/e2e/__tests__/selectProjects.test.ts b/e2e/__tests__/selectProjects.test.ts index b1ed9b942a59..8746d557f97b 100644 --- a/e2e/__tests__/selectProjects.test.ts +++ b/e2e/__tests__/selectProjects.test.ts @@ -284,10 +284,9 @@ describe('Given a config with two projects, first-project and an unnamed project resolve(dir, '__tests__/second-project.test.js'), ]); }); - // FIXME(F3n67u) it('prints that a project does not have a name', () => { expect(result.stderr).toMatch( - /^You provided values for --selectProjects but a project does not have a name/, + /^You provided values for --ignoreProjects but a project does not have a name/, ); }); it('prints that only second-project will run', () => { diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index fc95edd3c3f4..f3e4c33bcbaf 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -76,7 +76,10 @@ export async function runCLI( selectProjects: argv.selectProjects, }); if (argv.selectProjects || argv.ignoreProjects) { - const namesMissingWarning = getProjectNamesMissingWarning(configs); + const namesMissingWarning = getProjectNamesMissingWarning(configs, { + ignoreProjects: argv.ignoreProjects, + selectProjects: argv.selectProjects, + }); if (namesMissingWarning) { outputStream.write(namesMissingWarning); } diff --git a/packages/jest-core/src/getProjectNamesMissingWarning.ts b/packages/jest-core/src/getProjectNamesMissingWarning.ts index 53f0543d1cc8..947955dfefcf 100644 --- a/packages/jest-core/src/getProjectNamesMissingWarning.ts +++ b/packages/jest-core/src/getProjectNamesMissingWarning.ts @@ -11,6 +11,10 @@ import getProjectDisplayName from './getProjectDisplayName'; export default function getProjectNamesMissingWarning( projectConfigs: Array, + opts: { + ignoreProjects: Array | undefined; + selectProjects: Array | undefined; + }, ): string | undefined { const numberOfProjectsWithoutAName = projectConfigs.filter( config => !getProjectDisplayName(config), @@ -18,8 +22,15 @@ export default function getProjectNamesMissingWarning( if (numberOfProjectsWithoutAName === 0) { return undefined; } + const args: Array = []; + if (opts.selectProjects) { + args.push('--selectProjects'); + } + if (opts.ignoreProjects) { + args.push('--ignoreProjects'); + } return chalk.yellow( - `You provided values for --selectProjects but ${ + `You provided values for ${args.join(' and ')} but ${ numberOfProjectsWithoutAName === 1 ? 'a project does not have a name' : `${numberOfProjectsWithoutAName} projects do not have a name` From a38ddd44080bb79c741000e0e0001138c0ab6e52 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Fri, 1 Apr 2022 08:24:27 +0800 Subject: [PATCH 07/12] Update docs/CLI.md Co-authored-by: Paavo Bennett --- docs/CLI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CLI.md b/docs/CLI.md index da957a0ed4e6..b2f7a8297a2d 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -224,7 +224,7 @@ This feature is an escape-hatch. If Jest doesn't exit at the end of a test run, Show the help information, similar to this page. -### `--igoreProjects ... ` +### `--ignoreProjects ... ` Ignore the tests of the specified projects. Jest uses the attribute `displayName` in the configuration to identify each project. If you use this option, you should provide a `displayName` to all your projects. From bc92ed99c9ec8fa42c02542ab3e87905015487dd Mon Sep 17 00:00:00 2001 From: feng Date: Fri, 1 Apr 2022 12:36:07 +0800 Subject: [PATCH 08/12] refactor notIgnore --- packages/jest-core/src/getConfigsOfProjectsToRun.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-core/src/getConfigsOfProjectsToRun.ts b/packages/jest-core/src/getConfigsOfProjectsToRun.ts index 104708ee8f8d..75542c3d2e7d 100644 --- a/packages/jest-core/src/getConfigsOfProjectsToRun.ts +++ b/packages/jest-core/src/getConfigsOfProjectsToRun.ts @@ -35,7 +35,7 @@ function createProjectFilter(opts: { : always; const notIgnore = ignoreProjects - ? (name: string | undefined) => !name || !ignoreProjects.includes(name) + ? (name: string | undefined) => !(name && ignoreProjects.includes(name)) : always; function test(name: string | undefined) { From 4871daa6b48ad54875ca7b9fd0f25fbe2e89c8cd Mon Sep 17 00:00:00 2001 From: feng Date: Fri, 1 Apr 2022 12:40:55 +0800 Subject: [PATCH 09/12] unnamed project --- e2e/__tests__/selectProjects.test.ts | 4 +++- packages/jest-core/src/getSelectProjectsMessage.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/e2e/__tests__/selectProjects.test.ts b/e2e/__tests__/selectProjects.test.ts index 8746d557f97b..a7d040e0b2e5 100644 --- a/e2e/__tests__/selectProjects.test.ts +++ b/e2e/__tests__/selectProjects.test.ts @@ -291,7 +291,9 @@ describe('Given a config with two projects, first-project and an unnamed project }); it('prints that only second-project will run', () => { const stderrThirdLine = result.stderr.split('\n')[2]; - expect(stderrThirdLine).toMatch(/^Running one project: second-project/); + expect(stderrThirdLine).toMatch( + /^Running one project: /, + ); }); }); }); diff --git a/packages/jest-core/src/getSelectProjectsMessage.ts b/packages/jest-core/src/getSelectProjectsMessage.ts index 5d3fff3577b4..0d52568eef84 100644 --- a/packages/jest-core/src/getSelectProjectsMessage.ts +++ b/packages/jest-core/src/getSelectProjectsMessage.ts @@ -28,7 +28,8 @@ function getProjectsRunningMessage( projectConfigs: Array, ): string { if (projectConfigs.length === 1) { - const name = getProjectDisplayName(projectConfigs[0]); + const name = + getProjectDisplayName(projectConfigs[0]) ?? ''; return `Running one project: ${chalk.bold(name)}\n`; } const projectsList = projectConfigs From 43e0fa8b322cfec9ba37c4a427f476a7334b250b Mon Sep 17 00:00:00 2001 From: feng Date: Fri, 1 Apr 2022 13:03:22 +0800 Subject: [PATCH 10/12] optimize message --- e2e/__tests__/selectProjects.test.ts | 46 ++++++++++++++++++- packages/jest-core/src/cli/index.ts | 7 ++- .../jest-core/src/getSelectProjectsMessage.ts | 31 +++++++++++-- 3 files changed, 76 insertions(+), 8 deletions(-) diff --git a/e2e/__tests__/selectProjects.test.ts b/e2e/__tests__/selectProjects.test.ts index a7d040e0b2e5..2928fc8c2b18 100644 --- a/e2e/__tests__/selectProjects.test.ts +++ b/e2e/__tests__/selectProjects.test.ts @@ -187,10 +187,52 @@ describe('Given a config with two named projects, first-project and second-proje it('fails', () => { expect(result).toHaveProperty('failed', true); }); - // FIXME(F3n67u) it.skip('prints that no project was found', () => { expect(result.stdout).toMatch( - /^You provided values for --selectProjects but no projects were found matching the selection/, + /^You provided values for --ignoreProjects, but no projects were found matching the selection/, + ); + }); + }); + + describe('when Jest is started with `--selectProjects first-project second-project --ignoreProjects first-project` ', () => { + let result: RunJestJsonResult; + beforeAll(() => { + result = runWithJson('select-projects', [ + '--selectProjects', + 'first-project', + 'second-project', + '--ignoreProjects', + 'first-project', + ]); + }); + it('runs the tests in the second project only', () => { + expect(result.json).toHaveProperty('success', true); + expect(result.json).toHaveProperty('numTotalTests', 1); + expect(result.json.testResults.map(({name}) => name)).toEqual([ + resolve(dir, '__tests__/second-project.test.js'), + ]); + }); + it('prints that only second-project will run', () => { + expect(result.stderr).toMatch(/^Running one project: second-project/); + }); + }); + + describe('when Jest is started with `--selectProjects first-project --ignoreProjects first-project` ', () => { + let result: RunJestResult; + beforeAll(() => { + result = run('select-projects', [ + '--selectProjects', + 'first-project', + '--ignoreProjects', + 'first-project', + ]); + }); + it('fails', () => { + expect(result).toHaveProperty('failed', true); + }); + it.skip('prints that no project was found', () => { + expect(result.stdout).toMatch( + /^You provided values for --selectProjects and --ignoreProjects, but no projects were found matching the selection./, ); }); }); diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index f3e4c33bcbaf..b7727a263b93 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -83,7 +83,12 @@ export async function runCLI( if (namesMissingWarning) { outputStream.write(namesMissingWarning); } - outputStream.write(getSelectProjectsMessage(configsOfProjectsToRun)); + outputStream.write( + getSelectProjectsMessage(configsOfProjectsToRun, { + ignoreProjects: argv.ignoreProjects, + selectProjects: argv.selectProjects, + }), + ); } await _run10000( diff --git a/packages/jest-core/src/getSelectProjectsMessage.ts b/packages/jest-core/src/getSelectProjectsMessage.ts index 0d52568eef84..b8a3a9f40c88 100644 --- a/packages/jest-core/src/getSelectProjectsMessage.ts +++ b/packages/jest-core/src/getSelectProjectsMessage.ts @@ -11,17 +11,38 @@ import getProjectDisplayName from './getProjectDisplayName'; export default function getSelectProjectsMessage( projectConfigs: Array, + opts: { + ignoreProjects: Array | undefined; + selectProjects: Array | undefined; + }, ): string { if (projectConfigs.length === 0) { - return getNoSelectionWarning(); + return getNoSelectionWarning(opts); } return getProjectsRunningMessage(projectConfigs); } -function getNoSelectionWarning(): string { - return chalk.yellow( - 'You provided values for --selectProjects but no projects were found matching the selection.\n', - ); +function getNoSelectionWarning(opts: { + ignoreProjects: Array | undefined; + selectProjects: Array | undefined; +}): string { + if (opts.ignoreProjects && opts.selectProjects) { + return chalk.yellow( + 'You provided values for --selectProjects and --ignoreProjects, but no projects were found matching the selection.\n' + + 'Are you ignoring all the selected projects?\n', + ); + } else if (opts.ignoreProjects) { + return chalk.yellow( + 'You provided values for --ignoreProjects, but no projects were found matching the selection.\n' + + 'Are you ignoring all projects?\n', + ); + } else if (opts.selectProjects) { + return chalk.yellow( + 'You provided values for --selectProjects but no projects were found matching the selection.\n', + ); + } else { + return chalk.yellow('No projects were found.\n'); + } } function getProjectsRunningMessage( From 01315cbe5580db1abc9f059a537796efcd851eac Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Fri, 1 Apr 2022 10:27:17 +0000 Subject: [PATCH 11/12] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index efa038f928b6..88384e57d694 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - `[jest-config]` [**BREAKING**] Rename `extraGlobals` to `sandboxInjectedGlobals` ([#10817](https://github.com/facebook/jest/pull/10817)) - `[jest-config]` [**BREAKING**] Throw an error instead of showing a warning if multiple configs are used ([#12510](https://github.com/facebook/jest/pull/12510)) - `[jest-core]` Pass project config to `globalSetup`/`globalTeardown` function as second argument ([#12440](https://github.com/facebook/jest/pull/12440)) +- `[jest-cli, jest-core]` Add `--ignoreProjects` CLI argument to ignore test suites by project name ([#12620](https://github.com/facebook/jest/pull/12620)) - `[jest-environment-jsdom]` [**BREAKING**] Upgrade jsdom to 19.0.0 ([#12290](https://github.com/facebook/jest/pull/12290)) - `[jest-environment-jsdom]` [**BREAKING**] Add default `browser` condition to `exportConditions` for `jsdom` environment ([#11924](https://github.com/facebook/jest/pull/11924)) - `[jest-environment-jsdom]` [**BREAKING**] Pass global config to Jest environment constructor for `jsdom` environment ([#12461](https://github.com/facebook/jest/pull/12461)) From f71c418edd7dfc3c70ed8d1fdccc485418633dc8 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Fri, 1 Apr 2022 11:14:44 +0000 Subject: [PATCH 12/12] type sort-keys --- packages/jest-types/src/Config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index dd26c13e0bab..d93d77c87b69 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -440,6 +440,7 @@ export type Argv = Arguments< globalSetup: string | null | undefined; globalTeardown: string | null | undefined; haste: string; + ignoreProjects: Array; init: boolean; injectGlobals: boolean; json: boolean; @@ -468,7 +469,6 @@ export type Argv = Arguments< roots: Array; runInBand: boolean; selectProjects: Array; - ignoreProjects: Array; setupFiles: Array; setupFilesAfterEnv: Array; shard: string;