-
Notifications
You must be signed in to change notification settings - Fork 772
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
add workers assets to vitest integration #6835
Conversation
🦋 Changeset detectedLatest commit: 85c34dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
f55cb0d
to
f12d63b
Compare
if ("name" in service) { | ||
if (service.name === kCurrentWorker) { | ||
// self binding e.g. for Vitest | ||
serviceName = getUserServiceName(refererName); |
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.
This case should also cover the router worker switch
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.
Might've misunderstood something, but this branch is for RPC entrypoints right, which shouldn't get assets...? To reflect prod behaviour.
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.
Oh fair point, I had thought that you could define things as { name: "service-name" }
with entrypoint being optional—didn't realise this was just for RPC
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.
Turns out fetch on an RPC entrypoint can get assets ¯\_(ツ)_/¯
doesn't work in miniflare yet, so leave it for now with a todo 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.
I think what you mean is that a fetch()
handler on a WorkerEntryPoint
type entry point (whether it is the default or a named entry-point) will check assets first (i.e. go via the Router Worker).
But actual RPC invocations (not to fetch()
) such as await env.WORKER.foo()
will not check assets first and will go directly to the User Worker.
Right?
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.
Also other non-fetch()
handlers such as scheduled
and queue
will not go via Router Worker
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.
Yes sorry that was imprecise - I meant fetch on a worker entrypoint should return assets.
Although currently SELF can only hit the default entrypoint (with fetch or RPC) right? So you still couldn't replicate prod behaviour for assets + fetch on a named entrypoints, since we decided importing the worker directly won't return assets.
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.
Can't you have service bindings to Worker + Assets in Vitest tests?
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 do you mean by a service binding sorry? As in another worker calling a "regular" fetch handler on a worker with assets? I hadn't thought about multiple workers in vitest with assets yet D:
What I was trying to say above was - from what I understand, SELF.fetch()
will only ever hit the default entrypoint on the UW. If its on a named entrypoint, you need to import the worker and do worker.NAMED.fetch()
We also agreed previously that worker.fetch()
shouldn't return assets because it makes sense that there is no RW if you're importing a worker directly.
So if you had a UW with a named entrypoint, you couldn't test that alongside assets (barring some janky workarounds with another worker in front). Feels like I'm getting into quite the edge case though.
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.
Right. Sounds right.
f12d63b
to
75d9fc3
Compare
75d9fc3
to
b2a1791
Compare
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/11180182432/npm-package-wrangler-6835 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6835/npm-package-wrangler-6835 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-wrangler-6835 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-create-cloudflare-6835 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-kv-asset-handler-6835 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-miniflare-6835 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-pages-shared-6835 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-vitest-pool-workers-6835 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-workers-editor-shared-6835 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-workers-shared-6835 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
What this PR solves / how to test
Fixes WC-2771
Author has addressed the following