-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support Vitest 4 in @cloudflare/vitest-pool-workers
#11632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
f649413
Support Vitest v4
penalosa 3afc4f6
fix build
penalosa 964012e
fix build
penalosa e1f2a8b
fix build
penalosa cfc5f70
fix snapshot
penalosa 704466b
fix fixture tests
penalosa 99a88c9
env & exports
penalosa 3e60beb
better module runner
penalosa 9dec2c5
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 3037a20
fix tests after merge
penalosa c6af16d
green
penalosa 64982d4
run with vitest3
penalosa c4ec1a8
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa adc5e54
address some comments
penalosa 1149696
fix tests
penalosa 1625d85
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa e80bd62
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 9f80b75
lockfile
penalosa d317d15
Merge branch 'main' into penalosa/vitest-v4-support
penalosa 20eb0a6
fix snapshot
penalosa 2f511be
lock down versions
penalosa 7143d5d
fix?
penalosa de5f57f
Add nunjucks to module-resolution fixture
penalosa 7870094
Add comment re hardcoded event names
penalosa 3f6fef8
delete temp dirs
penalosa 131244a
address more comments
penalosa 1c67bfe
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 858ed07
fix tests after merge
penalosa 79a1932
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa d46a09b
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 1f1072a
[vitest-pool-workers] Fix vitest 4.1.0-beta.4 compatibility
penalosa a925f45
[vitest-pool-workers] Fix Windows CI failures
penalosa 36bdd7b
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 522b117
[vitest-pool-workers] Fix lint errors and dep validation
penalosa 6fdaa56
[create-cloudflare] Fix vite type conflict with vitest 3
penalosa 177e94c
[vitest-pool-workers] Add @types/node to fixture tsconfig
penalosa 2e76e3c
[miniflare] Normalize persist paths to forward slashes for Windows
penalosa a63af5a
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa ccaf85f
[edge-preview-authenticated-proxy] Migrate to vitest-pool-workers v4 API
penalosa ebb56c4
[vitest-pool-workers] Exclude SQLite DO fixture on Windows (workerd bug)
penalosa b5561cf
[vitest-pool-workers] Make runner DO ephemeral
penalosa 5764732
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 6324643
[vitest-pool-workers] Revert ephemeral runner DO
penalosa 8791f8b
[vitest-pool-workers] Use in-memory DO storage on Windows
penalosa 4bb7043
[vitest-pool-workers] Revert in-memory DOs, re-add Windows exclusion
penalosa a8a1a8c
[vitest-pool-workers] Make runner DO ephemeral to avoid Windows SQLit…
penalosa 8ca9dad
Update packages/wrangler/src/codemod.ts
penalosa d3ef674
[vitest-pool-workers] Fix review findings: bugs, error handling, and …
penalosa c4e2a7c
[vitest-pool-workers] Update Vitest source links to v4.0.18
penalosa ef2ba23
[vitest-pool-workers] Fix review findings: bugs, tests, and nits
penalosa ac94357
[vitest-pool-workers] Fix leaked FSWatcher handles in Pages ASSETS bi…
penalosa 989f559
[vitest-pool-workers] Add regression tests for bare specifier resolut…
penalosa 8003a66
[vitest-pool-workers] Fix review findings in Pages watcher cleanup
penalosa fe26fd9
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 31a64e5
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 3c40844
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 017ad0c
Fix lockfile after merge
penalosa 755f295
[vitest-pool-workers] Remove redundant polyfills, use workerd compat …
penalosa 6cce159
[edge-preview-authenticated-proxy] Use return await for async sub-han…
penalosa 9f15f7b
Address review comments: codemod as jscodeshift transform, fixture up…
penalosa a277e2c
Add unpkg URL option for running the codemod
penalosa bd3472f
Remove stale todo file
penalosa 343ffb9
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 2eeb830
Update fixtures/get-platform-proxy/tests/get-platform-proxy.env.test.ts
penalosa 6de6838
fix check
penalosa 9a224e4
fix: resolve CI failures from NodeJS namespace and stale snapshot
penalosa 04f0bf5
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa 55a5510
Fix CI: codemods type mismatch and format-errors mock for vitest v4
penalosa 4b70c1e
Add config API migration example to changeset
penalosa c7e06d1
Support withEnv() in entrypoint wrappers, fix workers-assets fixture …
penalosa 1d0e89f
Merge remote-tracking branch 'origin/main' into penalosa/vitest-v4-su…
penalosa ab488a8
Remove stale singleWorker option from tests, expand compat flag comment
penalosa 92707da
Fix workers-assets withEnv test: use worker.fetch with withEnv
penalosa 405a192
Merge branch 'main' into penalosa/vitest-v4-support
penalosa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| "@cloudflare/vitest-pool-workers": minor | ||
| --- | ||
|
|
||
| Support Vitest 4 in `@cloudflare/vitest-pool-workers`. | ||
|
|
||
| This a breaking change to the `@cloudflare/vitest-pool-workers` integration in order to support Vitest v4. Along with supporting Vitest v4 (and dropping support for Vitest v2 and v3), we've made a number of changes that may require changes to your tests. Our aim has been to improve stability & the foundations of `@cloudflare/vitest-pool-workers` as we move towards a v1 release of the package. | ||
|
|
||
| We've made a codemod to make the migration easier, which will make the required changes to your config file: | ||
|
|
||
| ```sh | ||
| npx jscodeshift -t node_modules/@cloudflare/vitest-pool-workers/dist/codemods/vitest-v3-to-v4.mjs vitest.config.ts | ||
| ``` | ||
|
|
||
| Or, without installing the package first: | ||
|
|
||
| ```sh | ||
| npx jscodeshift -t https://unpkg.com/@cloudflare/vitest-pool-workers/dist/codemods/vitest-v3-to-v4.mjs --parser=ts vitest.config.ts | ||
| ``` | ||
|
|
||
| - **Config API:** `defineWorkersProject` and `defineWorkersConfig` from `@cloudflare/vitest-pool-workers/config` have been replaced with a `cloudflareTest()` Vite plugin exported from `@cloudflare/vitest-pool-workers`. The `test.poolOptions.workers` options are now passed directly to `cloudflareTest()`: | ||
|
|
||
| Before: | ||
|
|
||
| ```ts | ||
| import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config"; | ||
|
|
||
| export default defineWorkersProject({ | ||
| test: { | ||
| poolOptions: { | ||
| workers: { | ||
| wrangler: { configPath: "./wrangler.jsonc" }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| After: | ||
|
|
||
| ```ts | ||
| import { cloudflareTest } from "@cloudflare/vitest-pool-workers"; | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| cloudflareTest({ | ||
| wrangler: { configPath: "./wrangler.jsonc" }, | ||
| }), | ||
| ], | ||
| }); | ||
| ``` | ||
|
|
||
| - **`isolatedStorage` & `singleWorker`:** These have been removed in favour of a simpler isolation model that more closely matches Vitest. Storage isolation is now on a per test file basis, and you can make your test files share the same storage by using the Vitest flags `--max-workers=1 --no-isolate` | ||
| - **`import { env, SELF } from "cloudflare:test"`:** These have been removed in favour of `import { env, exports } from "cloudflare:workers"`. `exports.default.fetch()` has the same behaviour as `SELF.fetch()`, except that it doesn't expose Assets. To test your assets, write an integration test using [`startDevWorker()`](https://developers.cloudflare.com/workers/testing/unstable_startworker/) | ||
| - **`import { fetchMock } from "cloudflare:test"`:** This has been removed. Instead, [mock `globalThis.fetch`](https://github.com/cloudflare/workers-sdk/blob/main/fixtures/vitest-pool-workers-examples/request-mocking/test/imperative.test.ts) or use ecosystem libraries like [MSW (recommended)](https://mswjs.io/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
fixtures/vitest-pool-workers-examples/ai-vectorize/test/env.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| declare module "cloudflare:test" { | ||
| interface ProvidedEnv extends Env {} | ||
| declare namespace Cloudflare { | ||
| interface Env {} | ||
| } |
19 changes: 10 additions & 9 deletions
19
fixtures/vitest-pool-workers-examples/ai-vectorize/vitest.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config"; | ||
| import { cloudflareTest } from "@cloudflare/vitest-pool-workers"; | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| cloudflareTest({ | ||
| remoteBindings: false, | ||
| wrangler: { configPath: "./wrangler.jsonc" }, | ||
| }), | ||
| ], | ||
|
|
||
| export default defineWorkersProject({ | ||
| test: { | ||
| globalSetup: ["./global-setup.ts"], | ||
| poolOptions: { | ||
| workers: { | ||
| singleWorker: true, | ||
| remoteBindings: false, | ||
| wrangler: { configPath: "./wrangler.jsonc" }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
5 changes: 2 additions & 3 deletions
5
fixtures/vitest-pool-workers-examples/basics-integration-auxiliary/test/env.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| declare module "cloudflare:test" { | ||
| // Controls the type of `import("cloudflare:test").env` | ||
| interface ProvidedEnv { | ||
| declare namespace Cloudflare { | ||
| interface Env { | ||
| WORKER: Fetcher; | ||
| } | ||
| } |
75 changes: 38 additions & 37 deletions
75
fixtures/vitest-pool-workers-examples/basics-integration-auxiliary/vitest.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,43 @@ | ||
| import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config"; | ||
| import { cloudflareTest } from "@cloudflare/vitest-pool-workers"; | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineWorkersProject({ | ||
| test: { | ||
| globalSetup: ["./global-setup.ts"], | ||
| poolOptions: { | ||
| workers: { | ||
| singleWorker: true, | ||
| miniflare: { | ||
| // Configuration for the test runner Worker | ||
| compatibilityDate: "2024-01-01", | ||
| compatibilityFlags: [ | ||
| // This illustrates a Worker that in production only wants v1 of Node.js compatibility. | ||
| // The Vitest pool integration will need to remove this flag since the `MockAgent` requires v2. | ||
| "no_nodejs_compat_v2", | ||
| "nodejs_compat", | ||
| // Required to use `WORKER.scheduled()`. This is an experimental | ||
| // compatibility flag, and cannot be enabled in production. | ||
| "service_binding_extra_handlers", | ||
| ], | ||
| serviceBindings: { | ||
| WORKER: "worker-under-test", | ||
| }, | ||
|
|
||
| workers: [ | ||
| // Configuration for the "auxiliary" Worker under test. | ||
| // Unfortunately, auxiliary Workers cannot load their configuration | ||
| // from `wrangler.toml` files, and must be configured with Miniflare | ||
| // `WorkerOptions`. | ||
| { | ||
| name: "worker-under-test", | ||
| modules: true, | ||
| scriptPath: "./dist/index.js", // Built by `global-setup.ts` | ||
| compatibilityDate: "2024-01-01", | ||
| compatibilityFlags: ["nodejs_compat"], | ||
| }, | ||
| ], | ||
| export default defineConfig({ | ||
| plugins: [ | ||
| cloudflareTest({ | ||
| miniflare: { | ||
| // Configuration for the test runner Worker | ||
| compatibilityDate: "2024-01-01", | ||
| compatibilityFlags: [ | ||
| // This illustrates a Worker that in production only wants v1 of Node.js compatibility. | ||
| // The Vitest pool integration will need to remove this flag since the `MockAgent` requires v2. | ||
| "no_nodejs_compat_v2", | ||
| "nodejs_compat", | ||
| // Required to use `WORKER.scheduled()`. This is an experimental | ||
| // compatibility flag, and cannot be enabled in production. | ||
| "service_binding_extra_handlers", | ||
| ], | ||
| serviceBindings: { | ||
| WORKER: "worker-under-test", | ||
| }, | ||
|
|
||
| workers: [ | ||
| // Configuration for the "auxiliary" Worker under test. | ||
| // Unfortunately, auxiliary Workers cannot load their configuration | ||
| // from `wrangler.toml` files, and must be configured with Miniflare | ||
| // `WorkerOptions`. | ||
| { | ||
| name: "worker-under-test", | ||
| modules: true, | ||
| scriptPath: "./dist/index.js", // Built by `global-setup.ts` | ||
| compatibilityDate: "2024-01-01", | ||
| compatibilityFlags: ["nodejs_compat"], | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
|
|
||
| test: { | ||
| globalSetup: ["./global-setup.ts"], | ||
| }, | ||
| }); |
32 changes: 16 additions & 16 deletions
32
fixtures/vitest-pool-workers-examples/basics-unit-integration-self/vitest.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,19 @@ | ||
| import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config"; | ||
| import { cloudflareTest } from "@cloudflare/vitest-pool-workers"; | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineWorkersProject({ | ||
| test: { | ||
| poolOptions: { | ||
| workers: { | ||
| singleWorker: true, | ||
| miniflare: { | ||
| // Required to use `SELF.scheduled()`. This is an experimental | ||
| // compatibility flag, and cannot be enabled in production. | ||
| compatibilityFlags: ["service_binding_extra_handlers"], | ||
| }, | ||
| wrangler: { | ||
| configPath: "./wrangler.jsonc", | ||
| }, | ||
| export default defineConfig({ | ||
| plugins: [ | ||
| cloudflareTest({ | ||
| miniflare: { | ||
| // Required to use `SELF.scheduled()`. This is an experimental | ||
| // compatibility flag, and cannot be enabled in production. | ||
| compatibilityFlags: ["service_binding_extra_handlers"], | ||
| }, | ||
| }, | ||
| }, | ||
| wrangler: { | ||
| configPath: "./wrangler.jsonc", | ||
| }, | ||
| }), | ||
| ], | ||
|
|
||
| test: {}, | ||
| }); |
5 changes: 2 additions & 3 deletions
5
fixtures/vitest-pool-workers-examples/container-app/test/env.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| declare module "cloudflare:test" { | ||
| // Controls the type of `import("cloudflare:test").env` | ||
| interface ProvidedEnv extends Env { | ||
| declare namespace Cloudflare { | ||
| interface Env { | ||
| MY_CONTAINER: DurableObjectNamespace<MyContainer>; | ||
| } | ||
| } | ||
|
penalosa marked this conversation as resolved.
|
||
20 changes: 10 additions & 10 deletions
20
fixtures/vitest-pool-workers-examples/container-app/vitest.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config"; | ||
| import { cloudflareTest } from "@cloudflare/vitest-pool-workers"; | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineWorkersProject({ | ||
| test: { | ||
| poolOptions: { | ||
| workers: { | ||
| singleWorker: true, | ||
| wrangler: { configPath: "./wrangler.jsonc" }, | ||
| }, | ||
| }, | ||
| }, | ||
| export default defineConfig({ | ||
| plugins: [ | ||
| cloudflareTest({ | ||
| wrangler: { configPath: "./wrangler.jsonc" }, | ||
| }), | ||
| ], | ||
|
|
||
| test: {}, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
fixtures/vitest-pool-workers-examples/context-exports/test/auxiliary.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.