Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

assorted test fixes & refactors (#4240)

Christopher Hiller2509ab5f261e
diff --git a/.mocharc.yml b/.mocharc.yml
index fc4c9733..dfb82e07 100644
--- a/.mocharc.yml
+++ b/.mocharc.yml
@@ -1,7 +1,14 @@
-require: test/setup
-ui: bdd
+require: 'test/setup'
+ui: 'bdd'
global:
- - okGlobalA,okGlobalB
- - okGlobalC
- - callback*
-timeout: 300
+ - 'okGlobalA,okGlobalB'
+ - 'okGlobalC'
+ - 'callback*'
+timeout: 1000
+watch-ignore:
+ - '.*'
+ - 'docs/_dist/**'
+ - 'docs/_site/**'
+ - 'node_modules'
+ - 'coverage'
+ - 'cache'
diff --git a/example/config/.mocharc.yml b/example/config/.mocharc.yml
index da5a0a0c..a310525b 100644
--- a/example/config/.mocharc.yml
+++ b/example/config/.mocharc.yml
@@ -8,39 +8,39 @@ delay: false
diff: true
exit: false # could be expressed as "no-exit: true"
extension:
- - js
+ - 'js'
# fgrep and grep are mutually exclusive
# fgrep: something
file:
- - /path/to/some/file
- - /path/to/some/other/file
+ - '/path/to/some/file'
+ - '/path/to/some/other/file'
forbid-only: false
forbid-pending: false
full-trace: false
global:
- - jQuery
- - $
+ - 'jQuery'
+ - '$'
# fgrep and grep are mutually exclusive
# grep: something
growl: false
ignore:
- - /path/to/some/ignored/file
+ - '/path/to/some/ignored/file'
inline-diffs: false
# needs to be used with grep or fgrep
# invert: false
recursive: false
-reporter: spec
+reporter: 'spec'
reporter-option:
- - foo=bar
- - baz=quux
+ - 'foo=bar'
+ - 'baz=quux'
require: '@babel/register'
retries: 1
slow: 75
sort: false
-spec: test/**/*.spec.js # the positional arguments!
+spec: 'test/**/*.spec.js' # the positional arguments!
timeout: false # same as "no-timeout: true" or "timeout: 0"
trace-warnings: true # node flags ok
-ui: bdd
+ui: 'bdd'
v8-stack-trace-limit: 100 # V8 flags are prepended with "v8-"
watch: false
watch-files:
diff --git a/lib/mocha.js b/lib/mocha.js
index 017daa1e..40718d09 100644
--- a/lib/mocha.js
+++ b/lib/mocha.js
@@ -388,7 +388,9 @@ Mocha.unloadFile = function(file) {
* @chainable
*/
Mocha.prototype.unloadFiles = function() {
- this.files.forEach(Mocha.unloadFile);
+ this.files.forEach(function(file) {
+ Mocha.unloadFile(file);
+ });
return this;
};
diff --git a/test/integration/diffs.spec.js b/test/integration/diffs.spec.js
index 44b30de1..ac9ad18d 100644
--- a/test/integration/diffs.spec.js
+++ b/test/integration/diffs.spec.js
@@ -72,7 +72,7 @@ describe('diffs', function() {
var diffs, expected;
before(function(done) {
- run('diffs/diffs.fixture.js', ['-C'], function(err, res) {
+ run('diffs/diffs.fixture.js', [], function(err, res) {
if (err) {
done(err);
return;
diff --git a/test/integration/fixtures/uncaught/listeners.fixture.js b/test/integration/fixtures/uncaught/listeners.fixture.js
index 3ad398cf..69c40592 100644
--- a/test/integration/fixtures/uncaught/listeners.fixture.js
+++ b/test/integration/fixtures/uncaught/listeners.fixture.js
@@ -3,7 +3,8 @@
const assert = require('assert');
const mocha = require("../../../../lib/mocha");
-for (let i = 0; i < 15; i++) {
+// keep this low to avoid warning
+for (let i = 0; i < 5; i++) {
const r = new mocha.Runner(new mocha.Suite("" + i, undefined));
r.run();
}
diff --git a/test/integration/options/watch.spec.js b/test/integration/options/watch.spec.js
index f5cd382d..259a9416 100644
--- a/test/integration/options/watch.spec.js
+++ b/test/integration/options/watch.spec.js
@@ -7,24 +7,24 @@ const helpers = require('../helpers');
describe('--watch', function() {
describe('when enabled', function() {
- this.timeout(10 * 1000);
- this.slow(3000);
+ let tempDir;
+ this.slow(5000);
beforeEach(function() {
- this.tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mocha-'));
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mocha-'));
});
afterEach(function() {
- if (this.tempDir) {
- return fs.remove(this.tempDir);
+ if (tempDir) {
+ return fs.remove(tempDir);
}
});
it('reruns test when watched test file is touched', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- return runMochaWatch([testFile], this.tempDir, () => {
+ return runMochaWatch([testFile], tempDir, () => {
touchFile(testFile);
}).then(results => {
expect(results, 'to have length', 2);
@@ -32,15 +32,15 @@ describe('--watch', function() {
});
it('reruns test when file matching --watch-files changes', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- const watchedFile = path.join(this.tempDir, 'dir/file.xyz');
+ const watchedFile = path.join(tempDir, 'dir/file.xyz');
touchFile(watchedFile);
return runMochaWatch(
[testFile, '--watch-files', 'dir/*.xyz'],
- this.tempDir,
+ tempDir,
() => {
touchFile(watchedFile);
}
@@ -50,13 +50,13 @@ describe('--watch', function() {
});
it('reruns test when file matching --watch-files is added', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- const watchedFile = path.join(this.tempDir, 'lib/file.xyz');
+ const watchedFile = path.join(tempDir, 'lib/file.xyz');
return runMochaWatch(
[testFile, '--watch-files', '**/*.xyz'],
- this.tempDir,
+ tempDir,
() => {
touchFile(watchedFile);
}
@@ -66,15 +66,15 @@ describe('--watch', function() {
});
it('reruns test when file matching --watch-files is removed', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- const watchedFile = path.join(this.tempDir, 'lib/file.xyz');
+ const watchedFile = path.join(tempDir, 'lib/file.xyz');
touchFile(watchedFile);
return runMochaWatch(
[testFile, '--watch-files', 'lib/**/*.xyz'],
- this.tempDir,
+ tempDir,
() => {
fs.removeSync(watchedFile);
}
@@ -84,15 +84,15 @@ describe('--watch', function() {
});
it('does not rerun test when file not matching --watch-files is changed', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- const watchedFile = path.join(this.tempDir, 'dir/file.js');
+ const watchedFile = path.join(tempDir, 'dir/file.js');
touchFile(watchedFile);
return runMochaWatch(
[testFile, '--watch-files', 'dir/*.xyz'],
- this.tempDir,
+ tempDir,
() => {
touchFile(watchedFile);
}
@@ -102,14 +102,14 @@ describe('--watch', function() {
});
it('picks up new test files when they are added', function() {
- const testFile = path.join(this.tempDir, 'test/a.js');
+ const testFile = path.join(tempDir, 'test/a.js');
copyFixture('__default__', testFile);
return runMochaWatch(
['test/**/*.js', '--watch-files', 'test/**/*.js'],
- this.tempDir,
+ tempDir,
() => {
- const addedTestFile = path.join(this.tempDir, 'test/b.js');
+ const addedTestFile = path.join(tempDir, 'test/b.js');
copyFixture('passing', addedTestFile);
}
).then(results => {
@@ -120,28 +120,24 @@ describe('--watch', function() {
});
it('reruns test when file matching --extension is changed', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- const watchedFile = path.join(this.tempDir, 'file.xyz');
+ const watchedFile = path.join(tempDir, 'file.xyz');
touchFile(watchedFile);
- return runMochaWatch(
- [testFile, '--extension', 'xyz,js'],
- this.tempDir,
- () => {
- touchFile(watchedFile);
- }
- ).then(results => {
+ return runMochaWatch([testFile, '--extension', 'xyz,js'], tempDir, () => {
+ touchFile(watchedFile);
+ }).then(results => {
expect(results, 'to have length', 2);
});
});
it('reruns when "rs\\n" typed', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- return runMochaWatch([testFile], this.tempDir, mochaProcess => {
+ return runMochaWatch([testFile], tempDir, mochaProcess => {
mochaProcess.stdin.write('rs\n');
}).then(results => {
expect(results, 'to have length', 2);
@@ -149,54 +145,42 @@ describe('--watch', function() {
});
it('reruns test when file starting with . and matching --extension is changed', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- const watchedFile = path.join(this.tempDir, '.file.xyz');
+ const watchedFile = path.join(tempDir, '.file.xyz');
touchFile(watchedFile);
- return runMochaWatch(
- [testFile, '--extension', 'xyz,js'],
- this.tempDir,
- () => {
- touchFile(watchedFile);
- }
- ).then(results => {
+ return runMochaWatch([testFile, '--extension', 'xyz,js'], tempDir, () => {
+ touchFile(watchedFile);
+ }).then(results => {
expect(results, 'to have length', 2);
});
});
it('ignores files in "node_modules" and ".git" by default', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- const nodeModulesFile = path.join(
- this.tempDir,
- 'node_modules',
- 'file.xyz'
- );
- const gitFile = path.join(this.tempDir, '.git', 'file.xyz');
+ const nodeModulesFile = path.join(tempDir, 'node_modules', 'file.xyz');
+ const gitFile = path.join(tempDir, '.git', 'file.xyz');
touchFile(gitFile);
touchFile(nodeModulesFile);
- return runMochaWatch(
- [testFile, '--extension', 'xyz,js'],
- this.tempDir,
- () => {
- touchFile(gitFile);
- touchFile(nodeModulesFile);
- }
- ).then(results => {
+ return runMochaWatch([testFile, '--extension', 'xyz,js'], tempDir, () => {
+ touchFile(gitFile);
+ touchFile(nodeModulesFile);
+ }).then(results => {
expect(results, 'to have length', 1);
});
});
it('ignores files matching --watch-ignore', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('__default__', testFile);
- const watchedFile = path.join(this.tempDir, 'dir/file-to-ignore.xyz');
+ const watchedFile = path.join(tempDir, 'dir/file-to-ignore.xyz');
touchFile(watchedFile);
return runMochaWatch(
@@ -207,7 +191,7 @@ describe('--watch', function() {
'--watch-ignore',
'dir/*ignore*'
],
- this.tempDir,
+ tempDir,
() => {
touchFile(watchedFile);
}
@@ -217,12 +201,12 @@ describe('--watch', function() {
});
it('reloads test files when they change', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('options/watch/test-file-change', testFile);
return runMochaWatch(
[testFile, '--watch-files', '**/*.js'],
- this.tempDir,
+ tempDir,
() => {
replaceFileContents(
testFile,
@@ -240,15 +224,15 @@ describe('--watch', function() {
});
it('reloads test dependencies when they change', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('options/watch/test-with-dependency', testFile);
- const dependency = path.join(this.tempDir, 'lib', 'dependency.js');
+ const dependency = path.join(tempDir, 'lib', 'dependency.js');
copyFixture('options/watch/dependency', dependency);
return runMochaWatch(
[testFile, '--watch-files', 'lib/**/*.js'],
- this.tempDir,
+ tempDir,
() => {
replaceFileContents(
dependency,
@@ -267,10 +251,10 @@ describe('--watch', function() {
// Regression test for https://github.com/mochajs/mocha/issues/2027
it('respects --fgrep on re-runs', function() {
- const testFile = path.join(this.tempDir, 'test.js');
+ const testFile = path.join(tempDir, 'test.js');
copyFixture('options/grep', testFile);
- return runMochaWatch([testFile, '--fgrep', 'match'], this.tempDir, () => {
+ return runMochaWatch([testFile, '--fgrep', 'match'], tempDir, () => {
touchFile(testFile);
}).then(results => {
expect(results, 'to have length', 2);
@@ -293,12 +277,12 @@ describe('--watch', function() {
function runMochaWatch(args, cwd, change) {
const [mochaProcess, resultPromise] = helpers.invokeMochaAsync(
[...args, '--watch', '--reporter', 'json'],
- {cwd, stdio: 'pipe'}
+ {cwd, stdio: ['pipe', 'pipe', 'inherit']}
);
- return sleep(1000)
+ return sleep(2000)
.then(() => change(mochaProcess))
- .then(() => sleep(1000))
+ .then(() => sleep(2000))
.then(() => {
mochaProcess.kill('SIGINT');
return resultPromise;
diff --git a/test/node-unit/cli/config.spec.js b/test/node-unit/cli/config.spec.js
index 2823cdcd..2d49423b 100644
--- a/test/node-unit/cli/config.spec.js
+++ b/test/node-unit/cli/config.spec.js
@@ -1,12 +1,11 @@
'use strict';
-const {loadConfig, parsers, CONFIG_FILES} = require('../../../lib/cli/config');
const {createSandbox} = require('sinon');
const rewiremock = require('rewiremock/node');
describe('cli/config', function() {
let sandbox;
- const config = {ok: true};
+ const phonyConfigObject = {ok: true};
beforeEach(function() {
sandbox = createSandbox();
@@ -17,11 +16,22 @@ describe('cli/config', function() {
});
describe('loadConfig()', function() {
+ let parsers;
+ let loadConfig;
+
+ beforeEach(function() {
+ const config = rewiremock.proxy(
+ require.resolve('../../../lib/cli/config')
+ );
+ parsers = config.parsers;
+ loadConfig = config.loadConfig;
+ });
+
describe('when parsing succeeds', function() {
beforeEach(function() {
- sandbox.stub(parsers, 'yaml').returns(config);
- sandbox.stub(parsers, 'json').returns(config);
- sandbox.stub(parsers, 'js').returns(config);
+ sandbox.stub(parsers, 'yaml').returns(phonyConfigObject);
+ sandbox.stub(parsers, 'json').returns(phonyConfigObject);
+ sandbox.stub(parsers, 'js').returns(phonyConfigObject);
});
describe('when supplied a filepath with ".yaml" extension', function() {
@@ -30,8 +40,8 @@ describe('cli/config', function() {
it('should use the YAML parser', function() {
loadConfig(filepath);
expect(parsers.yaml, 'to have calls satisfying', [
- {args: [filepath], returned: config}
- ]).and('was called times', 1);
+ {args: [filepath], returned: phonyConfigObject}
+ ]).and('was called once');
});
});
@@ -41,8 +51,8 @@ describe('cli/config', function() {
it('should use the YAML parser', function() {
loadConfig(filepath);
expect(parsers.yaml, 'to have calls satisfying', [
- {args: [filepath], returned: config}
- ]).and('was called times', 1);
+ {args: [filepath], returned: phonyConfigObject}
+ ]).and('was called once');
});
});
@@ -52,8 +62,19 @@ describe('cli/config', function() {
it('should use the JS parser', function() {
loadConfig(filepath);
expect(parsers.js, 'to have calls satisfying', [
- {args: [filepath], returned: config}
- ]).and('was called times', 1);
+ {args: [filepath], returned: phonyConfigObject}
+ ]).and('was called once');
+ });
+ });
+
+ describe('when supplied a filepath with ".cjs" extension', function() {
+ const filepath = 'foo.cjs';
+
+ it('should use the JS parser', function() {
+ loadConfig(filepath);
+ expect(parsers.js, 'to have calls satisfying', [
+ {args: [filepath], returned: phonyConfigObject}
+ ]).and('was called once');
});
});
@@ -63,8 +84,8 @@ describe('cli/config', function() {
it('should use the JSON parser', function() {
loadConfig('foo.jsonc');
expect(parsers.json, 'to have calls satisfying', [
- {args: [filepath], returned: config}
- ]).and('was called times', 1);
+ {args: [filepath], returned: phonyConfigObject}
+ ]).and('was called once');
});
});
@@ -74,15 +95,15 @@ describe('cli/config', function() {
it('should use the JSON parser', function() {
loadConfig('foo.json');
expect(parsers.json, 'to have calls satisfying', [
- {args: [filepath], returned: config}
- ]).and('was called times', 1);
+ {args: [filepath], returned: phonyConfigObject}
+ ]).and('was called once');
});
});
});
describe('when supplied a filepath with unsupported extension', function() {
beforeEach(function() {
- sandbox.stub(parsers, 'json').returns(config);
+ sandbox.stub(parsers, 'json').returns(phonyConfigObject);
});
it('should use the JSON parser', function() {
@@ -105,20 +126,18 @@ describe('cli/config', function() {
describe('findConfig()', function() {
let findup;
let findConfig;
+ let CONFIG_FILES;
beforeEach(function() {
findup = {sync: sandbox.stub().returns('/some/path/.mocharc.js')};
- rewiremock.enable();
- findConfig = rewiremock.proxy(
+ const config = rewiremock.proxy(
require.resolve('../../../lib/cli/config'),
r => ({
'find-up': r.by(() => findup)
})
- ).findConfig;
- });
-
- afterEach(function() {
- rewiremock.disable();
+ );
+ findConfig = config.findConfig;
+ CONFIG_FILES = config.CONFIG_FILES;
});
it('should look for one of the config files using findup-sync', function() {
diff --git a/test/node-unit/cli/options.spec.js b/test/node-unit/cli/options.spec.js
index d60de8e2..085ba5fc 100644
--- a/test/node-unit/cli/options.spec.js
+++ b/test/node-unit/cli/options.spec.js
@@ -40,12 +40,10 @@ describe('options', function() {
beforeEach(function() {
sandbox = createSandbox();
- rewiremock.enable();
});
afterEach(function() {
sandbox.restore();
- rewiremock.disable();
});
/**
@@ -58,7 +56,7 @@ describe('options', function() {
describe('loadOptions()', function() {
describe('when no parameter provided', function() {
beforeEach(function() {
- this.timeout(500);
+ this.timeout(1000);
readFileSync = sandbox.stub();
readFileSync.onFirstCall().returns('{}');
findConfig = sandbox.stub().returns('/some/.mocharc.json');
diff --git a/test/node-unit/fixtures/dumb-module.js b/test/node-unit/fixtures/dumb-module.js
new file mode 100644
index 00000000..e69de29b
diff --git a/test/node-unit/fixtures/dumber-module.js b/test/node-unit/fixtures/dumber-module.js
new file mode 100644
index 00000000..e69de29b
diff --git a/test/node-unit/mocha.spec.js b/test/node-unit/mocha.spec.js
index 314a0120..54f8afbc 100644
--- a/test/node-unit/mocha.spec.js
+++ b/test/node-unit/mocha.spec.js
@@ -1,72 +1,82 @@
'use strict';
-const path = require('path');
const Mocha = require('../../lib/mocha');
const utils = require('../../lib/utils');
+const {createSandbox} = require('sinon');
describe('Mocha', function() {
const opts = {reporter: utils.noop}; // no output
- const testFiles = [
- __filename,
- path.join(__dirname, 'cli', 'config.spec.js'),
- path.join(__dirname, 'cli', 'run.spec.js')
- ];
- const resolvedTestFiles = testFiles.map(require.resolve);
+ const dumbFilepath = require.resolve('./fixtures/dumb-module');
+ const dumberFilepath = require.resolve('./fixtures/dumber-module');
- describe('#addFile', function() {
- it('should add the given file to the files array', function() {
- const mocha = new Mocha(opts);
- mocha.addFile(__filename);
- expect(mocha.files, 'to have length', 1).and('to contain', __filename);
- });
+ let mocha;
+ let sandbox;
- it('should be chainable', function() {
- const mocha = new Mocha(opts);
- expect(mocha.addFile(__filename), 'to be', mocha);
- });
+ beforeEach(function() {
+ sandbox = createSandbox();
+ mocha = new Mocha(opts);
+ delete require.cache[dumbFilepath];
+ delete require.cache[dumberFilepath];
});
- describe('#loadFiles', function() {
- it('should load all files from the files array', function() {
- const mocha = new Mocha(opts);
+ afterEach(function() {
+ delete require.cache[dumbFilepath];
+ delete require.cache[dumberFilepath];
+ sandbox.restore();
+ });
- testFiles.forEach(mocha.addFile, mocha);
- mocha.loadFiles();
- expect(require.cache, 'to have keys', resolvedTestFiles);
- });
+ describe('instance method', function() {
+ describe('addFile()', function() {
+ it('should add the given file to the files array', function() {
+ mocha.addFile('some-file.js');
+ expect(mocha.files, 'to exhaustively satisfy', ['some-file.js']);
+ });
- it('should execute the optional callback if given', function() {
- const mocha = new Mocha(opts);
- expect(cb => {
- mocha.loadFiles(cb);
- }, 'to call the callback');
+ it('should be chainable', function() {
+ expect(mocha.addFile('some-file.js'), 'to be', mocha);
+ });
});
- });
- describe('.unloadFile', function() {
- it('should unload a specific file from cache', function() {
- const resolvedFilePath = require.resolve(__filename);
- require(__filename);
- expect(require.cache, 'to have key', resolvedFilePath);
+ describe('loadFiles()', function() {
+ it('should load all files from the files array', function() {
+ this.timeout(1000);
+ mocha.files = [dumbFilepath, dumberFilepath];
+ mocha.loadFiles();
+ expect(require.cache, 'to have keys', [dumbFilepath, dumberFilepath]);
+ });
- Mocha.unloadFile(__filename);
- expect(require.cache, 'not to have key', resolvedFilePath);
+ it('should execute the optional callback if given', function() {
+ expect(cb => {
+ mocha.loadFiles(cb);
+ }, 'to call the callback');
+ });
});
- });
- describe('#unloadFiles', function() {
- it('should unload all test files from cache', function() {
- const mocha = new Mocha(opts);
+ describe('unloadFiles()', function() {
+ it('should delegate Mocha.unloadFile() for each item in its list of files', function() {
+ mocha.files = [dumbFilepath, dumberFilepath];
+ sandbox.stub(Mocha, 'unloadFile');
+ mocha.unloadFiles();
+ expect(Mocha.unloadFile, 'to have a call exhaustively satisfying', [
+ dumbFilepath
+ ])
+ .and('to have a call exhaustively satisfying', [dumberFilepath])
+ .and('was called twice');
+ });
- testFiles.forEach(mocha.addFile, mocha);
- mocha.loadFiles();
- mocha.unloadFiles();
- expect(require.cache, 'not to have keys', resolvedTestFiles);
+ it('should be chainable', function() {
+ expect(mocha.unloadFiles(), 'to be', mocha);
+ });
});
+ });
- it('should be chainable', function() {
- const mocha = new Mocha(opts);
- expect(mocha.unloadFiles(), 'to be', mocha);
+ describe('static method', function() {
+ describe('unloadFile()', function() {
+ it('should unload a specific file from cache', function() {
+ require(dumbFilepath);
+ Mocha.unloadFile(dumbFilepath);
+ expect(require.cache, 'not to have key', dumbFilepath);
+ });
});
});
});
diff --git a/test/unit/hook-timeout.spec.js b/test/unit/hook-timeout.spec.js
index df360551..8c1b1f47 100644
--- a/test/unit/hook-timeout.spec.js
+++ b/test/unit/hook-timeout.spec.js
@@ -1,8 +1,7 @@
'use strict';
before(function(done) {
- this.timeout(100);
- setTimeout(done, 50);
+ setTimeout(done, 100);
});
it('should work', function(done) {
diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.js
index 692559f1..c48e2d0e 100644
--- a/test/unit/runner.spec.js
+++ b/test/unit/runner.spec.js
@@ -416,10 +416,14 @@ describe('Runner', function() {
hook.parent = suite;
var err = new Error('error');
suite.bail(false);
- runner.on(EVENT_RUN_END, function() {
- throw new Error('"end" was emit, but the bail is false');
- });
- runner.failHook(hook, err);
+ expect(
+ function() {
+ runner.failHook(hook, err);
+ },
+ 'not to emit from',
+ hook,
+ EVENT_RUN_END
+ );
done();
});
});
diff --git a/test/unit/throw.spec.js b/test/unit/throw.spec.js
index 2dc3c8a7..1e02a3a0 100644
--- a/test/unit/throw.spec.js
+++ b/test/unit/throw.spec.js
@@ -25,6 +25,7 @@ describe('a test that throws', function() {
});
afterEach(function() {
+ process.removeAllListeners('uncaughtException');
uncaughtHandlers.forEach(function(listener) {
process.on('uncaughtException', listener);
});
diff --git a/test/unit/timeout.spec.js b/test/unit/timeout.spec.js
index ce95edcb..e96f4b5d 100644
--- a/test/unit/timeout.spec.js
+++ b/test/unit/timeout.spec.js
@@ -14,7 +14,7 @@ describe('timeouts', function() {
});
it('should allow overriding per-test', function(done) {
- this.timeout(200);
+ this.timeout(1500);
setTimeout(function() {
done();
}, 50);