diff --git a/packages/browser/src/node/plugin.ts b/packages/browser/src/node/plugin.ts index 0200de4fa..387fc4b38 100644 --- a/packages/browser/src/node/plugin.ts +++ b/packages/browser/src/node/plugin.ts @@ -241,6 +241,7 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => { 'vitest > @vitest/snapshot > magic-string', 'vitest > chai', 'vitest > chai > loupe', + 'vitest > strip-literal', 'vitest > @vitest/utils > loupe', '@vitest/browser > @testing-library/user-event', '@vitest/browser > @testing-library/dom', diff --git a/packages/runner/package.json b/packages/runner/package.json index 159dab761..08ec6cd33 100644 --- a/packages/runner/package.json +++ b/packages/runner/package.json @@ -43,6 +43,7 @@ }, "dependencies": { "@vitest/utils": "workspace:*", - "pathe": "catalog:" + "pathe": "catalog:", + "strip-literal": "catalog:" } } diff --git a/packages/runner/src/fixture.ts b/packages/runner/src/fixture.ts index 4a0130b2c..e5334ebbf 100644 --- a/packages/runner/src/fixture.ts +++ b/packages/runner/src/fixture.ts @@ -1,6 +1,7 @@ import type { VitestRunner } from './types' import type { FixtureOptions, TestContext } from './types/tasks' import { createDefer, isObject } from '@vitest/utils' +import { stripLiteral } from 'strip-literal' import { getFileContext } from './context' import { getTestFixture } from './map' @@ -338,9 +339,9 @@ function resolveDeps( } function getUsedProps(fn: Function) { - let fnString = fn.toString() + let fnString = stripLiteral(fn.toString()) // match lowered async function and strip it off - // example code on esbuild-try https://esbuild.github.io/try/#YgAwLjI0LjAALS1zdXBwb3J0ZWQ6YXN5bmMtYXdhaXQ9ZmFsc2UAZQBlbnRyeS50cwBjb25zdCBvID0gewogIGYxOiBhc3luYyAoKSA9PiB7fSwKICBmMjogYXN5bmMgKGEpID0+IHt9LAogIGYzOiBhc3luYyAoYSwgYikgPT4ge30sCiAgZjQ6IGFzeW5jIGZ1bmN0aW9uKGEpIHt9LAogIGY1OiBhc3luYyBmdW5jdGlvbiBmZihhKSB7fSwKICBhc3luYyBmNihhKSB7fSwKCiAgZzE6IGFzeW5jICgpID0+IHt9LAogIGcyOiBhc3luYyAoeyBhIH0pID0+IHt9LAogIGczOiBhc3luYyAoeyBhIH0sIGIpID0+IHt9LAogIGc0OiBhc3luYyBmdW5jdGlvbiAoeyBhIH0pIHt9LAogIGc1OiBhc3luYyBmdW5jdGlvbiBnZyh7IGEgfSkge30sCiAgYXN5bmMgZzYoeyBhIH0pIHt9Cn0 + // example code on esbuild-try https://esbuild.github.io/try/#YgAwLjI0LjAALS1zdXBwb3J0ZWQ6YXN5bmMtYXdhaXQ9ZmFsc2UAZQBlbnRyeS50cwBjb25zdCBvID0gewogIGYxOiBhc3luYyAoKSA9PiB7fSwKICBmMjogYXN5bmMgKGEpID0+IHt9LAogIGYzOiBhc3luYyAoYSwgYikgPT4ge30sCiAgZjQ6IGFzeW5jIGZ1bmN0aW9uKGEpIHt9LAogIGY1OiBhc3luYyBmdW5jdGlvbiBmZihhKSB7fSwKICBhc3luYyBmNihhKSB7fSwKCiAgZzE6IGFzeW5jICgpID0+IHt9LAogIGcyOiBhc3luYyAoeyBhIH0pID0+IHt9LAogIGczOiBhc3luYyAoeyBhIH0sIGIpID0+IHt9LAogIGc0OiBhc3luYyBmdW5jdGlvbiAoeyBhIH0pIHt9LAogIGc1OiBhc3luYyBmdW5jdGlvbiBnZyh7IGEgfSkge30sCiAgYXN5bmMgZzYoeyBhIH0pIHt9LAoKICBoMTogYXN5bmMgKCkgPT4ge30sCiAgLy8gY29tbWVudCBiZXR3ZWVuCiAgaDI6IGFzeW5jIChhKSA9PiB7fSwKfQ // __async(this, null, function* // __async(this, arguments, function* // __async(this, [_0, _1], function* diff --git a/packages/vitest/package.json b/packages/vitest/package.json index 1266b8b0e..4a1ac11e8 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -201,7 +201,7 @@ "mime": "^4.0.7", "pretty-format": "^29.7.0", "prompts": "^2.4.2", - "strip-literal": "^3.0.0", + "strip-literal": "catalog:", "ws": "catalog:" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2f9a7bc36..4291a3156 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -102,6 +102,9 @@ catalogs: std-env: specifier: ^3.9.0 version: 3.9.0 + strip-literal: + specifier: ^3.0.0 + version: 3.0.0 test-exclude: specifier: ^7.0.1 version: 7.0.1 @@ -738,6 +741,9 @@ importers: pathe: specifier: 'catalog:' version: 2.0.3 + strip-literal: + specifier: 'catalog:' + version: 3.0.0 packages/snapshot: dependencies: @@ -1101,7 +1107,7 @@ importers: specifier: ^2.4.2 version: 2.4.2 strip-literal: - specifier: ^3.0.0 + specifier: 'catalog:' version: 3.0.0 ws: specifier: 'catalog:' diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 5b7067588..9293f6bb2 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -37,6 +37,7 @@ catalog: pathe: ^2.0.3 sirv: ^3.0.1 std-env: ^3.9.0 + strip-literal: ^3.0.0 test-exclude: ^7.0.1 tinyglobby: ^0.2.14 tinyrainbow: ^2.0.0 diff --git a/test/core/test/fixture-comments-between-destructure.test.ts b/test/core/test/fixture-comments-between-destructure.test.ts new file mode 100644 index 000000000..541fa4fa6 --- /dev/null +++ b/test/core/test/fixture-comments-between-destructure.test.ts @@ -0,0 +1,53 @@ +/* eslint-disable style/spaced-comment */ +import { test as base, expect } from 'vitest' + +const test = base.extend<{ + one: 1 + two: 2 +}>({ + one: 1, + two: 2, +}) + +test('no comments', ({ one, two }) => { + expect(one).toBe(1) + expect(two).toBe(2) +}) + +test('inline comment', ({ + one, + // comment + two, +}) => { + expect(one).toBe(1) + expect(two).toBe(2) +}) + +test('multiline comment', ({ + one, + /** + * comment + */ + two, +}) => { + expect(one).toBe(1) + expect(two).toBe(2) +}) + +test('inline legal comment', ({ + one, + //! comment + two, +}) => { + expect(one).toBe(1) + expect(two).toBe(2) +}) + +test('multiline legal comment', ({ + one, + /*! comment */ + two, +}) => { + expect(one).toBe(1) + expect(two).toBe(2) +})