workers-sdk
workers-sdk copied to clipboard
vitest-pool-workers: Support AbortSignal in fetch-mock
What this PR solves / how to test
This PR introduces support for AbortSignal to fetch-mock, allowing signals to 'abort' requests during tests as they do at actual runtime. This makes it significantly easier to test this behaviour when writing tests that rely on signals and their behaviours.
Author has addressed the following
- Tests
- [ ] TODO (before merge)
- [x] Tests included
- [ ] Tests not necessary because:
- E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
- [ ] I don't know
- [ ] Required
- [x] Not required because:
- Unit tests cover changes
- Changeset (Changeset guidelines)
- [ ] TODO (before merge)
- [x] Changeset included
- [ ] Changeset not necessary because:
- Public documentation
- [ ] TODO (before merge)
- [ ] Cloudflare docs PR(s):
- [x] Documentation not necessary because:
- This not being supported was a little cryptic as it was undocumented but suggested in the discord community to use
AbortSignalwhen wanting to time out fetch calls. SupportedAbortSignalaligns with what is expected offetchin tests reflecting actual usage.
- This not being supported was a little cryptic as it was undocumented but suggested in the discord community to use
🦋 Changeset detected
Latest commit: 9794a3916e46f2c2e2521efb766adb763058b6f8
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
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/11941549222/npm-package-wrangler-7032
You can reference the automatically updated head of this PR with:
npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7032/npm-package-wrangler-7032
Or you can use npx with this latest build directly:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11941549222/npm-package-wrangler-7032 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11941549222/npm-package-create-cloudflare-7032 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11941549222/npm-package-cloudflare-kv-asset-handler-7032
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11941549222/npm-package-miniflare-7032
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11941549222/npm-package-cloudflare-pages-shared-7032
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11941549222/npm-package-cloudflare-vitest-pool-workers-7032
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11941549222/npm-package-cloudflare-workers-editor-shared-7032
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11941549222/npm-package-cloudflare-workers-shared-7032
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11941549222/npm-package-cloudflare-workflows-shared-7032
Note that these links will no longer work once the GitHub Actions artifact expires.
[email protected] includes the following runtime dependencies:
| Package | Constraint | Resolved |
|---|---|---|
miniflare |
workspace:* | 3.20241106.0 |
workerd |
1.20241106.1 | 1.20241106.1 |
workerd --version |
1.20241106.1 | 2024-11-06 |
Please ensure constraints are pinned, and miniflare/workerd minor versions match.
@emily-shen is there any chance I can get a re-review on this? :)
Hey, really sorry for the delay! I had a look earlier and it looks all good to me, but I'm not actually that familiar with this part of the codebase and probably not the best person to review this, will forward this to the team again 😅
cc @penalosa (when you get back) and @edmundhung if you could help with this PR :)
@Codex- Are we sure this is the correct behaviour in the runtime? This PR seems to suggest that the AbortController does not work as expected at the moment: https://github.com/cloudflare/workers-sdk/issues/6467
@Codex- Are we sure this is the correct behaviour in the runtime? This PR seems to suggest that the AbortController does not work as expected at the moment: #6467
@andyjessop the linked appears to be in regards to a client aborting the request to the worker, but this is for a request the worker is making to another service via fetch which in my manual testing appears to work okay 🤔
FAIL e2e-tests/cli.test.ts > E2E: Basic C3 functionality > Inferring the category, type and language if the type is `hello-world-python`
Error: Test timed out in 600000ms.
Appears unrelated to these changes
Validation errors in PR description:
- Your PR must run E2E tests, or provide justification for why running them is not required
- Your PR must include documentation (in the form of a link to a Cloudflare Docs issue or PR), or provide justification for why no documentation is required
e2e runs, and the documentation point is covered above
Is there anything else you need from me?
Congratulations @Codex-, the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cm3zxwf8718910cmnohdto81a
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!