2020-08-26 01:57:08 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
|
|
|
exports.default = void 0;
|
|
|
|
var _utils = require("./utils");
|
|
|
|
var _default = (0, _utils.createRule)({
|
|
|
|
name: __filename,
|
|
|
|
meta: {
|
|
|
|
docs: {
|
|
|
|
category: 'Best Practices',
|
|
|
|
description: 'Disallow disabled tests',
|
|
|
|
recommended: 'warn'
|
|
|
|
},
|
|
|
|
messages: {
|
|
|
|
missingFunction: 'Test is missing function argument',
|
|
|
|
pending: 'Call to pending()',
|
|
|
|
pendingSuite: 'Call to pending() within test suite',
|
|
|
|
pendingTest: 'Call to pending() within test',
|
|
|
|
disabledSuite: 'Disabled test suite',
|
|
|
|
disabledTest: 'Disabled test'
|
|
|
|
},
|
|
|
|
schema: [],
|
|
|
|
type: 'suggestion'
|
|
|
|
},
|
|
|
|
defaultOptions: [],
|
|
|
|
create(context) {
|
|
|
|
let suiteDepth = 0;
|
|
|
|
let testDepth = 0;
|
|
|
|
return {
|
|
|
|
CallExpression(node) {
|
2022-11-10 11:43:16 +01:00
|
|
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
|
|
if (!jestFnCall) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (jestFnCall.type === 'describe') {
|
|
|
|
suiteDepth++;
|
|
|
|
}
|
|
|
|
if (jestFnCall.type === 'test') {
|
|
|
|
testDepth++;
|
|
|
|
if (node.arguments.length < 2 && jestFnCall.members.every(s => (0, _utils.getAccessorValue)(s) !== 'todo')) {
|
2020-08-26 01:57:08 +02:00
|
|
|
context.report({
|
2022-11-10 11:43:16 +01:00
|
|
|
messageId: 'missingFunction',
|
2020-08-26 01:57:08 +02:00
|
|
|
node
|
|
|
|
});
|
2022-11-10 11:43:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
// the only jest functions that are with "x" are "xdescribe", "xtest", and "xit"
|
|
|
|
jestFnCall.name.startsWith('x') || jestFnCall.members.some(s => (0, _utils.getAccessorValue)(s) === 'skip')) {
|
|
|
|
context.report({
|
|
|
|
messageId: jestFnCall.type === 'describe' ? 'disabledSuite' : 'disabledTest',
|
|
|
|
node
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'CallExpression:exit'(node) {
|
|
|
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
|
|
if (!jestFnCall) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (jestFnCall.type === 'describe') {
|
|
|
|
suiteDepth--;
|
|
|
|
}
|
|
|
|
if (jestFnCall.type === 'test') {
|
|
|
|
testDepth--;
|
2020-08-26 01:57:08 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'CallExpression[callee.name="pending"]'(node) {
|
|
|
|
if ((0, _utils.scopeHasLocalReference)(context.getScope(), 'pending')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (testDepth > 0) {
|
|
|
|
context.report({
|
|
|
|
messageId: 'pendingTest',
|
|
|
|
node
|
|
|
|
});
|
|
|
|
} else if (suiteDepth > 0) {
|
|
|
|
context.report({
|
|
|
|
messageId: 'pendingSuite',
|
|
|
|
node
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
context.report({
|
|
|
|
messageId: 'pending',
|
|
|
|
node
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
exports.default = _default;
|