Skip to content

Commit

Permalink
optimize message
Browse files Browse the repository at this point in the history
  • Loading branch information
F3n67u committed Apr 1, 2022
1 parent 4871daa commit 43e0fa8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 8 deletions.
46 changes: 44 additions & 2 deletions e2e/__tests__/selectProjects.test.ts
Expand Up @@ -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./,
);
});
});
Expand Down
7 changes: 6 additions & 1 deletion packages/jest-core/src/cli/index.ts
Expand Up @@ -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(
Expand Down
31 changes: 26 additions & 5 deletions packages/jest-core/src/getSelectProjectsMessage.ts
Expand Up @@ -11,17 +11,38 @@ import getProjectDisplayName from './getProjectDisplayName';

export default function getSelectProjectsMessage(
projectConfigs: Array<Config.ProjectConfig>,
opts: {
ignoreProjects: Array<string> | undefined;
selectProjects: Array<string> | 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<string> | undefined;
selectProjects: Array<string> | 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(
Expand Down

0 comments on commit 43e0fa8

Please sign in to comment.