Skip to content

Commit

Permalink
test actually checks rootHooks behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Apr 8, 2020
1 parent a7dc33c commit 0d04957
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 21 deletions.
7 changes: 5 additions & 2 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,17 @@ function Mocha(options) {
'fullTrace',
'growl',
'inlineDiffs',
'invert',
'rootHooks'
'invert'
].forEach(function(opt) {
if (options[opt]) {
this[opt]();
}
}, this);

if (options.rootHooks) {
this.rootHooks(options.rootHooks);
}

if (options.parallel) {
this._runner = require('./buffered-runner');
this.lazyLoadFiles = true;
Expand Down
8 changes: 5 additions & 3 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ let bootstrap = argv => {
/* istanbul ignore next */
debug('exiting');
});
debug('bootstrapped');
bootstrap = () => {};
};

Expand Down Expand Up @@ -67,7 +66,7 @@ async function run(filepath, argv = {ui: 'bdd'}) {

bootstrap(opts);

opts.rootHooks = opts.rootHooks || rootHooks;
opts.rootHooks = rootHooks;

const mocha = new Mocha(opts).addFile(filepath);

Expand All @@ -86,7 +85,10 @@ async function run(filepath, argv = {ui: 'bdd'}) {
// Runner adds these; if we don't remove them, we'll get a leak.
process.removeAllListeners('uncaughtException');

debug('completed run with %d test failures', result.failures);
debug(
'completed run with %d test failures',
typeof result.failures === 'number' ? result.failures : 0
);
try {
const serialized = serialize(result);
debug('returning to main process');
Expand Down
69 changes: 53 additions & 16 deletions test/integration/options/require.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,58 @@
var invokeMochaAsync = require('../helpers').invokeMochaAsync;

describe('--require', function() {
it('should allow registration of root hooks', function() {
return expect(
invokeMochaAsync([
'--require',
require.resolve(
'../fixtures/options/require/root-hook-defs-a.fixture.js'
),
'--require',
require.resolve(
'../fixtures/options/require/root-hook-defs-b.fixture.js'
),
require.resolve('../fixtures/options/require/root-hook-test.fixture.js')
])[1],
'when fulfilled',
'to have succeeded'
);
describe('when run in serial', function() {
it('should allow registration of root hooks', function() {
return expect(
invokeMochaAsync([
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-a.fixture.js'
),
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-b.fixture.js'
),
require.resolve(
'../fixtures/options/require/root-hook-test.fixture.js'
)
])[1],
'when fulfilled',
'to contain output',
/beforeAll\nbeforeAll array 1\nbeforeAll array 2\nbeforeEach\nbeforeEach array 1\nbeforeEach array 2\n/
).and(
'when fulfilled',
'to contain output',
/afterEach\nafterEach array 1\nafterEach array 2\nafterAll\nafterAll array 1\nafterAll array 2\n/
);
});
});

describe('when run with --parallel', function() {
it('should allow registration of root hooks', function() {
return expect(
invokeMochaAsync([
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-a.fixture.js'
),
'--require=' +
require.resolve(
'../fixtures/options/require/root-hook-defs-b.fixture.js'
),
'--parallel',
require.resolve(
'../fixtures/options/require/root-hook-test.fixture.js'
)
])[1],
'when fulfilled',
'to contain output',
/beforeAll\nbeforeAll array 1\nbeforeAll array 2\nbeforeEach\nbeforeEach array 1\nbeforeEach array 2\n/
).and(
'when fulfilled',
'to contain output',
/afterEach\nafterEach array 1\nafterEach array 2\nafterAll\nafterAll array 1\nafterAll array 2\n/
);
});
});
});

0 comments on commit 0d04957

Please sign in to comment.