Skip to content

Commit

Permalink
Fix: make it().timeout() work again (#4599)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster committed Mar 12, 2021
1 parent 1de836b commit 6a47776
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
37 changes: 23 additions & 14 deletions lib/mocha.js
Expand Up @@ -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;
Expand All @@ -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);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions test/integration/fixtures/common-js-require.fixture.js
Expand Up @@ -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');
});
Expand Down

0 comments on commit 6a47776

Please sign in to comment.