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

Support outputFile option for listTests option #14944

17 changes: 13 additions & 4 deletions packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,22 @@ export default async function runJest({

if (globalConfig.listTests) {
const testsPaths = [...new Set(allTests.map(test => test.path))];
/* eslint-disable no-console */
let testsListOutput;

if (globalConfig.json) {
console.log(JSON.stringify(testsPaths));
testsListOutput = JSON.stringify(testsPaths);
} else {
testsListOutput = testsPaths.join('\n');
}

if (globalConfig.outputFile) {
const outputFile = path.resolve(process.cwd(), globalConfig.outputFile);
fs.writeFileSync(outputFile, testsListOutput, 'utf8');
} else {
console.log(testsPaths.join('\n'));
/* eslint-disable no-console */
console.log(testsListOutput);
/* eslint-enable */
manoraj marked this conversation as resolved.
Show resolved Hide resolved
}
/* eslint-enable */

onComplete && onComplete(makeEmptyAggregatedTestResult());
return;
Expand Down
Loading