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
+
While Vitest is instructed to resolve packages for the `workerd` runtime, it runs your global setup file in the NodeJS environment. This is why you might encounter issue importing pacakges like [Postgres.js](https://github.com/cloudflare/workers-sdk/issues/6465) that export non-node version for `workerd`. To get around this issue, you can create a wrapper that uses Vite's SSR module loader to import your global setup file under the correct conditions. Then, adjust your Vitest configuration to point to this wrapper. For example:
68
+
69
+
```ts
70
+
// File: global-setup-wrapper.ts
71
+
import { createServer } from"vite"
72
+
73
+
// Import the actual global setup file with the correct setup
74
+
const mod =awaitviteImport("./global-setup.ts")
75
+
76
+
exportdefaultmod.default;
77
+
78
+
// Helper to import the file with default node setup
0 commit comments