Skip to content

Conversation

@Enchan1207
Copy link
Contributor

@Enchan1207 Enchan1207 commented Jun 3, 2025

Summary

add custom serializer for RegExp object.

Problem

vitest can filter test suites that contain non-ascii chars in its name.

test("test suite that contains 日本語", ()=>{
  expect(1).toBe(1)
})
npx vitest -t '日本語' # test suites can be filtered by non-ascii strings

but with vitest-pool-workers, errors are reported:

TypeError: Cannot convert argument to a ByteString because the character at index 1404 has a value of 21336 which is greater than 255.
 ❯ webidl.converters.ByteString ../node_modules/undici/lib/fetch/webidl.js:431:13
 ❯ Object.record<ByteString, ByteString> ../node_modules/undici/lib/fetch/webidl.js:281:28
 ❯ webidl.converters.HeadersInit ../node_modules/undici/lib/fetch/headers.js:579:63
 ❯ Object.RequestInit ../node_modules/undici/lib/fetch/webidl.js:370:17
 ❯ new Request ../node_modules/undici/lib/fetch/request.js:54:30
 ❯ new _Request ../node_modules/@cloudflare/vitest-pool-workers/node_modules/miniflare/dist/src/index.js:1879:5
 ❯ #fetcherFetchCall ../node_modules/@cloudflare/vitest-pool-workers/node_modules/miniflare/dist/src/index.js:12025:21
 ❯ #call ../node_modules/@cloudflare/vitest-pool-workers/node_modules/miniflare/dist/src/index.js:11943:71
 ❯ Proxy.fetch ../node_modules/@cloudflare/vitest-pool-workers/node_modules/miniflare/dist/src/index.js:11933:34
 ❯ runTests ../node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:1517:26

Cause

it caused by serialization process of devalue.

when option -t (--testNamePattern to be exact) was specified, test pattern strings will be passed as RegExp object (to metadata).

metadatas for tests are passed as request header MF-Vitest-Worker-Data, but devalue operates RegExp object as set of pattern and flags without any encoding.

therefore, when non-ascii chars are included in testNamePattern, it will be passed to request header directly.
request header cannot contain any non-ascii chars, so the problems will be caused.

Solution

added custom reducer/revivers of devalue that encode/decode source strings of RegExp object as base64.


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • Wrangler / Vite E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because: vitest is not covered by the e2e tests
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: it is maybe internal fix
  • Wrangler V3 Backport
    • TODO (before merge)
    • Wrangler PR:
    • Not necessary because: not a Wrangler change

@Enchan1207 Enchan1207 requested a review from a team as a code owner June 3, 2025 14:12
@changeset-bot
Copy link

changeset-bot bot commented Jun 3, 2025

🦋 Changeset detected

Latest commit: 2892b99

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/vitest-pool-workers Patch

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

Copy link

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

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

Looks good to me 🤙

@github-actions
Copy link
Contributor

github-actions bot commented Jun 4, 2025

A Wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-wrangler-9454
Prereleases for other packages:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-cloudflare-workers-bindings-extension-9454 -O ./cloudflare-workers-bindings-extension.0.0.0-vdfd83e32e.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-vdfd83e32e.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-create-cloudflare-9454 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-cloudflare-kv-asset-handler-9454

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-miniflare-9454

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-cloudflare-pages-shared-9454

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-cloudflare-unenv-preset-9454

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-cloudflare-vite-plugin-9454

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-cloudflare-vitest-pool-workers-9454

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-cloudflare-workers-editor-shared-9454

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-cloudflare-workers-shared-9454

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/15445882788/npm-package-cloudflare-workflows-shared-9454

Note that these links will no longer work once the GitHub Actions artifact expires.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Really nice PR - thanks

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Jun 4, 2025
@petebacondarwin
Copy link
Contributor

The CI/TEsts (macOS) job is failing on main so not related to this PR. Once that is fixed we should rebase.

@Enchan1207
Copy link
Contributor Author

@petebacondarwin

Thank you for approval!
CI problems seem to be resolved by other PR. Should I rebase this?

@petebacondarwin petebacondarwin force-pushed the enchan1207/encode-regexp-at-serialize branch from 50c5a85 to 2892b99 Compare June 4, 2025 15:08
@petebacondarwin petebacondarwin added this pull request to the merge queue Jun 4, 2025
Merged via the queue into cloudflare:main with commit 9c30aec Jun 4, 2025
15 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Jun 4, 2025
@workers-devprod workers-devprod added the contribution [Holopin] Recognizes an open-source contribution, big or small label Jun 4, 2025
@holopin-bot
Copy link

holopin-bot bot commented Jun 4, 2025

Congratulations @Enchan1207, the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cmbi49hp8485607jrvkbrbuou

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

@petebacondarwin
Copy link
Contributor

Sorry this should have been backported to v3

dario-piotrowicz pushed a commit that referenced this pull request Sep 26, 2025
* feat: encode pattern when serialize RegExp object

* test: check if test suites can be filtered by pattern includes non-ascii string

* chore: remove unneeded comment

* test: serialize RegExp object

* docs: add changeset for vitest-pool-workers to describe fix
dario-piotrowicz pushed a commit that referenced this pull request Sep 26, 2025
* feat: encode pattern when serialize RegExp object

* test: check if test suites can be filtered by pattern includes non-ascii string

* chore: remove unneeded comment

* test: serialize RegExp object

* docs: add changeset for vitest-pool-workers to describe fix
petebacondarwin pushed a commit that referenced this pull request Sep 29, 2025
* fix(miniflare): api proxy preserve multiple Set-Cookie headers

* [miniflare] custom serialization for RegExp object (#9454)

* feat: encode pattern when serialize RegExp object

* test: check if test suites can be filtered by pattern includes non-ascii string

* chore: remove unneeded comment

* test: serialize RegExp object

* docs: add changeset for vitest-pool-workers to describe fix

---------

Co-authored-by: Calvin Tsang <yuripave@gmail.com>
Co-authored-by: Enchan <enchant0130@gmail.com>
Co-authored-by: Victor Berchet <victor@suumit.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution [Holopin] Recognizes an open-source contribution, big or small

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants