mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 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:
parent
2e748a87c2
commit
3e69dd6158
40
types/mocha/index.d.ts
vendored
40
types/mocha/index.d.ts
vendored
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user