You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can find an example in the [Recipes](/workers/testing/vitest-integration/recipes) page.
63
+
You can find an example in the [Recipes](/workers/testing/vitest-integration/recipes) page.
64
+
65
+
### Importing modules from global setup file
66
+
67
+
Although Vitest is set up to resolve packages for the `workerd` runtime, it runs your global setup file in the Node.js environment. This can cause issues when importing packages like [Postgres.js](https://github.com/cloudflare/workers-sdk/issues/6465), which exports a non-Node version for `workerd`.
68
+
To work around this, you can create a wrapper that uses Vite's SSR module loader to import the global setup file under the correct conditions. Then, adjust your Vitest configuration to point to this wrapper. For example:
69
+
70
+
```ts
71
+
// File: global-setup-wrapper.ts
72
+
import { createServer } from"vite"
73
+
74
+
// Import the actual global setup file with the correct setup
75
+
const mod =awaitviteImport("./global-setup.ts")
76
+
77
+
exportdefaultmod.default;
78
+
79
+
// Helper to import the file with default node setup
0 commit comments