|
| 1 | +import dedent from 'dedent'; |
| 2 | +import rule from '../../src/rules/no-commented-out-tests'; |
| 3 | +import { runRuleTester } from '../utils/rule-tester'; |
| 4 | + |
| 5 | +const messageId = 'commentedTests'; |
| 6 | + |
| 7 | +runRuleTester('no-commented-out-tests', rule, { |
| 8 | + invalid: [ |
| 9 | + { |
| 10 | + code: '// test.describe("foo", function () {})', |
| 11 | + errors: [{ column: 1, line: 1, messageId }], |
| 12 | + }, |
| 13 | + { |
| 14 | + code: '// describe["skip"]("foo", function () {})', |
| 15 | + errors: [{ column: 1, line: 1, messageId }], |
| 16 | + }, |
| 17 | + { |
| 18 | + code: '// describe[\'skip\']("foo", function () {})', |
| 19 | + errors: [{ column: 1, line: 1, messageId }], |
| 20 | + }, |
| 21 | + { |
| 22 | + code: '// test("foo", function () {})', |
| 23 | + errors: [{ column: 1, line: 1, messageId }], |
| 24 | + }, |
| 25 | + { |
| 26 | + code: '// test.only("foo", function () {})', |
| 27 | + errors: [{ column: 1, line: 1, messageId }], |
| 28 | + }, |
| 29 | + { |
| 30 | + code: '// test["skip"]("foo", function () {})', |
| 31 | + errors: [{ column: 1, line: 1, messageId }], |
| 32 | + }, |
| 33 | + { |
| 34 | + code: '// test.skip("foo", function () {})', |
| 35 | + errors: [{ column: 1, line: 1, messageId }], |
| 36 | + }, |
| 37 | + { |
| 38 | + code: '// test["skip"]("foo", function () {})', |
| 39 | + errors: [{ column: 1, line: 1, messageId }], |
| 40 | + }, |
| 41 | + { |
| 42 | + code: dedent` |
| 43 | + // test( |
| 44 | + // "foo", function () {} |
| 45 | + // ) |
| 46 | + `, |
| 47 | + errors: [{ column: 1, line: 1, messageId }], |
| 48 | + }, |
| 49 | + { |
| 50 | + code: dedent` |
| 51 | + /* test |
| 52 | + ( |
| 53 | + "foo", function () {} |
| 54 | + ) |
| 55 | + */ |
| 56 | + `, |
| 57 | + errors: [{ column: 1, line: 1, messageId }], |
| 58 | + }, |
| 59 | + { |
| 60 | + code: '// test("has title but no callback")', |
| 61 | + errors: [{ column: 1, line: 1, messageId }], |
| 62 | + }, |
| 63 | + { |
| 64 | + code: '// test()', |
| 65 | + errors: [{ column: 1, line: 1, messageId }], |
| 66 | + }, |
| 67 | + { |
| 68 | + code: '// test.someNewMethodThatMightBeAddedInTheFuture()', |
| 69 | + errors: [{ column: 1, line: 1, messageId }], |
| 70 | + }, |
| 71 | + { |
| 72 | + code: '// test["someNewMethodThatMightBeAddedInTheFuture"]()', |
| 73 | + errors: [{ column: 1, line: 1, messageId }], |
| 74 | + }, |
| 75 | + { |
| 76 | + code: '// test("has title but no callback")', |
| 77 | + errors: [{ column: 1, line: 1, messageId }], |
| 78 | + }, |
| 79 | + { |
| 80 | + code: dedent` |
| 81 | + foo() |
| 82 | + /* |
| 83 | + test.describe("has title but no callback", () => {}) |
| 84 | + */ |
| 85 | + bar() |
| 86 | + `, |
| 87 | + errors: [{ column: 1, line: 2, messageId }], |
| 88 | + }, |
| 89 | + // Global aliases |
| 90 | + { |
| 91 | + code: '// it("foo", () => {});', |
| 92 | + errors: [{ column: 1, line: 1, messageId }], |
| 93 | + settings: { |
| 94 | + playwright: { |
| 95 | + globalAliases: { test: ['it'] }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + }, |
| 99 | + ], |
| 100 | + valid: [ |
| 101 | + '// foo("bar", function () {})', |
| 102 | + 'test.describe("foo", function () {})', |
| 103 | + 'test("foo", function () {})', |
| 104 | + 'test.describe.only("foo", function () {})', |
| 105 | + 'test.only("foo", function () {})', |
| 106 | + 'test.skip("foo", function () {})', |
| 107 | + 'test("foo", function () {})', |
| 108 | + 'test.only("foo", function () {})', |
| 109 | + 'test.concurrent("foo", function () {})', |
| 110 | + 'var appliedSkip = describe.skip; appliedSkip.apply(describe)', |
| 111 | + 'var calledSkip = test.skip; calledSkip.call(it)', |
| 112 | + '({ f: function () {} }).f()', |
| 113 | + '(a || b).f()', |
| 114 | + 'testHappensToStartWithTest()', |
| 115 | + 'testSomething()', |
| 116 | + '// latest(dates)', |
| 117 | + '// TODO: unify with Git implementation from Shipit (?)', |
| 118 | + '#!/usr/bin/env node', |
| 119 | + dedent` |
| 120 | + import { pending } from "actions" |
| 121 | +
|
| 122 | + test("foo", () => { |
| 123 | + expect(pending()).toEqual({}) |
| 124 | + }) |
| 125 | + `, |
| 126 | + dedent` |
| 127 | + const { pending } = require("actions") |
| 128 | +
|
| 129 | + test("foo", () => { |
| 130 | + expect(pending()).toEqual({}) |
| 131 | + }) |
| 132 | + `, |
| 133 | + dedent` |
| 134 | + test("foo", () => { |
| 135 | + const pending = getPending() |
| 136 | + expect(pending()).toEqual({}) |
| 137 | + }) |
| 138 | + `, |
| 139 | + dedent` |
| 140 | + test("foo", () => { |
| 141 | + expect(pending()).toEqual({}) |
| 142 | + }) |
| 143 | +
|
| 144 | + function pending() { |
| 145 | + return {} |
| 146 | + } |
| 147 | + `, |
| 148 | + // Global aliases |
| 149 | + { |
| 150 | + code: 'it("foo", () => {});', |
| 151 | + settings: { |
| 152 | + playwright: { |
| 153 | + globalAliases: { test: ['it'] }, |
| 154 | + }, |
| 155 | + }, |
| 156 | + }, |
| 157 | + ], |
| 158 | +}); |
0 commit comments