| [9af201e] | 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = void 0;
|
|---|
| 7 |
|
|---|
| 8 | var _utils = require("./utils");
|
|---|
| 9 |
|
|---|
| 10 | const newDescribeContext = () => ({
|
|---|
| 11 | describeTitles: [],
|
|---|
| 12 | testTitles: []
|
|---|
| 13 | });
|
|---|
| 14 |
|
|---|
| 15 | var _default = (0, _utils.createRule)({
|
|---|
| 16 | name: __filename,
|
|---|
| 17 | meta: {
|
|---|
| 18 | docs: {
|
|---|
| 19 | category: 'Best Practices',
|
|---|
| 20 | description: 'Disallow identical titles',
|
|---|
| 21 | recommended: 'error'
|
|---|
| 22 | },
|
|---|
| 23 | messages: {
|
|---|
| 24 | multipleTestTitle: 'Test title is used multiple times in the same describe block.',
|
|---|
| 25 | multipleDescribeTitle: 'Describe block title is used multiple times in the same describe block.'
|
|---|
| 26 | },
|
|---|
| 27 | schema: [],
|
|---|
| 28 | type: 'suggestion'
|
|---|
| 29 | },
|
|---|
| 30 | defaultOptions: [],
|
|---|
| 31 |
|
|---|
| 32 | create(context) {
|
|---|
| 33 | const contexts = [newDescribeContext()];
|
|---|
| 34 | return {
|
|---|
| 35 | CallExpression(node) {
|
|---|
| 36 | var _getNodeName;
|
|---|
| 37 |
|
|---|
| 38 | const currentLayer = contexts[contexts.length - 1];
|
|---|
| 39 |
|
|---|
| 40 | if ((0, _utils.isDescribeCall)(node)) {
|
|---|
| 41 | contexts.push(newDescribeContext());
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | if ((_getNodeName = (0, _utils.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 && _getNodeName.endsWith('.each')) {
|
|---|
| 45 | return;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | const [argument] = node.arguments;
|
|---|
| 49 |
|
|---|
| 50 | if (!argument || !(0, _utils.isStringNode)(argument)) {
|
|---|
| 51 | return;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | const title = (0, _utils.getStringValue)(argument);
|
|---|
| 55 |
|
|---|
| 56 | if ((0, _utils.isTestCaseCall)(node)) {
|
|---|
| 57 | if (currentLayer.testTitles.includes(title)) {
|
|---|
| 58 | context.report({
|
|---|
| 59 | messageId: 'multipleTestTitle',
|
|---|
| 60 | node: argument
|
|---|
| 61 | });
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | currentLayer.testTitles.push(title);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | if (!(0, _utils.isDescribeCall)(node)) {
|
|---|
| 68 | return;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | if (currentLayer.describeTitles.includes(title)) {
|
|---|
| 72 | context.report({
|
|---|
| 73 | messageId: 'multipleDescribeTitle',
|
|---|
| 74 | node: argument
|
|---|
| 75 | });
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | currentLayer.describeTitles.push(title);
|
|---|
| 79 | },
|
|---|
| 80 |
|
|---|
| 81 | 'CallExpression:exit'(node) {
|
|---|
| 82 | if ((0, _utils.isDescribeCall)(node)) {
|
|---|
| 83 | contexts.pop();
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | };
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | });
|
|---|
| 91 |
|
|---|
| 92 | exports.default = _default; |
|---|