|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { RuleTester } = require('eslint'); |
| 4 | +const rule = require('../no-commented-out-tests'); |
| 5 | + |
| 6 | +const ruleTester = new RuleTester({ |
| 7 | + parserOptions: { |
| 8 | + sourceType: 'module', |
| 9 | + }, |
| 10 | +}); |
| 11 | + |
| 12 | +ruleTester.run('no-commented-out-tests', rule, { |
| 13 | + valid: [ |
| 14 | + '// foo("bar", function () {})', |
| 15 | + 'describe("foo", function () {})', |
| 16 | + 'it("foo", function () {})', |
| 17 | + 'describe.only("foo", function () {})', |
| 18 | + 'it.only("foo", function () {})', |
| 19 | + 'test("foo", function () {})', |
| 20 | + 'test.only("foo", function () {})', |
| 21 | + 'var appliedSkip = describe.skip; appliedSkip.apply(describe)', |
| 22 | + 'var calledSkip = it.skip; calledSkip.call(it)', |
| 23 | + '({ f: function () {} }).f()', |
| 24 | + '(a || b).f()', |
| 25 | + 'itHappensToStartWithIt()', |
| 26 | + 'testSomething()', |
| 27 | + [ |
| 28 | + 'import { pending } from "actions"', |
| 29 | + '', |
| 30 | + 'test("foo", () => {', |
| 31 | + ' expect(pending()).toEqual({})', |
| 32 | + '})', |
| 33 | + ].join('\n'), |
| 34 | + [ |
| 35 | + 'const { pending } = require("actions")', |
| 36 | + '', |
| 37 | + 'test("foo", () => {', |
| 38 | + ' expect(pending()).toEqual({})', |
| 39 | + '})', |
| 40 | + ].join('\n'), |
| 41 | + [ |
| 42 | + 'test("foo", () => {', |
| 43 | + ' const pending = getPending()', |
| 44 | + ' expect(pending()).toEqual({})', |
| 45 | + '})', |
| 46 | + ].join('\n'), |
| 47 | + [ |
| 48 | + 'test("foo", () => {', |
| 49 | + ' expect(pending()).toEqual({})', |
| 50 | + '})', |
| 51 | + '', |
| 52 | + 'function pending() {', |
| 53 | + ' return {}', |
| 54 | + '}', |
| 55 | + ].join('\n'), |
| 56 | + ], |
| 57 | + |
| 58 | + invalid: [ |
| 59 | + { |
| 60 | + code: '// describe("foo", function () {})', |
| 61 | + errors: [ |
| 62 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 63 | + ], |
| 64 | + }, |
| 65 | + { |
| 66 | + code: '// describe["skip"]("foo", function () {})', |
| 67 | + errors: [ |
| 68 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 69 | + ], |
| 70 | + }, |
| 71 | + { |
| 72 | + code: '// describe[\'skip\']("foo", function () {})', |
| 73 | + errors: [ |
| 74 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 75 | + ], |
| 76 | + }, |
| 77 | + { |
| 78 | + code: '// it.skip("foo", function () {})', |
| 79 | + errors: [ |
| 80 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 81 | + ], |
| 82 | + }, |
| 83 | + { |
| 84 | + code: '// it.only("foo", function () {})', |
| 85 | + errors: [ |
| 86 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 87 | + ], |
| 88 | + }, |
| 89 | + { |
| 90 | + code: '// it["skip"]("foo", function () {})', |
| 91 | + errors: [ |
| 92 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + { |
| 96 | + code: '// test.skip("foo", function () {})', |
| 97 | + errors: [ |
| 98 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 99 | + ], |
| 100 | + }, |
| 101 | + { |
| 102 | + code: '// test["skip"]("foo", function () {})', |
| 103 | + errors: [ |
| 104 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 105 | + ], |
| 106 | + }, |
| 107 | + { |
| 108 | + code: '// xdescribe("foo", function () {})', |
| 109 | + errors: [ |
| 110 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 111 | + ], |
| 112 | + }, |
| 113 | + { |
| 114 | + code: '// xit("foo", function () {})', |
| 115 | + errors: [ |
| 116 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 117 | + ], |
| 118 | + }, |
| 119 | + { |
| 120 | + code: '// fit("foo", function () {})', |
| 121 | + errors: [ |
| 122 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 123 | + ], |
| 124 | + }, |
| 125 | + { |
| 126 | + code: '// xtest("foo", function () {})', |
| 127 | + errors: [ |
| 128 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 129 | + ], |
| 130 | + }, |
| 131 | + { |
| 132 | + code: `// test( |
| 133 | + // "foo", function () {} |
| 134 | + // )`, |
| 135 | + errors: [ |
| 136 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 137 | + ], |
| 138 | + }, |
| 139 | + { |
| 140 | + code: `/* test |
| 141 | + ( |
| 142 | + "foo", function () {} |
| 143 | + ) |
| 144 | + */`, |
| 145 | + errors: [ |
| 146 | + { message: 'Some tests seem to be commented', column: 1, line: 1 }, |
| 147 | + ], |
| 148 | + }, |
| 149 | + { |
| 150 | + code: '// it("has title but no callback")', |
| 151 | + errors: [ |
| 152 | + { |
| 153 | + message: 'Some tests seem to be commented', |
| 154 | + column: 1, |
| 155 | + line: 1, |
| 156 | + }, |
| 157 | + ], |
| 158 | + }, |
| 159 | + { |
| 160 | + code: '// it()', |
| 161 | + errors: [ |
| 162 | + { |
| 163 | + message: 'Some tests seem to be commented', |
| 164 | + column: 1, |
| 165 | + line: 1, |
| 166 | + }, |
| 167 | + ], |
| 168 | + }, |
| 169 | + { |
| 170 | + code: '// test.someNewMethodThatMightBeAddedInTheFuture()', |
| 171 | + errors: [ |
| 172 | + { |
| 173 | + message: 'Some tests seem to be commented', |
| 174 | + column: 1, |
| 175 | + line: 1, |
| 176 | + }, |
| 177 | + ], |
| 178 | + }, |
| 179 | + { |
| 180 | + code: '// test["someNewMethodThatMightBeAddedInTheFuture"]()', |
| 181 | + errors: [ |
| 182 | + { |
| 183 | + message: 'Some tests seem to be commented', |
| 184 | + column: 1, |
| 185 | + line: 1, |
| 186 | + }, |
| 187 | + ], |
| 188 | + }, |
| 189 | + { |
| 190 | + code: '// test("has title but no callback")', |
| 191 | + errors: [ |
| 192 | + { |
| 193 | + message: 'Some tests seem to be commented', |
| 194 | + column: 1, |
| 195 | + line: 1, |
| 196 | + }, |
| 197 | + ], |
| 198 | + }, |
| 199 | + { |
| 200 | + code: ` |
| 201 | + foo() |
| 202 | + /* |
| 203 | + describe("has title but no callback", () => {}) |
| 204 | + */ |
| 205 | + bar()`, |
| 206 | + errors: [ |
| 207 | + { |
| 208 | + message: 'Some tests seem to be commented', |
| 209 | + column: 7, |
| 210 | + line: 3, |
| 211 | + }, |
| 212 | + ], |
| 213 | + }, |
| 214 | + ], |
| 215 | +}); |
0 commit comments