UNPKG

eslint-plugin-ui-testing

Version:

ESLint rules for UI testing tools WebdriverIO, Cypress, TestCafe, Playwright, Puppeteer

45 lines (44 loc) 1.55 kB
"use strict"; 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 hard wait', recommended: 'error', }, messages: { noAutomationToolSet: data_1.NO_AUTOMATION_TOOL_SET_MESSAGE, noHardWait: 'Avoid hard wait', }, schema: [ { type: 'string', default: '', additionalProperties: false, }, ], type: 'problem', }, defaultOptions: [null], create: function (context, _a) { var automationApi = _a[0]; if (!automationApi) { context.report({ loc: data_1.LOC_SOF, messageId: 'noAutomationToolSet' }); } var digitPattern = new RegExp('\\d+'); var hardWaitCommands = (0, utils_1.getHardWaitCommands)(automationApi); return { 'CallExpression[callee.object.name][callee.property.name]': function rule(node) { if ((0, utils_1.isObjectPropertyNameInCommands)(node, hardWaitCommands) && digitPattern.test((0, utils_1.getArgumentValue)(node))) { context.report({ node: node, messageId: 'noHardWait' }); } }, }; }, });