Skip to content

Conversation

@petebacondarwin
Copy link
Contributor

@petebacondarwin petebacondarwin commented Oct 21, 2025

Fixes #11028
Fixes #11029

Recent additions to native nodejs_compat modules (node:console and node:vm) broke the vitest-pool-workers as it relies upon specialized polyfills to ensure that the Vitest runner can operate. This broke because generally the vitest-pool-workers uses module fallback to provide the polyfill which no longer works when there is a native version available.

  • fixes by putting the polyfill into the bundle directly which overrides the built-in module.
  • adds a test that proves that nodejs_compat scenarios work
  • changes most vitest-pool-workers fixtures to always use the latest compat date (by adding a feature to vitest-pool-workers where the latest compat date is used if none is provided).

The aim of the last bullet is for us to get an early warning if any changes to the runtime that are flagged behind a compat date will cause breakages to testing.


@petebacondarwin petebacondarwin requested a review from a team as a code owner October 21, 2025 13:14
@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2025

🦋 Changeset detected

Latest commit: 134ddad

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 21, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@11047

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@11047

miniflare

npm i https://pkg.pr.new/miniflare@11047

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@11047

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@11047

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@11047

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@11047

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@11047

wrangler

npm i https://pkg.pr.new/wrangler@11047

commit: 134ddad

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

Do we really need a polyfill for node:url ?

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Oct 21, 2025
@petebacondarwin petebacondarwin force-pushed the pbd/vitest-pool-workers/infer-compat-date branch from eeaae54 to 522333d Compare October 22, 2025 09:26
@petebacondarwin
Copy link
Contributor Author

@vicb I did a pass through and removed all unnecessary polyfills (turning on native features as needed). PTAL.

* @param enableFlag The flag that enables the feature.
* @param disableFlag The flag that disables the feature.
*/
function ensureFlag(flags: string[], enableFlag: string, disableFlag: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed offline, using a Set could simplify the handling of the flags in this PR.

I find it hard to figure out what that means:

	ensureFlag(
		runnerWorker.compatibilityFlags,
		"enable_nodejs_tty_module",
		"disable_nodejs_tty_module"
	);

ensure what flag (enable vs disable) is what (used vs not used)?

Maybe a wrapper class could help, constructed with an array, using a Set internally, having ensureUsed(flag) and ensureNotUsed(flag) and a flags getter returning an array

Copy link
Contributor Author

@petebacondarwin petebacondarwin Oct 22, 2025

Choose a reason for hiding this comment

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

I reworked the helper to make its purpose more clear: ab1f757

@petebacondarwin petebacondarwin marked this pull request as draft October 22, 2025 14:09
@petebacondarwin petebacondarwin force-pushed the pbd/vitest-pool-workers/infer-compat-date branch from d49d7d6 to 134ddad Compare October 22, 2025 17:26
@petebacondarwin petebacondarwin marked this pull request as ready for review October 22, 2025 18:52
@petebacondarwin petebacondarwin merged commit 0ff1964 into main Oct 22, 2025
31 checks passed
@petebacondarwin petebacondarwin deleted the pbd/vitest-pool-workers/infer-compat-date branch October 22, 2025 18:54
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-v3-pr Skip validation of presence of a v3 backport PR

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Run vitest tests against the latest compat date vitest no longer works as of compat date 2025-09-21 when using nodejs_compat

3 participants