Skip to content

Commit

Permalink
Expose onComplete event in jest.run()
Browse files Browse the repository at this point in the history
  • Loading branch information
eldarshamukhamedov committed Jun 6, 2017
1 parent 1eae7f8 commit 931927f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@

import type {Path} from 'types/Config';
import type {Argv} from 'types/Argv';
import type {AggregatedResult} from 'types/TestResult';

const {validateCLIOptions} = require('jest-util');
const yargs = require('yargs');
const args = require('./args');
const getJest = require('./getJest');
const runCLI = require('./runCLI');

function run(argv?: Argv, project?: Path) {
function run(
argv?: Argv,
project?: Path,
onComplete?: (results: ?AggregatedResult) => void,
) {
argv = yargs(argv || process.argv.slice(2))
.usage(args.usage)
.help()
Expand All @@ -28,7 +33,10 @@ function run(argv?: Argv, project?: Path) {

validateCLIOptions(argv, args.options);

if (!project) {
if (typeof project === 'function') {

This comment has been minimized.

Copy link
@rogeliog

rogeliog Jun 8, 2017

Should this be onComplete ==== 'function'?
Also, do we need to check if !project as an independent if rather than an else if?

onComplete = project;
project = process.cwd();
} else if (!project) {
project = process.cwd();
}

Expand All @@ -38,10 +46,14 @@ function run(argv?: Argv, project?: Path) {

const execute = argv.projects.length === 1 ? getJest(project).runCLI : runCLI;
execute(argv, argv.projects, result => {
const code = !result || result.success ? 0 : 1;
process.on('exit', () => process.exit(code));
if (argv && argv.forceExit) {
process.exit(code);
if (typeof onComplete === 'function') {
onComplete(result);
} else {
const code = !result || result.success ? 0 : 1;
process.on('exit', () => process.exit(code));
if (argv && argv.forceExit) {
process.exit(code);
}
}
});
}
Expand Down

0 comments on commit 931927f

Please sign in to comment.