eslint-plugin-ui-testing
Version:
ESLint rules for UI testing tools WebdriverIO, Cypress, TestCafe, Playwright, Puppeteer
54 lines (53 loc) • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RULE_NAME = void 0;
var data_1 = require("../data/data");
var utils_1 = require("../utils/utils");
function report(context, node, commands) {
if ((0, utils_1.isObjectPropertyNameInCommands)(node, commands)) {
context.report({ node: node, messageId: 'noWaitInTests' });
}
}
exports.RULE_NAME = __filename.slice(__dirname.length + 1, -3);
exports.default = (0, utils_1.createRule)({
name: exports.RULE_NAME,
meta: {
docs: {
description: 'Disallow wait in tests',
recommended: 'error',
},
messages: {
noAutomationToolSet: 'Please set the appropriate automation API used, choose one from: playwright, puppeteer, webdriverio',
noWaitInTests: 'Avoid wait in tests, rather move these to page objects or an other abstraction layer',
},
schema: [
{
type: 'string',
default: '',
additionalProperties: false,
},
],
type: 'problem',
},
defaultOptions: [null],
create: function (context, _a) {
var _b;
var automationApi = _a[0];
if (!automationApi) {
context.report({ loc: data_1.LOC_SOF, messageId: 'noAutomationToolSet' });
}
var waitCommands = (0, utils_1.getWaitCommandsNotInTest)(automationApi);
var matcher = 'CallExpression[callee.object.name][callee.property.name]';
return _b = {},
_b["CallExpression[callee.name=" + data_1.TEST_BLOCKS_PATTERN + "] " + matcher] = function (node) {
report(context, node, waitCommands);
},
_b["CallExpression[callee.object.name=" + data_1.TEST_BLOCKS_PATTERN + "] " + matcher] = function (node) {
report(context, node, waitCommands);
},
_b["CallExpression[callee.object.object.name=" + data_1.TEST_BLOCKS_PATTERN + "] " + matcher] = function (node) {
report(context, node, waitCommands);
},
_b;
},
});