Skip to content

Commit

Permalink
fix forceExit (jestjs#4105)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov authored and cpojer committed Jul 22, 2017
1 parent 3ce4d9f commit 70a2179
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
46 changes: 46 additions & 0 deletions integration_tests/__tests__/force_exit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

import runJest from '../runJest';
import {cleanup, extractSummary, writeFiles} from '../utils';
import os from 'os';
import path from 'path';

const skipOnWindows = require('skipOnWindows');
const DIR = path.resolve(os.tmpdir(), 'force_exit_test');

skipOnWindows.suite();

beforeEach(() => cleanup(DIR));
afterEach(() => cleanup(DIR));

test('exits the process after test are done but before timers complete', () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'__tests__/test.test.js': `
test('finishes before the timer is complete', () => {
setTimeout(() => console.log('TIMER_DONE'), 500);
});
`,
'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}),
});

let stdout;
({stdout} = runJest(DIR));
expect(stdout).toMatch(/TIMER_DONE/);
writeFiles(DIR, {
'package.json': JSON.stringify({
jest: {forceExit: true, testEnvironment: 'node'},
}),
});

({stdout} = runJest(DIR));
expect(stdout).not.toMatch(/TIMER_DONE/);
});
5 changes: 2 additions & 3 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function run(maybeArgv?: Argv, project?: Path) {
const runCLIFn = _getRunCLIFn(projects);

const {results, globalConfig} = await runCLIFn(argv, projects);
_readResultsAndExit(argv, results, globalConfig);
_readResultsAndExit(results, globalConfig);
}

const runCLI = async (
Expand Down Expand Up @@ -99,13 +99,12 @@ const runCLI = async (
};

const _readResultsAndExit = (
argv: Argv,
result: ?AggregatedResult,
globalConfig: GlobalConfig,
) => {
const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
process.on('exit', () => process.exit(code));
if (argv && argv.forceExit) {
if (globalConfig.forceExit) {
process.exit(code);
}
};
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ function normalize(options: InitialOptions, argv: Argv) {
case 'coverageThreshold':
case 'expand':
case 'globals':
case 'forceExit':
case 'listTests':
case 'logHeapUsage':
case 'mapCoverage':
Expand Down

0 comments on commit 70a2179

Please sign in to comment.