Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: correct Mocha overloads order #59075

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
153 changes: 16 additions & 137 deletions types/mocha/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,29 +400,14 @@ declare namespace Mocha {
*
* - _Only available when invoked via the mocha CLI._
*/
(fn: Func): void;

/**
* [bdd, qunit, tdd] Describe a "hook" to execute the given callback `fn`. The name of the
* function is used as the name of the hook.
*
* - _Only available when invoked via the mocha CLI._
*/
(fn: AsyncFunc): void;
(fn: Func | AsyncFunc): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we would use a rest parameter with a discriminated union type instead of function overrides as a workaround?

For example:

type HookFunction = (...args: [Func|AsyncFunc] | [string, (Func|AsyncFunc)?]) => void;


/**
* [bdd, qunit, tdd] Describe a "hook" to execute the given `title` and callback `fn`.
*
* - _Only available when invoked via the mocha CLI._
*/
(name: string, fn?: Func): void;

/**
* [bdd, qunit, tdd] Describe a "hook" to execute the given `title` and callback `fn`.
*
* - _Only available when invoked via the mocha CLI._
*/
(name: string, fn?: AsyncFunc): void;
(name: string, fn?: Func | AsyncFunc): void;
}

interface SuiteFunction {
Expand Down Expand Up @@ -494,31 +479,15 @@ declare namespace Mocha {
*
* - _Only available when invoked via the mocha CLI._
*/
(fn: Func): Test;

/**
* Describe a specification or test-case with the given callback `fn` acting as a thunk.
* The name of the function is used as the name of the test.
*
* - _Only available when invoked via the mocha CLI._
*/
(fn: AsyncFunc): Test;

/**
* Describe a specification or test-case with the given `title` and callback `fn` acting
* as a thunk.
*
* - _Only available when invoked via the mocha CLI._
*/
(title: string, fn?: Func): Test;
(fn: Func | AsyncFunc): Test;

/**
* Describe a specification or test-case with the given `title` and callback `fn` acting
* as a thunk.
*
* - _Only available when invoked via the mocha CLI._
*/
(title: string, fn?: AsyncFunc): Test;
(title: string, fn?: Func | AsyncFunc): Test;

/**
* Indicates this test should be executed exclusively.
Expand Down Expand Up @@ -550,32 +519,15 @@ declare namespace Mocha {
*
* - _Only available when invoked via the mocha CLI._
*/
(fn: Func): Test;

/**
* [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
* acting as a thunk. The name of the function is used as the name of the test. Indicates
* this test should be executed exclusively.
*
* - _Only available when invoked via the mocha CLI._
*/
(fn: AsyncFunc): Test;

/**
* [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
* callback `fn` acting as a thunk. Indicates this test should be executed exclusively.
*
* - _Only available when invoked via the mocha CLI._
*/
(title: string, fn?: Func): Test;
(fn: Func | AsyncFunc): Test;

/**
* [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
* callback `fn` acting as a thunk. Indicates this test should be executed exclusively.
*
* - _Only available when invoked via the mocha CLI._
*/
(title: string, fn?: AsyncFunc): Test;
(title: string, fn?: Func | AsyncFunc): Test;
}

interface PendingTestFunction {
Expand All @@ -586,32 +538,15 @@ declare namespace Mocha {
*
* - _Only available when invoked via the mocha CLI._
*/
(fn: Func): Test;

/**
* [bdd, tdd, qunit] Describe a specification or test-case with the given callback `fn`
* acting as a thunk. The name of the function is used as the name of the test. Indicates
* this test should not be executed.
*
* - _Only available when invoked via the mocha CLI._
*/
(fn: AsyncFunc): Test;
(fn: Func | AsyncFunc): Test;

/**
* [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
* callback `fn` acting as a thunk. Indicates this test should not be executed.
*
* - _Only available when invoked via the mocha CLI._
*/
(title: string, fn?: Func): Test;

/**
* [bdd, tdd, qunit] Describe a specification or test-case with the given `title` and
* callback `fn` acting as a thunk. Indicates this test should not be executed.
*
* - _Only available when invoked via the mocha CLI._
*/
(title: string, fn?: AsyncFunc): Test;
(title: string, fn?: Func | AsyncFunc): Test;
}

/**
Expand Down Expand Up @@ -1875,112 +1810,56 @@ declare namespace Mocha {
*
* @see https://mochajs.org/api/Mocha.Suite.html#beforeAll
*/
beforeAll(fn?: Func): this;

/**
* Run `fn(test[, done])` before running tests.
*
* @see https://mochajs.org/api/Mocha.Suite.html#beforeAll
*/
beforeAll(fn?: AsyncFunc): this;

/**
* Run `fn(test[, done])` before running tests.
*
* @see https://mochajs.org/api/Mocha.Suite.html#beforeAll
*/
beforeAll(title: string, fn?: Func): this;
beforeAll(fn?: Func | AsyncFunc): this;

/**
* Run `fn(test[, done])` before running tests.
*
* @see https://mochajs.org/api/Mocha.Suite.html#beforeAll
*/
beforeAll(title: string, fn?: AsyncFunc): this;

/**
* Run `fn(test[, done])` after running tests.
*
* @see https://mochajs.org/api/Mocha.Suite.html#afterAll
*/
afterAll(fn?: Func): this;

/**
* Run `fn(test[, done])` after running tests.
*
* @see https://mochajs.org/api/Mocha.Suite.html#afterAll
*/
afterAll(fn?: AsyncFunc): this;
beforeAll(title: string, fn?: Func | AsyncFunc): this;

/**
* Run `fn(test[, done])` after running tests.
*
* @see https://mochajs.org/api/Mocha.Suite.html#afterAll
*/
afterAll(title: string, fn?: Func): this;
afterAll(fn?: Func | AsyncFunc): this;

/**
* Run `fn(test[, done])` after running tests.
*
* @see https://mochajs.org/api/Mocha.Suite.html#afterAll
*/
afterAll(title: string, fn?: AsyncFunc): this;

/**
* Run `fn(test[, done])` before each test case.
*
* @see https://mochajs.org/api/Mocha.Suite.html#beforeEach
*/
beforeEach(fn?: Func): this;

/**
* Run `fn(test[, done])` before each test case.
*
* @see https://mochajs.org/api/Mocha.Suite.html#beforeEach
*/
beforeEach(fn?: AsyncFunc): this;
afterAll(title: string, fn?: Func | AsyncFunc): this;

/**
* Run `fn(test[, done])` before each test case.
*
* @see https://mochajs.org/api/Mocha.Suite.html#beforeEach
*/
beforeEach(title: string, fn?: Func): this;
beforeEach(fn?: Func | AsyncFunc): this;

/**
* Run `fn(test[, done])` before each test case.
*
* @see https://mochajs.org/api/Mocha.Suite.html#beforeEach
*/
beforeEach(title: string, fn?: AsyncFunc): this;

/**
* Run `fn(test[, done])` after each test case.
*
* @see https://mochajs.org/api/Mocha.Suite.html#afterEach
*/
afterEach(fn?: Func): this;

/**
* Run `fn(test[, done])` after each test case.
*
* @see https://mochajs.org/api/Mocha.Suite.html#afterEach
*/
afterEach(fn?: AsyncFunc): this;
beforeEach(title: string, fn?: Func | AsyncFunc): this;

/**
* Run `fn(test[, done])` after each test case.
*
* @see https://mochajs.org/api/Mocha.Suite.html#afterEach
*/
afterEach(title: string, fn?: Func): this;
afterEach(fn?: Func | AsyncFunc): this;

/**
* Run `fn(test[, done])` after each test case.
*
* @see https://mochajs.org/api/Mocha.Suite.html#afterEach
*/
afterEach(title: string, fn?: AsyncFunc): this;
afterEach(title: string, fn?: Func | AsyncFunc): this;

/**
* Add a test `suite`.
Expand Down