cloudflare / cloudflare/actors
Unable to use with vitest in integration tests
- Dominant language
- TypeScript
- Stars
- 422
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When I use this library in integration tests with vitest and the cloudflare vitest plugin, I'm getting a lot of resolve errors.
With the config below I'm getting
```
Error: Cannot find module '/Users/me/my-repo/node_modules/.pnpm/@cloudflare+actors@0.0.1-beta.3/node_modules/@cloudflare/actors/dist/storage/src/index' imported from /Users/me/my-repo/node_modules/.pnpm/@cloudflare+actors@0.0.1-beta.3/node_modules/@cloudflare/actors/dist/core/src/index.js
```
**To Reproduce**
1. Write an integration test in a project that uses `@cloudflare/actors`
2. Setup vitest as per the config below
3. There will be errors about modules not found
**Expected behavior**
Vitest can resolve internal packages in the `@cloudflare/actors` package
**Information (please complete the following information):**
- Typescript: 5.9.2
- Node.js: 23.11.0
- Wrangler: 4.28.1
- Actor Version: 0.0.1-beta.3
**Additional context**
I can see that the library is built with `tsc`. While it works at the bare minimum there are problems with not having the extension in the output since Tyepscript bundler doesn't deal with that or paths.
But also there are problems with exports not declared in `package.json` for the internal packages as it's required in es modules. This is another issue when I tried to write resolvers in the vitest file.
I wonder if using something like [tsdown](https://tsdown.dev) would help.
This is my vitest config:
```ts
import { resolve as pathResolve } from "node:path";
import { fileURLToPath } from "node:url";
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineWorkersConfig({
plugins: [tsconfigPaths({ projects: ["tsconfig.test.json"] })],
resolve: {
alias: {
"~": pathResolve(fileURLToPath(new URL("./src", import.meta.url))),
},
},
test: {
clearMocks: true,
coverage: { provider: "istanbul" as const },
globals: false,
mockReset: true,
projects: [
{
extends: true,
test: {
name: "unit",
include: ["./src/**/*.spec.ts"],
setupFiles: ["./src/mocks/cloudflare.actors.ts"],
pool: "threads",
},
},
{
extends: true,
test: {
name: "e2e-workers",
include: ["./tests/**/*.spec.ts"],
pool: "tests/worker.ts",
deps: { inline: [/^@cloudflare\/actors(\/.*)?$/] },
poolOptions: {
workers: {
wrangler: { configPath: "./tests/wrangler.jsonc" },
compatibilityDate: "2022-10-31",
compatibilityFlags: ["export_commonjs_default"],
},
},
},
},
],
},
});
```
Contributor guide
Assessment
This issue has not been assessed yet.