eslint-plugin-ui-testing
Version:
ESLint rules for UI testing tools WebdriverIO, Cypress, TestCafe, Playwright, Puppeteer
48 lines (47 loc) • 2.18 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");
exports.RULE_NAME = __filename.slice(__dirname.length + 1, -3);
exports.default = (0, utils_1.createRule)({
name: exports.RULE_NAME,
meta: {
docs: {
description: 'Disallow browser/page commands in tests',
recommended: 'warn',
},
messages: {
noAutomationToolSet: 'Please set the appropriate automation API used, choose one from: playwright, puppeteer, webdriverio',
noBrowserCommandInTests: 'Avoid browser/page commands in tests, rather move these to page objects or an other abstraction layer',
},
schema: [
{
type: 'string',
default: '',
additionalProperties: false,
},
],
type: 'suggestion',
},
defaultOptions: [null],
create: function (context, _a) {
var _b;
var automationApi = _a[0];
if (!automationApi) {
context.report({ loc: data_1.LOC_SOF, messageId: 'noAutomationToolSet' });
}
var browserObjectNames = ((0, utils_1.getBrowserObjectNames)(automationApi)).join('|');
return _b = {},
_b["CallExpression[callee.name=" + data_1.TEST_BLOCKS_PATTERN + "] CallExpression[callee.object.name=/^" + browserObjectNames + "$/]"] = function (node) {
context.report({ node: node, messageId: 'noBrowserCommandInTests' });
},
_b["CallExpression[callee.object.name=" + data_1.TEST_BLOCKS_PATTERN + "] CallExpression[callee.object.name=/^" + browserObjectNames + "$/]"] = function (node) {
context.report({ node: node, messageId: 'noBrowserCommandInTests' });
},
_b["CallExpression[callee.object.object.name=" + data_1.TEST_BLOCKS_PATTERN + "] CallExpression[callee.object.name=/^" + browserObjectNames + "$/]"] = function (node) {
context.report({ node: node, messageId: 'noBrowserCommandInTests' });
},
_b;
},
});