Skip to content

Commit 7070806

Browse files
paescujveritem
andauthored
fix: make .extend exclusive, add .scoped (#809)
* fix: make `.extend` exclusive, add `.scoped` * fix: regenerate valid chains * fix: merge conflict --------- Co-authored-by: Verité <[email protected]>
1 parent 20e5301 commit 7070806

File tree

4 files changed

+17
-146
lines changed

4 files changed

+17
-146
lines changed

scripts/chain-permutations.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,31 @@ const data = [
1212
{
1313
names: ['beforeEach', 'beforeAll', 'afterEach', 'afterAll'],
1414
first: [],
15+
exclusive: [],
1516
conditions: [],
1617
methods: [],
1718
last: [],
1819
},
1920
{
2021
names: ['it', 'test'],
21-
first: ['extend'],
22+
first: [],
23+
exclusive: ['extend', 'scoped'],
2224
conditions: ['skipIf', 'runIf'],
2325
methods: ['skip', 'only', 'concurrent', 'sequential', 'todo', 'fails'],
2426
last: ['each', 'for'],
2527
},
2628
{
2729
names: ['bench'],
2830
first: [],
31+
exclusive: [],
2932
conditions: ['skipIf', 'runIf'],
3033
methods: ['skip', 'only', 'todo'],
3134
last: [],
3235
},
3336
{
3437
names: ['describe', 'suite'],
3538
first: [],
39+
exclusive: [],
3640
conditions: ['skipIf', 'runIf'],
3741
methods: ['skip', 'only', 'concurrent', 'sequential', 'shuffle', 'todo'],
3842
last: ['each', 'for'],
@@ -43,15 +47,15 @@ const DEPTH = 3
4347

4448
const allPermutations: string[] = []
4549

46-
const depths = (maxDepth: number) =>
47-
Array.from({ length: maxDepth }, (_, i) => i)
48-
4950
data.forEach((q) => {
5051
q.names.forEach((name) => {
5152
allPermutations.push(name)
5253

54+
allPermutations.push(...q.exclusive.map((p) => [name, p].join('.')))
55+
5356
const maxDepth = Math.min(DEPTH, q.methods.length)
54-
const methodPerms = depths(maxDepth).flatMap((i) => [
57+
const depths = Array.from({ length: maxDepth }, (_, i) => i)
58+
const methodPerms = depths.flatMap((i) => [
5559
...per(q.methods, i + 1),
5660
...q.first.flatMap((first) =>
5761
(per(q.methods, i) || ['']).map((p) => [first, ...p]),
@@ -106,8 +110,7 @@ data.forEach((q) => {
106110
)
107111
: []),
108112
])
109-
const allPerms = methodPerms.map((p) => [name, ...p].join('.'))
110-
allPermutations.push(...allPerms)
113+
allPermutations.push(...methodPerms.map((p) => [name, ...p].join('.')))
111114
})
112115
})
113116

src/utils/valid-vitest-fn-call-chains.ts

Lines changed: 4 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ export const ValidVitestFnCallChains = new Set([
44
'afterEach',
55
'afterAll',
66
'it',
7+
'it.extend',
8+
'it.scoped',
79
'it.skip',
810
'it.only',
911
'it.concurrent',
1012
'it.sequential',
1113
'it.todo',
1214
'it.fails',
13-
'it.extend',
1415
'it.skipIf',
1516
'it.runIf',
1617
'it.each',
@@ -45,12 +46,6 @@ export const ValidVitestFnCallChains = new Set([
4546
'it.fails.concurrent',
4647
'it.fails.sequential',
4748
'it.fails.todo',
48-
'it.extend.skip',
49-
'it.extend.only',
50-
'it.extend.concurrent',
51-
'it.extend.sequential',
52-
'it.extend.todo',
53-
'it.extend.fails',
5449
'it.skipIf.skip',
5550
'it.skipIf.only',
5651
'it.skipIf.concurrent',
@@ -75,10 +70,6 @@ export const ValidVitestFnCallChains = new Set([
7570
'it.sequential.for',
7671
'it.todo.for',
7772
'it.fails.for',
78-
'it.extend.skipIf',
79-
'it.extend.runIf',
80-
'it.extend.each',
81-
'it.extend.for',
8273
'it.skipIf.each',
8374
'it.skipIf.for',
8475
'it.runIf.each',
@@ -203,36 +194,6 @@ export const ValidVitestFnCallChains = new Set([
203194
'it.fails.todo.only',
204195
'it.fails.todo.concurrent',
205196
'it.fails.todo.sequential',
206-
'it.extend.skip.only',
207-
'it.extend.skip.concurrent',
208-
'it.extend.skip.sequential',
209-
'it.extend.skip.todo',
210-
'it.extend.skip.fails',
211-
'it.extend.only.skip',
212-
'it.extend.only.concurrent',
213-
'it.extend.only.sequential',
214-
'it.extend.only.todo',
215-
'it.extend.only.fails',
216-
'it.extend.concurrent.skip',
217-
'it.extend.concurrent.only',
218-
'it.extend.concurrent.sequential',
219-
'it.extend.concurrent.todo',
220-
'it.extend.concurrent.fails',
221-
'it.extend.sequential.skip',
222-
'it.extend.sequential.only',
223-
'it.extend.sequential.concurrent',
224-
'it.extend.sequential.todo',
225-
'it.extend.sequential.fails',
226-
'it.extend.todo.skip',
227-
'it.extend.todo.only',
228-
'it.extend.todo.concurrent',
229-
'it.extend.todo.sequential',
230-
'it.extend.todo.fails',
231-
'it.extend.fails.skip',
232-
'it.extend.fails.only',
233-
'it.extend.fails.concurrent',
234-
'it.extend.fails.sequential',
235-
'it.extend.fails.todo',
236197
'it.skipIf.skip.only',
237198
'it.skipIf.skip.concurrent',
238199
'it.skipIf.skip.sequential',
@@ -353,30 +314,6 @@ export const ValidVitestFnCallChains = new Set([
353314
'it.fails.concurrent.for',
354315
'it.fails.sequential.for',
355316
'it.fails.todo.for',
356-
'it.extend.skipIf.skip',
357-
'it.extend.skipIf.only',
358-
'it.extend.skipIf.concurrent',
359-
'it.extend.skipIf.sequential',
360-
'it.extend.skipIf.todo',
361-
'it.extend.skipIf.fails',
362-
'it.extend.runIf.skip',
363-
'it.extend.runIf.only',
364-
'it.extend.runIf.concurrent',
365-
'it.extend.runIf.sequential',
366-
'it.extend.runIf.todo',
367-
'it.extend.runIf.fails',
368-
'it.extend.skip.each',
369-
'it.extend.only.each',
370-
'it.extend.concurrent.each',
371-
'it.extend.sequential.each',
372-
'it.extend.todo.each',
373-
'it.extend.fails.each',
374-
'it.extend.skip.for',
375-
'it.extend.only.for',
376-
'it.extend.concurrent.for',
377-
'it.extend.sequential.for',
378-
'it.extend.todo.for',
379-
'it.extend.fails.for',
380317
'it.skipIf.skip.each',
381318
'it.skipIf.only.each',
382319
'it.skipIf.concurrent.each',
@@ -401,18 +338,15 @@ export const ValidVitestFnCallChains = new Set([
401338
'it.runIf.sequential.for',
402339
'it.runIf.todo.for',
403340
'it.runIf.fails.for',
404-
'it.extend.skipIf.each',
405-
'it.extend.skipIf.for',
406-
'it.extend.runIf.each',
407-
'it.extend.runIf.for',
408341
'test',
342+
'test.extend',
343+
'test.scoped',
409344
'test.skip',
410345
'test.only',
411346
'test.concurrent',
412347
'test.sequential',
413348
'test.todo',
414349
'test.fails',
415-
'test.extend',
416350
'test.skipIf',
417351
'test.runIf',
418352
'test.each',
@@ -447,12 +381,6 @@ export const ValidVitestFnCallChains = new Set([
447381
'test.fails.concurrent',
448382
'test.fails.sequential',
449383
'test.fails.todo',
450-
'test.extend.skip',
451-
'test.extend.only',
452-
'test.extend.concurrent',
453-
'test.extend.sequential',
454-
'test.extend.todo',
455-
'test.extend.fails',
456384
'test.skipIf.skip',
457385
'test.skipIf.only',
458386
'test.skipIf.concurrent',
@@ -477,10 +405,6 @@ export const ValidVitestFnCallChains = new Set([
477405
'test.sequential.for',
478406
'test.todo.for',
479407
'test.fails.for',
480-
'test.extend.skipIf',
481-
'test.extend.runIf',
482-
'test.extend.each',
483-
'test.extend.for',
484408
'test.skipIf.each',
485409
'test.skipIf.for',
486410
'test.runIf.each',
@@ -605,36 +529,6 @@ export const ValidVitestFnCallChains = new Set([
605529
'test.fails.todo.only',
606530
'test.fails.todo.concurrent',
607531
'test.fails.todo.sequential',
608-
'test.extend.skip.only',
609-
'test.extend.skip.concurrent',
610-
'test.extend.skip.sequential',
611-
'test.extend.skip.todo',
612-
'test.extend.skip.fails',
613-
'test.extend.only.skip',
614-
'test.extend.only.concurrent',
615-
'test.extend.only.sequential',
616-
'test.extend.only.todo',
617-
'test.extend.only.fails',
618-
'test.extend.concurrent.skip',
619-
'test.extend.concurrent.only',
620-
'test.extend.concurrent.sequential',
621-
'test.extend.concurrent.todo',
622-
'test.extend.concurrent.fails',
623-
'test.extend.sequential.skip',
624-
'test.extend.sequential.only',
625-
'test.extend.sequential.concurrent',
626-
'test.extend.sequential.todo',
627-
'test.extend.sequential.fails',
628-
'test.extend.todo.skip',
629-
'test.extend.todo.only',
630-
'test.extend.todo.concurrent',
631-
'test.extend.todo.sequential',
632-
'test.extend.todo.fails',
633-
'test.extend.fails.skip',
634-
'test.extend.fails.only',
635-
'test.extend.fails.concurrent',
636-
'test.extend.fails.sequential',
637-
'test.extend.fails.todo',
638532
'test.skipIf.skip.only',
639533
'test.skipIf.skip.concurrent',
640534
'test.skipIf.skip.sequential',
@@ -755,30 +649,6 @@ export const ValidVitestFnCallChains = new Set([
755649
'test.fails.concurrent.for',
756650
'test.fails.sequential.for',
757651
'test.fails.todo.for',
758-
'test.extend.skipIf.skip',
759-
'test.extend.skipIf.only',
760-
'test.extend.skipIf.concurrent',
761-
'test.extend.skipIf.sequential',
762-
'test.extend.skipIf.todo',
763-
'test.extend.skipIf.fails',
764-
'test.extend.runIf.skip',
765-
'test.extend.runIf.only',
766-
'test.extend.runIf.concurrent',
767-
'test.extend.runIf.sequential',
768-
'test.extend.runIf.todo',
769-
'test.extend.runIf.fails',
770-
'test.extend.skip.each',
771-
'test.extend.only.each',
772-
'test.extend.concurrent.each',
773-
'test.extend.sequential.each',
774-
'test.extend.todo.each',
775-
'test.extend.fails.each',
776-
'test.extend.skip.for',
777-
'test.extend.only.for',
778-
'test.extend.concurrent.for',
779-
'test.extend.sequential.for',
780-
'test.extend.todo.for',
781-
'test.extend.fails.for',
782652
'test.skipIf.skip.each',
783653
'test.skipIf.only.each',
784654
'test.skipIf.concurrent.each',
@@ -803,10 +673,6 @@ export const ValidVitestFnCallChains = new Set([
803673
'test.runIf.sequential.for',
804674
'test.runIf.todo.for',
805675
'test.runIf.fails.for',
806-
'test.extend.skipIf.each',
807-
'test.extend.skipIf.for',
808-
'test.extend.runIf.each',
809-
'test.extend.runIf.for',
810676
'bench',
811677
'bench.skip',
812678
'bench.only',

tests/no-standalone-expect.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ ruleTester.run(RULE_NAME, rule, {
1616
'it("an it", () => expect(1).toBe(1))',
1717
'it.only("an it", () => expect(1).toBe(1))',
1818
'it.concurrent("an it", () => expect(1).toBe(1))',
19-
'it.extend.skip("an it", () => expect(1).toBe(1))',
2019
'test("a test", () => expect(1).toBe(1))',
2120
'test.skip("a skipped test", () => expect(1).toBe(1))',
2221
'test.fails("a failing test", () => expect(1).toBe(1))',

tests/require-hook.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ ruleTester.run(RULE_NAME, rule, {
99
test('something', () => {
1010
expect(true).toBe(true);
1111
}));`,
12+
`describe('scoped', () => {
13+
test.scoped({ example: 'value' });
14+
});`,
1215
{
1316
code: `
1417
import { myFn } from '../functions';

0 commit comments

Comments
 (0)