From 7386194d94ec8b0d0faee766fe98f0f4f2ece8a2 Mon Sep 17 00:00:00 2001 From: Haoliang Gao Date: Mon, 9 Oct 2017 19:58:06 -0500 Subject: [PATCH] fix: force exit when runner complete (#83) --- lib/cmd/test.js | 2 ++ test/fixtures/no-exit/test/foo.test.js | 16 ++++++++++++++++ test/lib/cmd/test.test.js | 8 ++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/fixtures/no-exit/test/foo.test.js diff --git a/lib/cmd/test.js b/lib/cmd/test.js index 076c00b3..d601ee56 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -59,6 +59,8 @@ class TestCommand extends Command { /* istanbul ignore next */ testArgv.timeout = testArgv.timeout || process.env.TEST_TIMEOUT || 60000; testArgv.reporter = testArgv.reporter || process.env.TEST_REPORTER; + // force exit + testArgv.exit = true; if (debug) { // --no-timeouts diff --git a/test/fixtures/no-exit/test/foo.test.js b/test/fixtures/no-exit/test/foo.test.js new file mode 100644 index 00000000..d9615257 --- /dev/null +++ b/test/fixtures/no-exit/test/foo.test.js @@ -0,0 +1,16 @@ +'use strict'; + +const http = require('http'); +const assert = require('assert'); + +describe('mocha-test', () => { + it('should work', () => { + assert(true); + }); +}); + +const server = http.createServer((req, res) => { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end('okay'); +}); +server.listen(); diff --git a/test/lib/cmd/test.test.js b/test/lib/cmd/test.test.js index e5d71d94..1ccb351f 100644 --- a/test/lib/cmd/test.test.js +++ b/test/lib/cmd/test.test.js @@ -110,6 +110,14 @@ describe('test/lib/cmd/test.test.js', () => { .end(); }); + it('should force exit', () => { + const cwd = path.join(__dirname, '../../fixtures/no-exit'); + return coffee.fork(eggBin, [ 'test' ], { cwd }) + .debug() + .expect('code', 0) + .end(); + }); + describe('simplify mocha error stack', () => { const cwd = path.join(__dirname, '../../fixtures/test-files-stack');