-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Description
Describe the bug
Unorthodox uses of vi.hoisted() cause invalid code to be generated during the vitest:mocks transform, for example:
const mock = (await $.track_reactivity_loss(vi.hoisted(() => import("vitest-mock-extended").then((m) => m.mock))))();
const toaster = vi.hoisted(() => mock());becomes
vi.hoisted(() => import("vitest-mock-extended").then((m) => m.mock))const toaster = vi.hoisted(() => mock());
const mock = (await __vi_import_0__.track_reactivity_loss())();The unorthodox code is initially just a normal
const mock = await vi.hoisted(() => import("vitest-mock-extended").then((m) => m.mock))
const toaster = vi.hoisted(() => mock<Toaster>())but top-level awaits are wrapped by Svelte in $.track_reactivity_loss in a previous transform.
Reproduction
Ensure Svelte is setup/configured for the project. Run a test file named whatever.svelte.test.ts containing:
import { vi } from "vitest";
const path = await vi.hoisted(() => import("node:path"));
const somePath = vi.hoisted(() => path.resolve("test"));Leads to error:
RollupError: Parse failure: Expected ';', '}' or <eof>
At file: /src/lib/util/some.test.ts:1:66
File: /src/lib/util/some.test.ts:1:66
1 | ...sted(() => import("/@id/__vite-browser-external:node:path"))const somePath = vi.hoisted(() => path.resolve("test")...
| ^
2 | /* clipboard-helper.svelte.test.ts generated by Svelte v5.46.1 */
3 |
System Info
System:
OS: Windows 11 10.0.26100
CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700KF
Memory: 8.53 GB / 31.86 GB
Binaries:
Node: 24.4.0 - C:\Users\Matei\AppData\Local\Temp\xfs-815d4b46\node.CMD
Yarn: 4.6.0 - C:\Users\Matei\AppData\Local\Temp\xfs-815d4b46\yarn.CMD
npm: 11.4.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 143.0.7499.170
Edge: Chromium (140.0.3485.66)
Firefox: 146.0.1 - C:\Program Files\Mozilla Firefox\firefox.exe
Internet Explorer: 11.0.26100.7309
npmPackages:
@vitest/coverage-v8: 4.0.16 => 4.0.16
@vitest/ui: 4.0.16 => 4.0.16
vite: 7.3.1 => 7.3.1
vitest: 4.0.16 => 4.0.16
vitest-mock-extended: ^3.1.0 => 3.1.0Used Package Manager
yarn
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable