Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed May 26, 2021
1 parent 19f736b commit 9a7a4db
Show file tree
Hide file tree
Showing 3 changed files with 1,082 additions and 1,012 deletions.
25 changes: 16 additions & 9 deletions lib/rules/no-synchronous-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ function isAsyncFunction(functionExpression) {

function findPromiseReturnStatement(nodes) {
return find(function (node) {
return node.type === 'ReturnStatement' && node.argument && node.argument.type !== 'Literal';
return (
node.type === 'ReturnStatement' &&
node.argument &&
node.argument.type !== 'Literal'
);
}, nodes);
}

Expand All @@ -25,14 +29,15 @@ function doesReturnPromise(functionExpression) {
let returnStatement = null;

if (bodyStatement.type === 'BlockStatement') {
returnStatement = findPromiseReturnStatement(functionExpression.body.body);
returnStatement = findPromiseReturnStatement(
functionExpression.body.body
);
} else if (bodyStatement.type !== 'Literal') {
// allow arrow statements calling a promise with implicit return.
returnStatement = bodyStatement;
}

return returnStatement !== null &&
typeof returnStatement !== 'undefined';
return returnStatement !== null && typeof returnStatement !== 'undefined';
}

module.exports = {
Expand Down Expand Up @@ -61,12 +66,16 @@ module.exports = {
create(context) {
const astUtils = createAstUtils(context.settings);
const options = context.options[0] || {};
const allowedAsyncMethods = isNil(options.allowed) ? asyncMethods : options.allowed;
const allowedAsyncMethods = isNil(options.allowed) ?
asyncMethods :
options.allowed;

function check(node) {
if (astUtils.hasParentMochaFunctionCall(node)) {
// For each allowed async test method, check if it is used in the test
const testAsyncMethods = allowedAsyncMethods.map(function (method) {
const testAsyncMethods = allowedAsyncMethods.map(function (
method
) {
switch (method) {
case 'async':
return isAsyncFunction(node);
Expand All @@ -80,9 +89,7 @@ module.exports = {
});

// Check that at least one allowed async test method is used in the test
const isAsyncTest = testAsyncMethods.some(function (value) {
return value === true;
});
const isAsyncTest = testAsyncMethods.includes(true);

if (!isAsyncTest) {
context.report(node, 'Unexpected synchronous test.');
Expand Down
Loading

0 comments on commit 9a7a4db

Please sign in to comment.