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
There was a problem hiding this comment.
This case should also cover the router worker switch
There was a problem hiding this comment.
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.
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.
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.
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.
Also other non-fetch() handlers such as scheduled and queue will not go via Router Worker
There was a problem hiding this comment.
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.
Can't you have service bindings to Worker + Assets in Vitest tests?
There was a problem hiding this comment.
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.
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-6835You 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-6835Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-wrangler-6835 dev path/to/script.jsAdditional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-create-cloudflare-6835 --no-auto-updatenpm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-kv-asset-handler-6835npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-miniflare-6835npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-pages-shared-6835npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-vitest-pool-workers-6835npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-workers-editor-shared-6835npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11180182432/npm-package-cloudflare-workers-shared-6835Note 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