test: extract defer helper (#24019)
This commit is contained in:
parent
c66282a460
commit
7c7ea141f0
2 changed files with 15 additions and 5 deletions
|
@ -60,6 +60,20 @@ app.whenReady().then(async () => {
|
||||||
}
|
}
|
||||||
const mocha = new Mocha(mochaOptions);
|
const mocha = new Mocha(mochaOptions);
|
||||||
|
|
||||||
|
// The cleanup method is registered this way rather than through an
|
||||||
|
// `afterEach` at the top level so that it can run before other `afterEach`
|
||||||
|
// methods.
|
||||||
|
//
|
||||||
|
// The order of events is:
|
||||||
|
// 1. test completes,
|
||||||
|
// 2. `defer()`-ed methods run, in reverse order,
|
||||||
|
// 3. regular `afterEach` hooks run.
|
||||||
|
const { runCleanupFunctions } = require('./spec-helpers');
|
||||||
|
mocha.suite.on('suite', function attach (suite) {
|
||||||
|
suite.afterEach('cleanup', runCleanupFunctions);
|
||||||
|
suite.on('suite', attach);
|
||||||
|
});
|
||||||
|
|
||||||
if (!process.env.MOCHA_REPORTER) {
|
if (!process.env.MOCHA_REPORTER) {
|
||||||
mocha.ui('bdd').reporter('tap');
|
mocha.ui('bdd').reporter('tap');
|
||||||
}
|
}
|
||||||
|
@ -110,8 +124,4 @@ app.whenReady().then(async () => {
|
||||||
chai.use(require('dirty-chai'));
|
chai.use(require('dirty-chai'));
|
||||||
|
|
||||||
const runner = mocha.run(cb);
|
const runner = mocha.run(cb);
|
||||||
const { runCleanupFunctions } = require('./spec-helpers');
|
|
||||||
runner.on('test end', () => {
|
|
||||||
runCleanupFunctions();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,7 +19,7 @@ export async function runCleanupFunctions () {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function defer (f: CleanupFunction) {
|
export function defer (f: CleanupFunction) {
|
||||||
cleanupFunctions.push(f);
|
cleanupFunctions.unshift(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
class RemoteControlApp {
|
class RemoteControlApp {
|
||||||
|
|
Loading…
Reference in a new issue