Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-numbers-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/vitest-pool-workers": patch
---

fix: loosen the peer dependency version on vitest to support versions ranging from 1.3.0 to 1.5.0
2 changes: 1 addition & 1 deletion fixtures/vitest-pool-workers-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"miniflare": "workspace:*",
"toucan-js": "^3.3.1",
"typescript": "^5.3.3",
"vitest": "1.3.0",
"vitest": "1.5.0",
"wrangler": "workspace:*"
}
}
8 changes: 5 additions & 3 deletions packages/vitest-pool-workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20240419.0",
"@types/node": "20.8.3",
"@types/semver": "^7.5.1",
"capnp-ts": "^0.7.0",
"capnpc-ts": "^0.7.0",
"undici": "5.28.3"
Expand All @@ -66,13 +67,14 @@
"devalue": "^4.3.0",
"esbuild": "0.17.19",
"miniflare": "workspace:*",
"semver": "^7.5.1",
"wrangler": "workspace:*",
"zod": "^3.20.6"
},
"peerDependencies": {
"@vitest/runner": "1.3.0",
"@vitest/snapshot": "1.3.0",
"vitest": "1.3.0"
"@vitest/runner": "1.3.x - 1.5.x",
"@vitest/snapshot": "1.3.x - 1.5.x",
"vitest": "1.3.x - 1.5.x"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL - hyphenated ranges!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same! >=1.3.0 || <= 1.5.x didn't work as I expected, because 1.2.0 satisfied this, as it's < 1.5.x, but hyphenated worked great!

},
"workers-sdk": {
"prerelease": true
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest-pool-workers/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const configPlugin: PluginOption = {
ensureArrayIncludes(config.resolve.conditions, requiredConditions);

// Vitest sets this to an empty array if unset, so restore Vite defaults:
// https://github.com/vitest-dev/vitest/blob/v1.3.0/packages/vitest/src/node/plugins/index.ts#L77
// https://github.com/vitest-dev/vitest/blob/v1.5.0/packages/vitest/src/node/plugins/index.ts#L77
ensureArrayIncludes(config.resolve.mainFields, requiredMainFields);

// Apply `package.json` `browser` field remapping in SSR mode:
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest-pool-workers/src/pool/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export async function parseProjectOptions(
let workersPoolOptions = poolOptions?.workers ?? {};
try {
if (typeof workersPoolOptions === "function") {
// https://github.com/vitest-dev/vitest/blob/v1.0.0/packages/vitest/src/integrations/inject.ts
// https://github.com/vitest-dev/vitest/blob/v1.5.0/packages/vitest/src/integrations/inject.ts
const inject = <K extends keyof ProvidedContext>(
key: K
): ProvidedContext[K] => {
Expand Down
11 changes: 6 additions & 5 deletions packages/vitest-pool-workers/src/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
testRegExps,
WebSocket,
} from "miniflare";
import semverSatisfies from "semver/functions/satisfies.js";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a .js on the end of this module specifier?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure, but I assume it's just due to how semver is built and published in a very CJS fashion?

Without it, I got an error like this:

Error: Cannot find module 'E:\xxx\node_modules\semver\functions\satisfies' imported from E:\xxx\node_modules\@cloudflare\vitest-pool-workers\dist\pool\index.mjs
Did you mean to import semver/functions/satisfies.js?
 ❯ finalizeResolution node:internal/modules/esm/resolve:264:11
 ❯ moduleResolve node:internal/modules/esm/resolve:917:10
 ❯ defaultResolve node:internal/modules/esm/resolve:1130:11
 ❯ ModuleLoader.defaultResolve node:internal/modules/esm/loader:396:12
 ❯ ModuleLoader.resolve node:internal/modules/esm/loader:365:25
 ❯ ModuleLoader.getModuleJob node:internal/modules/esm/loader:240:38
 ❯ ModuleWrap.<anonymous> node:internal/modules/esm/module_job:85:39
 ❯ link node:internal/modules/esm/module_job:84:36

And when swapping over to semver/functions/satisfies.js everything was happy, so I didn't dig any further.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option would be to just import semver from 'semver' and then using semver.satisfies, if that's preferred. Let me know.

import { createMethodsRPC } from "vitest/node";
import { createChunkingSocket } from "../shared/chunking-socket";
import { OPTIONS_PATH, parseProjectOptions } from "./config";
Expand Down Expand Up @@ -56,7 +57,7 @@ import type {
} from "vitest";
import type { ProcessPool, Vitest, WorkspaceProject } from "vitest/node";

// https://github.com/vitest-dev/vitest/blob/v1.3.0/packages/vite-node/src/client.ts#L386
// https://github.com/vitest-dev/vitest/blob/v1.5.0/packages/vite-node/src/client.ts#L386
declare const __vite_ssr_import__: unknown;
assert(
typeof __vite_ssr_import__ === "undefined",
Expand Down Expand Up @@ -775,13 +776,13 @@ function assertCompatibleVitestVersion(ctx: Vitest) {
"Expected to find `vitest`'s version"
);

if (expectedVitestVersion !== actualVitestVersion) {
if (!semverSatisfies(actualVitestVersion, expectedVitestVersion)) {
const message = [
`You're running \`vitest@${actualVitestVersion}\`, but this version of \`@cloudflare/vitest-pool-workers\` only supports \`vitest@${expectedVitestVersion}\`.`,
`You're running \`vitest@${actualVitestVersion}\`, but this version of \`@cloudflare/vitest-pool-workers\` only officially supports \`vitest ${expectedVitestVersion}\`.`,
"`@cloudflare/vitest-pool-workers` currently depends on internal Vitest APIs that are not protected by semantic-versioning guarantees.",
`Please install \`vitest@${expectedVitestVersion}\` to continue using \`@cloudflare/vitest-pool-workers\`.`,
`Your tests may work without issue, but we can not guarantee compatibility outside of the above version range.`,
].join("\n");
throw new Error(message);
log.warn(message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ export default class WorkersTestRunner extends VitestTestRunner {
// contain storage calls (e.g. caching responses) that could try to access
// aborted Durable Objects.
await waitForGlobalWaitUntil();
// @ts-expect-error `VitestTestRunner` doesn't define `onAfterRunFiles`, but
// could in the future.
return super.onAfterRunFiles?.();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest-pool-workers/vitest.workers.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfig({
server: {
deps: {
// Vitest automatically adds `/^(?!.*(?:node_modules)).*\.mjs$/` as an
// `inline` RegExp: https://github.com/vitest-dev/vitest/blob/v1.3.0/packages/vitest/src/node/config.ts#L204
// `inline` RegExp: https://github.com/vitest-dev/vitest/blob/v1.5.0/packages/vitest/src/node/config.ts#L236
// We'd like `packages/vitest-pool-workers/dist/pool/index.mjs` to be
// externalised though. Unfortunately, `inline`s are checked before
// `external`s, so there's no nice way we can override this. Instead,
Expand Down
93 changes: 52 additions & 41 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.