Skip to content

Commit 03bb96b

Browse files
committed
fix: correctly identify the newly created file as a test file
Fixes #617
1 parent 80713ab commit 03bb96b

File tree

2 files changed

+80
-89
lines changed

2 files changed

+80
-89
lines changed

samples/basic/test/each.test.ts

Lines changed: 79 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,84 @@
11
import { describe, expect, it, test, } from 'vitest'
22

3-
4-
describe.each([0, 3])('some terr %s.', () => {
5-
describe.each([1, 2])('testing %s', () => {
6-
it.each([3, 4])('testing %s and %s', (a) => {
7-
expect(a).toBe(a)
8-
})
3+
describe('testing', (a) => {
4+
it.each([
5+
[1, 1], [2, 2], [3, 3]
6+
])(`all pass: %i => %i`, (a, b) => {
7+
expect(a).toBe(b)
8+
})
9+
it.each([
10+
[1, 1], [2, 1], [3, 1]
11+
])(`first pass: %i => %i`, (a, b) => {
12+
expect(a).toBe(b)
13+
})
14+
it.each([
15+
[1, 1], [2, 2], [3, 1]
16+
])(`last pass: %i => %i`, (a, b) => {
17+
expect(a).toBe(b)
18+
})
19+
it.each([
20+
[1, 1], [2, 2], [3, 1]
21+
])(`first fail: %i => %i`, (a, b) => {
22+
expect(a).toBe(b)
23+
})
24+
it.each([
25+
[1, 1], [2, 2], [3, 1]
26+
])(`last fail: %i => %i`, (a, b) => {
27+
expect(a).toBe(b)
28+
})
29+
it.each([
30+
[1, 0], [2, 0], [3, 0]
31+
])(`all fail: %i => %i`, (a, b) => {
32+
expect(a).toBe(b)
33+
})
34+
it.each([
35+
1, 2, 3
36+
])('run %i', (a) => {
37+
expect(a).toBe(a)
38+
})
39+
it.each([
40+
[1, 1], [2, 4], [3, 9]
41+
])('run mul %i', (a,b) => {
42+
expect(a * a).toBe(b)
43+
})
44+
test.each([
45+
["test1", 1],
46+
["test2", 2],
47+
["test3", 3],
48+
])(`%s => %i`, (a, b) => {
49+
expect(a.at(-1)).toBe(`${b}`)
50+
})
51+
test.each`
52+
a | b | expected
53+
${1} | ${1} | ${2}
54+
${'a'} | ${'b'} | ${'ab'}
55+
${[]} | ${'b'} | ${'b'}
56+
${{}} | ${'b'} | ${'[object Object]b'}
57+
${{ asd: 1 }} | ${'b'} | ${'[object Object]b'}
58+
`('table1: returns $expected when $a is added $b', ({ a, b, expected }) => {
59+
expect(a + b).toBe(expected)
60+
})
61+
test.each`
62+
a | b | expected
63+
${{v: 1}} | ${{v: 1}} | ${2}
64+
`('table2: returns $expected when $a.v is added $b.v', ({ a, b, expected }) => {
65+
expect(a.v + b.v).toBe(expected)
66+
})
67+
test.each([
68+
{ input: 1, add: 1, sum: 2 },
69+
{ input: 2, add: 2, sum: 4 },
70+
])('$input + $add = $sum', ({ input, add, sum }) => {
71+
expect(input + add).toBe(sum)
972
})
1073
})
1174

12-
// describe('testing', (a) => {
13-
// it.each([
14-
// [1, 1], [2, 2], [3, 3]
15-
// ])(`all pass: %i => %i`, (a, b) => {
16-
// expect(a).toBe(b)
17-
// })
18-
// it.each([
19-
// [1, 1], [2, 1], [3, 1]
20-
// ])(`first pass: %i => %i`, (a, b) => {
21-
// expect(a).toBe(b)
22-
// })
23-
// it.each([
24-
// [1, 1], [2, 2], [3, 1]
25-
// ])(`last pass: %i => %i`, (a, b) => {
26-
// expect(a).toBe(b)
27-
// })
28-
// it.each([
29-
// [1, 1], [2, 2], [3, 1]
30-
// ])(`first fail: %i => %i`, (a, b) => {
31-
// expect(a).toBe(b)
32-
// })
33-
// it.each([
34-
// [1, 1], [2, 2], [3, 1]
35-
// ])(`last fail: %i => %i`, (a, b) => {
36-
// expect(a).toBe(b)
37-
// })
38-
// it.each([
39-
// [1, 0], [2, 0], [3, 0]
40-
// ])(`all fail: %i => %i`, (a, b) => {
41-
// expect(a).toBe(b)
42-
// })
43-
// it.each([
44-
// 1, 2, 3
45-
// ])('run %i', (a) => {
46-
// expect(a).toBe(a)
47-
// })
48-
// it.each([
49-
// [1, 1], [2, 4], [3, 9]
50-
// ])('run mul %i', (a,b) => {
51-
// expect(a * a).toBe(b)
52-
// })
53-
// test.each([
54-
// ["test1", 1],
55-
// ["test2", 2],
56-
// ["test3", 3],
57-
// ])(`%s => %i`, (a, b) => {
58-
// expect(a.at(-1)).toBe(`${b}`)
59-
// })
60-
// test.each`
61-
// a | b | expected
62-
// ${1} | ${1} | ${2}
63-
// ${'a'} | ${'b'} | ${'ab'}
64-
// ${[]} | ${'b'} | ${'b'}
65-
// ${{}} | ${'b'} | ${'[object Object]b'}
66-
// ${{ asd: 1 }} | ${'b'} | ${'[object Object]b'}
67-
// `('table1: returns $expected when $a is added $b', ({ a, b, expected }) => {
68-
// expect(a + b).toBe(expected)
69-
// })
70-
// test.each`
71-
// a | b | expected
72-
// ${{v: 1}} | ${{v: 1}} | ${2}
73-
// `('table2: returns $expected when $a.v is added $b.v', ({ a, b, expected }) => {
74-
// expect(a.v + b.v).toBe(expected)
75-
// })
76-
// test.each([
77-
// { input: 1, add: 1, sum: 2 },
78-
// { input: 2, add: 2, sum: 4 },
79-
// ])('$input + $add = $sum', ({ input, add, sum }) => {
80-
// expect(input + add).toBe(sum)
81-
// })
82-
// })
83-
84-
// // 'Test result not fourd' error occurs as both .each patterns are matched
85-
// // TODO: Fix this
86-
// describe("over matched test patterns", () => {
87-
// test.each(['1', '2'])('run %s', (a) => {
88-
// expect(a).toBe(String(a))
89-
// })
90-
// test.each(['1', '2'])('run for %s', (a) => {
91-
// expect(a).toBe(String(a))
92-
// })
93-
// })
75+
// 'Test result not fourd' error occurs as both .each patterns are matched
76+
// TODO: Fix this
77+
describe("over matched test patterns", () => {
78+
test.each(['1', '2'])('run %s', (a) => {
79+
expect(a).toBe(String(a))
80+
})
81+
test.each(['1', '2'])('run for %s', (a) => {
82+
expect(a).toBe(String(a))
83+
})
84+
})

src/watcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class ExtensionWatcher extends vscode.Disposable {
6161
}
6262
log.verbose?.('[VSCODE] File created:', this.relative(api, uri))
6363
const apis = this.apisByFolder.get(folder) || []
64-
apis.forEach(api => api.onFileChanged(path))
64+
apis.forEach(api => api.onFileCreated(path))
6565
})
6666
}
6767

0 commit comments

Comments
 (0)