eslint-plugin-ui-testing
Version:
ESLint rules for UI testing tools WebdriverIO, Cypress, TestCafe, Playwright, Puppeteer
46 lines (45 loc) • 1.74 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 absolute url',
recommended: 'warn',
},
messages: {
noAutomationToolSet: 'Please set the appropriate automation tool used, choose one from: cypress, webdriverio',
noAbsoluteUrl: 'Avoid absolute url, use a base url in the project config',
},
schema: [
{
type: 'string',
default: '',
additionalProperties: false,
},
],
type: 'suggestion',
},
defaultOptions: [null],
create: function (context, _a) {
var automationApi = _a[0];
if (!automationApi) {
context.report({ loc: data_1.LOC_SOF, messageId: 'noAutomationToolSet' });
}
var openUrlCommands = (0, utils_1.getOpenUrlCommands)(automationApi);
return {
'CallExpression[callee.object.name][callee.property.name]': function rule(node) {
var absoluteUrlPattern = new RegExp('^(?:[a-z]+:)?//');
var value = ("" + (0, utils_1.getArgumentValue)(node)).toLowerCase();
if ((0, utils_1.isObjectPropertyNameInCommands)(node, openUrlCommands)
&& absoluteUrlPattern.test(value)) {
context.report({ node: node, messageId: 'noAbsoluteUrl' });
}
},
};
},
});