Skip to content

Commit

Permalink
Deprecation message when an async Suites are used
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed Sep 13, 2022
1 parent 41567df commit 5ba820b
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
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
@@ -0,0 +1,3 @@
'use strict';

describe('a suite without an async callback', async function () {});
21 changes: 21 additions & 0 deletions test/integration/suite.spec.js
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 5ba820b

Please sign in to comment.