Skip to content

Commit

Permalink
Merge 9b338f6 into 41567df
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed Sep 13, 2022
2 parents 41567df + 9b338f6 commit 24127e3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/interfaces/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,16 @@ module.exports = function (suites, context, mocha) {
throw createUnsupportedError('Pending test forbidden');
}
if (typeof opts.fn === 'function') {
opts.fn.call(suite);
const suiteResult = opts.fn.call(suite);
if (suiteResult instanceof Promise) {
errors.deprecate(
'Suite "' +
suite.fullTitle() +
'" returned a Promise. ' +
'Asynchronous suites are not supported, use a ' +
'synchronous callback instead.'
);
}
suites.shift();
} else if (typeof opts.fn === 'undefined' && !suite.pending) {
throw createMissingArgumentError(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

describe('a suite with an async callback', async function () {});
21 changes: 21 additions & 0 deletions test/integration/suite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,24 @@ describe('suite returning a value', function () {
);
});
});

describe('suite w/async callback', function () {
it('should print a helpful deprecation message when a callback for suite is async', function (done) {
run(
'suite/suite-async-callback.fixture.js',
args,
function (err, res) {
if (err) {
return done(err);
}
expect(
res.output,
'to match',
/Asynchronous suites are not supported, use a synchronous callback instead./
);
done();
},
{stdio: 'pipe'}
);
});
});

0 comments on commit 24127e3

Please sign in to comment.