|
| 1 | +import { TSESLint } from '@typescript-eslint/experimental-utils'; |
| 2 | +import dedent from 'dedent'; |
| 3 | +import resolveFrom from 'resolve-from'; |
| 4 | +import rule from '../max-nested-describe'; |
| 5 | + |
| 6 | +const ruleTester = new TSESLint.RuleTester({ |
| 7 | + parser: resolveFrom(require.resolve('eslint'), 'espree'), |
| 8 | + parserOptions: { |
| 9 | + ecmaVersion: 2017, |
| 10 | + }, |
| 11 | +}); |
| 12 | + |
| 13 | +ruleTester.run('max-nested-describe', rule, { |
| 14 | + valid: [ |
| 15 | + dedent` |
| 16 | + describe('foo', function() { |
| 17 | + describe('bar', function () { |
| 18 | + describe('baz', function () { |
| 19 | + describe('qux', function () { |
| 20 | + describe('qux', function () { |
| 21 | + it('should get something', () => { |
| 22 | + expect(getSomething()).toBe('Something'); |
| 23 | + }); |
| 24 | + }) |
| 25 | + }) |
| 26 | + }) |
| 27 | + }) |
| 28 | + }); |
| 29 | + `, |
| 30 | + dedent` |
| 31 | + describe('foo', function() { |
| 32 | + describe('bar', function () { |
| 33 | + describe('baz', function () { |
| 34 | + describe('qux', function () { |
| 35 | + describe('qux', function () { |
| 36 | + it('should get something', () => { |
| 37 | + expect(getSomething()).toBe('Something'); |
| 38 | + }); |
| 39 | + }); |
| 40 | +
|
| 41 | + fdescribe('qux', () => { |
| 42 | + it('something', async () => { |
| 43 | + expect('something').toBe('something'); |
| 44 | + }); |
| 45 | + }); |
| 46 | + }) |
| 47 | + }) |
| 48 | + }) |
| 49 | + }); |
| 50 | + `, |
| 51 | + dedent` |
| 52 | + describe('foo', () => { |
| 53 | + describe('bar', () => { |
| 54 | + it('hello', async () => { |
| 55 | + expect('hello').toBe('hello'); |
| 56 | + }); |
| 57 | + }); |
| 58 | + }); |
| 59 | +
|
| 60 | + xdescribe('foo', function() { |
| 61 | + describe('bar', function() { |
| 62 | + it('something', async () => { |
| 63 | + expect('something').toBe('something'); |
| 64 | + }); |
| 65 | + }); |
| 66 | + }); |
| 67 | + `, |
| 68 | + { |
| 69 | + code: dedent` |
| 70 | + describe('foo', () => { |
| 71 | + describe.only('bar', () => { |
| 72 | + describe.skip('baz', () => { |
| 73 | + it('something', async () => { |
| 74 | + expect('something').toBe('something'); |
| 75 | + }); |
| 76 | + }); |
| 77 | + }); |
| 78 | + }); |
| 79 | + `, |
| 80 | + options: [{ max: 3 }], |
| 81 | + }, |
| 82 | + { |
| 83 | + code: dedent` |
| 84 | + it('something', async () => { |
| 85 | + expect('something').toBe('something'); |
| 86 | + }); |
| 87 | + `, |
| 88 | + options: [{ max: 0 }], |
| 89 | + }, |
| 90 | + dedent` |
| 91 | + describe('foo', () => { |
| 92 | + describe.each(['hello', 'world'])("%s", (a) => {}); |
| 93 | + }); |
| 94 | + `, |
| 95 | + dedent` |
| 96 | + describe('foo', () => { |
| 97 | + describe.each\` |
| 98 | + foo | bar |
| 99 | + ${1} | ${2} |
| 100 | + \`('$foo $bar', ({ foo, bar }) => {}); |
| 101 | + }); |
| 102 | + `, |
| 103 | + ], |
| 104 | + invalid: [ |
| 105 | + { |
| 106 | + code: dedent` |
| 107 | + describe('foo', function() { |
| 108 | + describe('bar', function () { |
| 109 | + describe('baz', function () { |
| 110 | + describe('qux', function () { |
| 111 | + describe('quxx', function () { |
| 112 | + describe('over limit', function () { |
| 113 | + it('should get something', () => { |
| 114 | + expect(getSomething()).toBe('Something'); |
| 115 | + }); |
| 116 | + }); |
| 117 | + }); |
| 118 | + }); |
| 119 | + }); |
| 120 | + }); |
| 121 | + }); |
| 122 | + `, |
| 123 | + errors: [{ messageId: 'exceededMaxDepth', line: 6, column: 11 }], |
| 124 | + }, |
| 125 | + { |
| 126 | + code: dedent` |
| 127 | + describe('foo', () => { |
| 128 | + describe('bar', () => { |
| 129 | + describe('baz', () => { |
| 130 | + describe('baz1', () => { |
| 131 | + describe('baz2', () => { |
| 132 | + describe('baz3', () => { |
| 133 | + it('should get something', () => { |
| 134 | + expect(getSomething()).toBe('Something'); |
| 135 | + }); |
| 136 | + }); |
| 137 | +
|
| 138 | + describe('baz4', () => { |
| 139 | + it('should get something', () => { |
| 140 | + expect(getSomething()).toBe('Something'); |
| 141 | + }); |
| 142 | + }); |
| 143 | + }); |
| 144 | + }); |
| 145 | + }); |
| 146 | +
|
| 147 | + describe('qux', function () { |
| 148 | + it('should get something', () => { |
| 149 | + expect(getSomething()).toBe('Something'); |
| 150 | + }); |
| 151 | + }); |
| 152 | + }) |
| 153 | + }); |
| 154 | + `, |
| 155 | + errors: [ |
| 156 | + { messageId: 'exceededMaxDepth', line: 6, column: 11 }, |
| 157 | + { messageId: 'exceededMaxDepth', line: 12, column: 11 }, |
| 158 | + ], |
| 159 | + }, |
| 160 | + { |
| 161 | + code: dedent` |
| 162 | + fdescribe('foo', () => { |
| 163 | + describe.only('bar', () => { |
| 164 | + describe.skip('baz', () => { |
| 165 | + it('should get something', () => { |
| 166 | + expect(getSomething()).toBe('Something'); |
| 167 | + }); |
| 168 | + }); |
| 169 | +
|
| 170 | + describe('baz', () => { |
| 171 | + it('should get something', () => { |
| 172 | + expect(getSomething()).toBe('Something'); |
| 173 | + }); |
| 174 | + }); |
| 175 | + }); |
| 176 | + }); |
| 177 | +
|
| 178 | + xdescribe('qux', () => { |
| 179 | + it('should get something', () => { |
| 180 | + expect(getSomething()).toBe('Something'); |
| 181 | + }); |
| 182 | + }); |
| 183 | + `, |
| 184 | + options: [{ max: 2 }], |
| 185 | + errors: [ |
| 186 | + { messageId: 'exceededMaxDepth', line: 3, column: 5 }, |
| 187 | + { messageId: 'exceededMaxDepth', line: 9, column: 5 }, |
| 188 | + ], |
| 189 | + }, |
| 190 | + { |
| 191 | + code: dedent` |
| 192 | + describe('qux', () => { |
| 193 | + it('should get something', () => { |
| 194 | + expect(getSomething()).toBe('Something'); |
| 195 | + }); |
| 196 | + }); |
| 197 | + `, |
| 198 | + options: [{ max: 0 }], |
| 199 | + errors: [{ messageId: 'exceededMaxDepth', line: 1, column: 1 }], |
| 200 | + }, |
| 201 | + { |
| 202 | + code: dedent` |
| 203 | + describe('foo', () => { |
| 204 | + describe.each(['hello', 'world'])("%s", (a) => {}); |
| 205 | + }); |
| 206 | + `, |
| 207 | + options: [{ max: 1 }], |
| 208 | + errors: [{ messageId: 'exceededMaxDepth', line: 2, column: 3 }], |
| 209 | + }, |
| 210 | + { |
| 211 | + code: dedent` |
| 212 | + describe('foo', () => { |
| 213 | + describe.each\` |
| 214 | + foo | bar |
| 215 | + ${1} | ${2} |
| 216 | + \`('$foo $bar', ({ foo, bar }) => {}); |
| 217 | + }); |
| 218 | + `, |
| 219 | + options: [{ max: 1 }], |
| 220 | + errors: [{ messageId: 'exceededMaxDepth', line: 2, column: 3 }], |
| 221 | + }, |
| 222 | + ], |
| 223 | +}); |
0 commit comments