🤖 Merge PR #46195 Mocha 8 - RootHook object type by @arnulfojr

* Mocha parallel and jobs options

* Remove deprecated functions

* Removed deprecated types

* Replace MochaSetupOptions for MochaOptions in browser mode

* Update deps to not use deprecated interfaces

* Added unloadFiles to mocha

* Mocha RootHook type
This commit is contained in:
Arnulfo Solis Ramirez 2020-08-11 21:04:36 +02:00 committed by GitHub
parent 2e748a87c2
commit 3e69dd6158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 1 deletions

View File

@ -228,6 +228,13 @@ declare class Mocha {
* @see https://mochajs.org/api/mocha#parallelMode
*/
parallelMode(enabled?: boolean): this;
/**
* Assigns hooks to the root suite.
*
* @see https://mochajs.org/api/mocha#rootHooks
*/
rootHooks(hooks: Mocha.RootHookObject): this;
}
declare namespace Mocha {
@ -2101,6 +2108,37 @@ declare namespace Mocha {
error(err: any): void;
}
/**
* An alternative way to define root hooks that works with parallel runs.
*
* Root hooks work with any interface, but the property names do not change.
* In other words, if you are using the tdd interface, suiteSetup maps to beforeAll, and setup maps to beforeEach.
*
* As with other hooks, `this` refers to to the current context object.
*
* @see https://mochajs.org/#root-hook-plugins
*/
interface RootHookObject {
/**
* In serial mode, run after all tests end, once only.
* In parallel mode, run after all tests end, for each file.
*/
afterAll?: Func | AsyncFunc | Func[] | AsyncFunc[];
/**
* In serial mode (Mocha's default), before all tests begin, once only.
* In parallel mode, run before all tests begin, for each file.
*/
beforeAll?: Func | AsyncFunc | Func[] | AsyncFunc[];
/**
* In both modes, run after every test.
*/
afterEach?: Func | AsyncFunc | Func[] | AsyncFunc[];
/**
* In both modes, run before each test.
*/
beforeEach?: Func | AsyncFunc | Func[] | AsyncFunc[];
}
/**
* Initialize a new `Test` with the given `title` and callback `fn`.
*
@ -2204,7 +2242,7 @@ declare namespace Mocha {
jobs?: number;
/** Assigns hooks to the root suite */
rootHooks?: any;
rootHooks?: RootHookObject;
asyncOnly?: boolean;
delay?: boolean;

View File

@ -828,6 +828,15 @@ function testParallelMode() {
mocha.parallelMode();
}
function testRootHooks() {
mocha.rootHooks({
beforeAll(done) {
done();
},
afterEach: [done => done()],
});
}
function testUnloadFiles() {
mocha.unloadFiles();
}
@ -884,6 +893,21 @@ function test_constructor_jobs_option() {
const m: Mocha = new LocalMocha({ jobs: 4 });
}
function test_constructor_root_hooks() {
const m: Mocha = new LocalMocha({
rootHooks: {
beforeEach(done) {
done();
},
afterEach(done) {
done();
},
afterAll: [done => done()],
beforeAll: [done => done()],
},
});
}
function test_constructor_all_options() {
const m: Mocha = new LocalMocha({
slow: 25,