-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workers] Add docs for Vitest testing (#13092)
* workers: initial testing docs commit. add files for structure per ToC. * add page write your first test * add config and setup sections to first test doc. * add sample tests to first test guide. add first sentence to unstable dev guide. * update docs to reference vitest 1.3.0. add section for configuring via wrangler config. * Reorder table-of-contents * Add migration from Miniflare 2's testing environments page * Add testing options page * Add configuration page * Add test APIs page * Add internal details page * add migration docs for unstable_dev * remove testing section from local dev guide * add callouts for additional config info docs * add recipes for fetch events and scheduled events. * add advanced config and integration test examples. * Minor fixups to `migrate-from-miniflare-2.md` and `configuration.md` * Update content/workers/testing/vitest/get-started/migrate-from-unstable-dev.md Co-authored-by: MrBBot <[email protected]> * Update content/workers/testing/vitest/get-started/migrate-from-unstable-dev.md Co-authored-by: MrBBot <[email protected]> * Update content/workers/testing/vitest/get-started/write-your-first-test.md Co-authored-by: MrBBot <[email protected]> * Update content/workers/testing/vitest/get-started/write-your-first-test.md Co-authored-by: MrBBot <[email protected]> * update unstable_dev migration guide per comments. update first test examples. * add npm command to install vitest 1.3.0 * move vitest into section about installing packages. add note about only 1.3.0 being supported. * Update content/workers/testing/vitest/get-started/write-your-first-test.md Co-authored-by: MrBBot <[email protected]> * Update content/workers/testing/vitest/get-started/write-your-first-test.md Co-authored-by: MrBBot <[email protected]> * Add isolation model diagrams to internal details page * More minor fixups to `configuration.md` * remove recipe examples. add links to fixtures folder. * add compat date and flag to prereqs * Replace `Vitest pool` with `Vitest integration` * Update `configuration.md` in response to review * Update `migrate-from-miniflare-2.md` in response to review * Update `internal-details.md` in response to review * Update `test-apis.md` in response to review * fixup! Update `configuration.md` in response to review * update testing section structure. add pages for unit and integration testing. add section for local binding support. * update testing section description * add description for vitest integration * add vitest integration description * update docs to reflect api changes for defineWorkersConfig * add more info about SELF and auxiliary Workers * Apply suggestions from code review Style guide fixes * PCX review test * Apply suggestions from code review Minor style guide edits * Apply suggestions from code review minor style guide fixes * PCX review for write your first test and isolation * Apply suggestions from code review Co-authored-by: Kate Tungusova <[email protected]> * update api code blocks. add recipe links. * add partial to reference pages functions. add partial to relevant pages. * add auxiliary worker glossary term. update integration testing page. * Apply more suggestions from code review * Minor fixups * Add known issues * edit first test examples to match c3 * Fix broken links * Replace `we` with `Cloudflare` per style guide --------- Co-authored-by: bcoll <[email protected]> Co-authored-by: MrBBot <[email protected]> Co-authored-by: Kate Tungusova <[email protected]> Co-authored-by: Kate Tungusova <[email protected]>
- Loading branch information
1 parent
45fe633
commit 652c33a
Showing
31 changed files
with
1,865 additions
and
153 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...rkers/testing/vitest/isolation-model-1-no-isolated-storage-no-single-worker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions
25
.../workers/testing/vitest/isolation-model-2-no-isolated-storage-single-worker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions
39
.../workers/testing/vitest/isolation-model-3-isolated-storage-no-single-worker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions
25
...ges/workers/testing/vitest/isolation-model-4-isolated-storage-single-worker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
_build: | ||
publishResources: false | ||
render: never | ||
list: never | ||
--- | ||
|
||
{{<Aside type="note" header="Pages Functions">}} | ||
|
||
The content described on this page is also applicable to [Pages Functions](/pages/functions/). Pages Functions are Cloudflare Workers and can be thought of synonymously with Workers in this context. | ||
|
||
{{</Aside>}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
--- | ||
pcx_content_type: navigation | ||
title: Observability | ||
weight: 9 | ||
weight: 10 | ||
--- | ||
|
||
# Observability | ||
|
||
Test and debug your Worker projects. | ||
Understand how your Worker projects are performing via logs, traces, and other data sources. | ||
|
||
{{<directory-listing showDescriptions="true">}} |
136 changes: 0 additions & 136 deletions
136
content/workers/observability/local-development-and-testing.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
pcx_content_type: navigation | ||
title: Testing | ||
weight: 9 | ||
--- | ||
|
||
# Testing | ||
|
||
Review the tools available for testing and debugging Workers. | ||
|
||
{{<directory-listing showDescriptions="true">}} | ||
|
||
## Testing comparison matrix | ||
|
||
| Feature | Vitest Pool | `unstable_dev()` | Miniflare's API | | ||
| ----------------------------------------- | ---------------- | ---------------- | -------------------- | | ||
| Unit testing | ✅ | ❌ | ❌ | | ||
| Integration testing | ✅ | ✅ | ✅ | | ||
| Loading Wrangler configuration files | ✅ | ✅ | ❌ | | ||
| Bindings directly in tests | ✅ | ❌ | ✅ | | ||
| Isolated per-test storage | ✅ | ❌ | ❌ | | ||
| Outbound request mocking | ✅ | ❌ | ✅ | | ||
| Multiple Worker support | ✅ | 🚧[^1] | ✅ | | ||
| Direct access to Durable Object instances | ✅ | ❌ | ❌ | | ||
| Run Durable Object alarms immediately | ✅ | ❌ | ❌ | | ||
| List Durable Objects | ✅ | ❌ | ❌ | | ||
| Testing service Workers | ❌ | ✅ | ✅ | | ||
|
||
[^1]: Support for multiple Workers in [`unstable_dev()`](/workers/wrangler/api/#unstable_dev) relies on `wrangler dev`'s service registry which can be unreliable when running multiple tests in parallel. | ||
|
||
{{<render file="_testing-pages-functions.md" productFolder="workers">}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
title: Debugging tools | ||
weight: 4 | ||
pcx_content_type: concept | ||
meta: | ||
description: Debug your local and deployed Workers using a variety of tools. | ||
--- | ||
|
||
# Debugging tools | ||
|
||
Being able to assess how your Workers are functioning at various points in the development cycle is vital to identifying the root causes of bugs or issues. | ||
|
||
Cloudflare provides a variety of tools to help you debug your Workers. | ||
|
||
## Chrome DevTools | ||
|
||
Wrangler supports using [Chrome DevTools](https://developer.chrome.com/docs/devtools/) to view logs/sources, set breakpoints, and profile CPU/memory usage. To open a DevTools session connected to your Worker from any Chromium-based browser, run [`wrangler dev`](/workers/wrangler/commands/#dev) and press the <kbd>d</kbd> key in your terminal. | ||
|
||
## Debug via breakpoints | ||
|
||
As of Wrangler 3.9.0, you can debug via breakpoints in your Worker. Breakpoints provide the ability to review what is happening at a given point in the execution of your Worker. Breakpoint functionality exists in both DevTools and VS Code. | ||
|
||
For more information on breakpoint debugging via Chrome's DevTools, refer to [Chrome's article on breakpoints](https://developer.chrome.com/docs/devtools/javascript/breakpoints/). | ||
|
||
### Setup VS Code to use breakpoints | ||
|
||
To setup VS Code for breakpoint debugging in your Worker project: | ||
|
||
1. Create a `.vscode` folder in your project's root folder if one does not exist. | ||
2. Within that folder, create a `launch.json` file with the following content: | ||
|
||
```json | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Wrangler", | ||
"type": "node", | ||
"request": "attach", | ||
"port": 9229, | ||
"cwd": "/", | ||
"resolveSourceMapLocations": null, | ||
"attachExistingChildren": false, | ||
"autoAttachChildProcesses": false, | ||
"sourceMaps": true // works with or without this line | ||
} | ||
] | ||
} | ||
``` | ||
|
||
3. Open your project in VS Code, open a new terminal window from VS Code, and run `npx wrangler dev` to start the local dev server. | ||
|
||
4. At the top of the **Run & Debug** panel, you should see an option to select a configuration. Choose **Wrangler**, and select the play icon. **Wrangler: Remote Process [0]** should show up in the Call Stack panel on the left. | ||
|
||
5. Go back to a `.js` or `.ts` file in your project and add at least one breakpoint. | ||
|
||
5. Open your browser and go to the Worker's local URL (default `http://127.0.0.1:8787`). The breakpoint should be hit, and you should be able to review details about your code at the specified line. | ||
|
||
{{<Aside type="warning">}} | ||
|
||
Breakpoint debugging in `wrangler dev` using `--remote` could extend Worker CPU time and incur additional costs since you are testing against actual resources that count against usage limits. It is recommended to use `wrangler dev` without the `--remote` option. This ensures you are developing locally. | ||
|
||
{{</Aside>}} | ||
|
||
{{<Aside type="note">}} | ||
|
||
The `.vscode/launch.json` file only applies to a single workspace. If you prefer, you can add the above launch configuration to your User Settings (per the [official VS Code documentation](https://code.visualstudio.com/docs/editor/debugging#_global-launch-configuration)) to have it available for all your workspaces. | ||
|
||
{{</Aside>}} | ||
|
||
## Related resources | ||
|
||
* [Local Development](/workers/testing/local-development/) - Develop your Workers and connected resources locally via Wrangler and [`workerd`](https://github.com/cloudflare/workerd), for a fast, accurate feedback loop. |
Oops, something went wrong.