From 6a47776178826323efd0d3278f8cddd3746544ed Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Thu, 11 Mar 2021 23:13:11 -0800 Subject: [PATCH] Fix: make it().timeout() work again (#4599) --- lib/mocha.js | 37 ++++++++++++------- .../fixtures/common-js-require.fixture.js | 4 +- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/mocha.js b/lib/mocha.js index c1bd896b70..fac1697c11 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -98,37 +98,46 @@ exports.Test = require('./test'); let currentContext; exports.afterEach = function(...args) { - (currentContext.afterEach || currentContext.teardown).apply(this, args); + return (currentContext.afterEach || currentContext.teardown).apply( + this, + args + ); }; exports.after = function(...args) { - (currentContext.after || currentContext.suiteTeardown).apply(this, args); + return (currentContext.after || currentContext.suiteTeardown).apply( + this, + args + ); }; exports.beforeEach = function(...args) { - (currentContext.beforeEach || currentContext.setup).apply(this, args); + return (currentContext.beforeEach || currentContext.setup).apply(this, args); }; exports.before = function(...args) { - (currentContext.before || currentContext.suiteSetup).apply(this, args); + return (currentContext.before || currentContext.suiteSetup).apply(this, args); }; exports.describe = function(...args) { - (currentContext.describe || currentContext.suite).apply(this, args); + return (currentContext.describe || currentContext.suite).apply(this, args); }; exports.describe.only = function(...args) { - (currentContext.describe || currentContext.suite).only.apply(this, args); + return (currentContext.describe || currentContext.suite).only.apply( + this, + args + ); }; exports.describe.skip = function(...args) { - (currentContext.describe || currentContext.suite).skip.apply(this, args); + return (currentContext.describe || currentContext.suite).skip.apply( + this, + args + ); }; exports.it = function(...args) { - (currentContext.it || currentContext.test).apply(this, args); + return (currentContext.it || currentContext.test).apply(this, args); }; exports.it.only = function(...args) { - (currentContext.it || currentContext.test).only.apply(this, args); + return (currentContext.it || currentContext.test).only.apply(this, args); }; exports.it.skip = function(...args) { - ( - currentContext.xit || - (currentContext.test && currentContext.test.skip) - ).apply(this, args); + return (currentContext.it || currentContext.test).skip.apply(this, args); }; exports.xdescribe = exports.describe.skip; exports.xit = exports.it.skip; @@ -139,7 +148,7 @@ exports.suite = exports.describe; exports.teardown = exports.afterEach; exports.test = exports.it; exports.run = function(...args) { - currentContext.run.apply(this, args); + return currentContext.run.apply(this, args); }; /** diff --git a/test/integration/fixtures/common-js-require.fixture.js b/test/integration/fixtures/common-js-require.fixture.js index 0573f6f0f9..17a0e62f61 100644 --- a/test/integration/fixtures/common-js-require.fixture.js +++ b/test/integration/fixtures/common-js-require.fixture.js @@ -44,13 +44,13 @@ suite('root suite', () => { describe.only('describe only', () => { it('it', () => { console.log('running it'); - }); + }).timeout(1000); xit('it', () => { console.log('running xit'); }); it.only('it.only', () => { console.log('running it.only'); - }); + }).retries(2); it.skip('it.skip', () => { console.log('running it.skip'); });