Skip to content

Commit dc469f2

Browse files
authored
fix(runner): comments between fixture destructures (#8127)
1 parent 7bd11a9 commit dc469f2

File tree

7 files changed

+68
-5
lines changed

7 files changed

+68
-5
lines changed

packages/browser/src/node/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
241241
'vitest > @vitest/snapshot > magic-string',
242242
'vitest > chai',
243243
'vitest > chai > loupe',
244+
'vitest > strip-literal',
244245
'vitest > @vitest/utils > loupe',
245246
'@vitest/browser > @testing-library/user-event',
246247
'@vitest/browser > @testing-library/dom',

packages/runner/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
},
4444
"dependencies": {
4545
"@vitest/utils": "workspace:*",
46-
"pathe": "catalog:"
46+
"pathe": "catalog:",
47+
"strip-literal": "catalog:"
4748
}
4849
}

packages/runner/src/fixture.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { VitestRunner } from './types'
22
import type { FixtureOptions, TestContext } from './types/tasks'
33
import { createDefer, isObject } from '@vitest/utils'
4+
import { stripLiteral } from 'strip-literal'
45
import { getFileContext } from './context'
56
import { getTestFixture } from './map'
67

@@ -338,9 +339,9 @@ function resolveDeps(
338339
}
339340

340341
function getUsedProps(fn: Function) {
341-
let fnString = fn.toString()
342+
let fnString = stripLiteral(fn.toString())
342343
// match lowered async function and strip it off
343-
// example code on esbuild-try https://esbuild.github.io/try/#YgAwLjI0LjAALS1zdXBwb3J0ZWQ6YXN5bmMtYXdhaXQ9ZmFsc2UAZQBlbnRyeS50cwBjb25zdCBvID0gewogIGYxOiBhc3luYyAoKSA9PiB7fSwKICBmMjogYXN5bmMgKGEpID0+IHt9LAogIGYzOiBhc3luYyAoYSwgYikgPT4ge30sCiAgZjQ6IGFzeW5jIGZ1bmN0aW9uKGEpIHt9LAogIGY1OiBhc3luYyBmdW5jdGlvbiBmZihhKSB7fSwKICBhc3luYyBmNihhKSB7fSwKCiAgZzE6IGFzeW5jICgpID0+IHt9LAogIGcyOiBhc3luYyAoeyBhIH0pID0+IHt9LAogIGczOiBhc3luYyAoeyBhIH0sIGIpID0+IHt9LAogIGc0OiBhc3luYyBmdW5jdGlvbiAoeyBhIH0pIHt9LAogIGc1OiBhc3luYyBmdW5jdGlvbiBnZyh7IGEgfSkge30sCiAgYXN5bmMgZzYoeyBhIH0pIHt9Cn0
344+
// example code on esbuild-try https://esbuild.github.io/try/#YgAwLjI0LjAALS1zdXBwb3J0ZWQ6YXN5bmMtYXdhaXQ9ZmFsc2UAZQBlbnRyeS50cwBjb25zdCBvID0gewogIGYxOiBhc3luYyAoKSA9PiB7fSwKICBmMjogYXN5bmMgKGEpID0+IHt9LAogIGYzOiBhc3luYyAoYSwgYikgPT4ge30sCiAgZjQ6IGFzeW5jIGZ1bmN0aW9uKGEpIHt9LAogIGY1OiBhc3luYyBmdW5jdGlvbiBmZihhKSB7fSwKICBhc3luYyBmNihhKSB7fSwKCiAgZzE6IGFzeW5jICgpID0+IHt9LAogIGcyOiBhc3luYyAoeyBhIH0pID0+IHt9LAogIGczOiBhc3luYyAoeyBhIH0sIGIpID0+IHt9LAogIGc0OiBhc3luYyBmdW5jdGlvbiAoeyBhIH0pIHt9LAogIGc1OiBhc3luYyBmdW5jdGlvbiBnZyh7IGEgfSkge30sCiAgYXN5bmMgZzYoeyBhIH0pIHt9LAoKICBoMTogYXN5bmMgKCkgPT4ge30sCiAgLy8gY29tbWVudCBiZXR3ZWVuCiAgaDI6IGFzeW5jIChhKSA9PiB7fSwKfQ
344345
// __async(this, null, function*
345346
// __async(this, arguments, function*
346347
// __async(this, [_0, _1], function*

packages/vitest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"mime": "^4.0.7",
202202
"pretty-format": "^29.7.0",
203203
"prompts": "^2.4.2",
204-
"strip-literal": "^3.0.0",
204+
"strip-literal": "catalog:",
205205
"ws": "catalog:"
206206
}
207207
}

pnpm-lock.yaml

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ catalog:
3737
pathe: ^2.0.3
3838
sirv: ^3.0.1
3939
std-env: ^3.9.0
40+
strip-literal: ^3.0.0
4041
test-exclude: ^7.0.1
4142
tinyglobby: ^0.2.14
4243
tinyrainbow: ^2.0.0
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* eslint-disable style/spaced-comment */
2+
import { test as base, expect } from 'vitest'
3+
4+
const test = base.extend<{
5+
one: 1
6+
two: 2
7+
}>({
8+
one: 1,
9+
two: 2,
10+
})
11+
12+
test('no comments', ({ one, two }) => {
13+
expect(one).toBe(1)
14+
expect(two).toBe(2)
15+
})
16+
17+
test('inline comment', ({
18+
one,
19+
// comment
20+
two,
21+
}) => {
22+
expect(one).toBe(1)
23+
expect(two).toBe(2)
24+
})
25+
26+
test('multiline comment', ({
27+
one,
28+
/**
29+
* comment
30+
*/
31+
two,
32+
}) => {
33+
expect(one).toBe(1)
34+
expect(two).toBe(2)
35+
})
36+
37+
test('inline legal comment', ({
38+
one,
39+
//! comment
40+
two,
41+
}) => {
42+
expect(one).toBe(1)
43+
expect(two).toBe(2)
44+
})
45+
46+
test('multiline legal comment', ({
47+
one,
48+
/*! comment */
49+
two,
50+
}) => {
51+
expect(one).toBe(1)
52+
expect(two).toBe(2)
53+
})

0 commit comments

Comments
 (0)