eslint-plugin-playwright
Version:
ESLint plugin for Playwright testing.
39 lines (38 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseExpectCall = void 0;
const ast_1 = require("./ast");
const MODIFIER_NAMES = new Set(['not', 'resolves', 'rejects']);
function getExpectArguments(node) {
const grandparent = node.parent.parent;
return grandparent.type === 'CallExpression' ? grandparent.arguments : [];
}
function parseExpectCall(node) {
if (!(0, ast_1.isExpectCall)(node)) {
return;
}
const members = (0, ast_1.getMatchers)(node);
const modifiers = [];
let matcher;
// Separate the matchers (e.g. toBe) from modifiers (e.g. not)
members.forEach((item) => {
if (MODIFIER_NAMES.has((0, ast_1.getStringValue)(item))) {
modifiers.push(item);
}
else {
matcher = item;
}
});
// Rules only run against full expect calls with matchers
if (!matcher) {
return;
}
return {
members,
matcher,
matcherName: (0, ast_1.getStringValue)(matcher),
modifiers,
args: getExpectArguments(matcher),
};
}
exports.parseExpectCall = parseExpectCall;