eslint-plugin-ui-testing
Version:
ESLint rules for UI testing tools WebdriverIO, Cypress, TestCafe, Playwright, Puppeteer
68 lines (67 loc) • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RULE_NAME = void 0;
var utils_1 = require("../utils/utils");
var actualCommands = [];
function report(context, node) {
if (!actualCommands.length) {
context.report({ node: node, messageId: 'missingAssertionInTest' });
}
else {
actualCommands = [];
}
}
exports.RULE_NAME = __filename.slice(__dirname.length + 1, -3);
exports.default = (0, utils_1.createRule)({
name: exports.RULE_NAME,
meta: {
docs: {
description: 'Disallow tests without assertions',
recommended: 'error',
},
messages: {
missingAssertionInTest: 'Missing assertion in test',
},
schema: [
{
type: 'object',
properties: {
assertCommands: {
type: 'array',
items: [{ type: 'string' }],
},
},
additionalProperties: false,
},
],
type: 'problem',
},
defaultOptions: [{ assertCommands: ['expect', 'expectAsync', 'assert'] }],
create: function (context, _a) {
var _b;
var _c = _a[0].assertCommands, assertCommands = _c === void 0 ? ['expect', 'expectAsync', 'assert'] : _c;
var testBlockPattern = '/(it|test)$/';
var testPropertyPattern = '/^(only|concurrent|skip)$/';
var commands = assertCommands.join('|');
return _b = {},
_b["CallExpression[callee.name=" + testBlockPattern + "] Identifier[name=/^" + commands + "$/]"] = function (node) {
actualCommands.push(node.name);
},
_b["CallExpression[callee.object.name=" + testBlockPattern + "][callee.property.name=" + testPropertyPattern + "] Identifier[name=/^" + commands + "$/]"] = function (node) {
actualCommands.push(node.name);
},
_b["CallExpression[callee.object.object.name=" + testBlockPattern + "][callee.property.name=" + testPropertyPattern + "] Identifier[name=/^" + commands + "$/]"] = function (node) {
actualCommands.push(node.name);
},
_b["CallExpression[callee.name=" + testBlockPattern + "]:exit"] = function (node) {
report(context, node);
},
_b["CallExpression[callee.object.name=" + testBlockPattern + "][callee.property.name=" + testPropertyPattern + "]:exit"] = function (node) {
report(context, node);
},
_b["CallExpression[callee.object.object.name=" + testBlockPattern + "][callee.property.name=" + testPropertyPattern + "]:exit"] = function (node) {
report(context, node);
},
_b;
},
});