-
Notifications
You must be signed in to change notification settings - Fork 1.1k
support ctx.exports in vitest-pool-workers
#11533
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
Conversation
🦋 Changeset detectedLatest commit: 0dc5ba5 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 |
b6b4f85 to
a09f165
Compare
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
3aba7ce to
11eaa14
Compare
ctx.exports in vitest-pool-workers
11eaa14 to
8d0c798
Compare
| ): exports is Cloudflare.Exports { | ||
| return ( | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| (globalThis as any).Cloudflare?.compatibilityFlags.enable_ctx_exports && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not in workers-types? Should we add it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently it is "internal"? It's not in our docs.
The only place I could find it being used was in the unenv preset code.
| @@ -1,4 +1,5 @@ | |||
| import assert from "node:assert"; | |||
| import { exports } from "cloudflare:workers"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used on line 64 to add the exports onto the user generated ctx object.
cd1c745 to
b115efe
Compare
jamesopstad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, @petebacondarwin! Great that you've managed to apply these changes so cleanly.
… will never teardown and always times out
…OBJECT__` in order to reduce chance of collision with user code. This is the approach used in the Vite plugin and reduces the complexity of our code since we can stop "prefixing" user exports.
b115efe to
0dc5ba5
Compare
It is now possible to access
ctx.exportsproperties for themain(SELF) worker.Due to the dynamic nature of Vitest the integration relies upon guessing what the exports of the
mainWorker are by statically analyzing the Worker source using esbuild. In cases where it is not possible to infer the exports (for example, a wildcard re-export of a virtual module) it is possible to declare these in the vitest-pool-workers config via theadditionalExportssetting.A picture of a cute animal (not mandatory, but encouraged)