Skip to content

Commit 43e0fa8

Browse files
committed
optimize message
1 parent 4871daa commit 43e0fa8

File tree

3 files changed

+76
-8
lines changed

3 files changed

+76
-8
lines changed

e2e/__tests__/selectProjects.test.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,52 @@ describe('Given a config with two named projects, first-project and second-proje
187187
it('fails', () => {
188188
expect(result).toHaveProperty('failed', true);
189189
});
190-
// FIXME(F3n67u)
191190
it.skip('prints that no project was found', () => {
192191
expect(result.stdout).toMatch(
193-
/^You provided values for --selectProjects but no projects were found matching the selection/,
192+
/^You provided values for --ignoreProjects, but no projects were found matching the selection/,
193+
);
194+
});
195+
});
196+
197+
describe('when Jest is started with `--selectProjects first-project second-project --ignoreProjects first-project` ', () => {
198+
let result: RunJestJsonResult;
199+
beforeAll(() => {
200+
result = runWithJson('select-projects', [
201+
'--selectProjects',
202+
'first-project',
203+
'second-project',
204+
'--ignoreProjects',
205+
'first-project',
206+
]);
207+
});
208+
it('runs the tests in the second project only', () => {
209+
expect(result.json).toHaveProperty('success', true);
210+
expect(result.json).toHaveProperty('numTotalTests', 1);
211+
expect(result.json.testResults.map(({name}) => name)).toEqual([
212+
resolve(dir, '__tests__/second-project.test.js'),
213+
]);
214+
});
215+
it('prints that only second-project will run', () => {
216+
expect(result.stderr).toMatch(/^Running one project: second-project/);
217+
});
218+
});
219+
220+
describe('when Jest is started with `--selectProjects first-project --ignoreProjects first-project` ', () => {
221+
let result: RunJestResult;
222+
beforeAll(() => {
223+
result = run('select-projects', [
224+
'--selectProjects',
225+
'first-project',
226+
'--ignoreProjects',
227+
'first-project',
228+
]);
229+
});
230+
it('fails', () => {
231+
expect(result).toHaveProperty('failed', true);
232+
});
233+
it.skip('prints that no project was found', () => {
234+
expect(result.stdout).toMatch(
235+
/^You provided values for --selectProjects and --ignoreProjects, but no projects were found matching the selection./,
194236
);
195237
});
196238
});

packages/jest-core/src/cli/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ export async function runCLI(
8383
if (namesMissingWarning) {
8484
outputStream.write(namesMissingWarning);
8585
}
86-
outputStream.write(getSelectProjectsMessage(configsOfProjectsToRun));
86+
outputStream.write(
87+
getSelectProjectsMessage(configsOfProjectsToRun, {
88+
ignoreProjects: argv.ignoreProjects,
89+
selectProjects: argv.selectProjects,
90+
}),
91+
);
8792
}
8893

8994
await _run10000(

packages/jest-core/src/getSelectProjectsMessage.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,38 @@ import getProjectDisplayName from './getProjectDisplayName';
1111

1212
export default function getSelectProjectsMessage(
1313
projectConfigs: Array<Config.ProjectConfig>,
14+
opts: {
15+
ignoreProjects: Array<string> | undefined;
16+
selectProjects: Array<string> | undefined;
17+
},
1418
): string {
1519
if (projectConfigs.length === 0) {
16-
return getNoSelectionWarning();
20+
return getNoSelectionWarning(opts);
1721
}
1822
return getProjectsRunningMessage(projectConfigs);
1923
}
2024

21-
function getNoSelectionWarning(): string {
22-
return chalk.yellow(
23-
'You provided values for --selectProjects but no projects were found matching the selection.\n',
24-
);
25+
function getNoSelectionWarning(opts: {
26+
ignoreProjects: Array<string> | undefined;
27+
selectProjects: Array<string> | undefined;
28+
}): string {
29+
if (opts.ignoreProjects && opts.selectProjects) {
30+
return chalk.yellow(
31+
'You provided values for --selectProjects and --ignoreProjects, but no projects were found matching the selection.\n' +
32+
'Are you ignoring all the selected projects?\n',
33+
);
34+
} else if (opts.ignoreProjects) {
35+
return chalk.yellow(
36+
'You provided values for --ignoreProjects, but no projects were found matching the selection.\n' +
37+
'Are you ignoring all projects?\n',
38+
);
39+
} else if (opts.selectProjects) {
40+
return chalk.yellow(
41+
'You provided values for --selectProjects but no projects were found matching the selection.\n',
42+
);
43+
} else {
44+
return chalk.yellow('No projects were found.\n');
45+
}
2546
}
2647

2748
function getProjectsRunningMessage(

0 commit comments

Comments
 (0)