Skip to content
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

[Workers] Add docs for Vitest testing #13092

Merged
merged 58 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9f6ad69
workers: initial testing docs commit. add files for structure per ToC.
admah Jan 31, 2024
5481020
add page write your first test
admah Feb 13, 2024
b9f904a
add config and setup sections to first test doc.
admah Feb 20, 2024
cf0b012
add sample tests to first test guide. add first sentence to unstable …
admah Feb 20, 2024
2add72b
update docs to reference vitest 1.3.0. add section for configuring vi…
admah Feb 20, 2024
7250135
Reorder table-of-contents
mrbbot Feb 20, 2024
a266e51
Add migration from Miniflare 2's testing environments page
mrbbot Feb 20, 2024
4a3494b
Add testing options page
mrbbot Feb 20, 2024
19364fd
Add configuration page
mrbbot Feb 20, 2024
e39f3d6
Add test APIs page
mrbbot Feb 20, 2024
5947811
Add internal details page
mrbbot Feb 20, 2024
cade5b2
add migration docs for unstable_dev
admah Feb 20, 2024
a68d2ea
remove testing section from local dev guide
admah Feb 20, 2024
fe0d63f
add callouts for additional config info docs
admah Feb 20, 2024
2456419
add recipes for fetch events and scheduled events.
admah Feb 21, 2024
7b7a8c8
add advanced config and integration test examples.
admah Feb 21, 2024
7a2994c
Minor fixups to `migrate-from-miniflare-2.md` and `configuration.md`
mrbbot Feb 22, 2024
6418117
Update content/workers/testing/vitest/get-started/migrate-from-unstab…
admah Feb 22, 2024
3ba6545
Update content/workers/testing/vitest/get-started/migrate-from-unstab…
admah Feb 22, 2024
52035e4
Update content/workers/testing/vitest/get-started/write-your-first-te…
admah Feb 22, 2024
a776599
Update content/workers/testing/vitest/get-started/write-your-first-te…
admah Feb 22, 2024
5f18637
update unstable_dev migration guide per comments. update first test e…
admah Feb 23, 2024
e154e1b
add npm command to install vitest 1.3.0
admah Feb 23, 2024
b531643
move vitest into section about installing packages. add note about on…
admah Feb 23, 2024
70af281
Update content/workers/testing/vitest/get-started/write-your-first-te…
admah Feb 23, 2024
21ec0b4
Update content/workers/testing/vitest/get-started/write-your-first-te…
admah Feb 23, 2024
dd3d3aa
Add isolation model diagrams to internal details page
mrbbot Feb 27, 2024
96362d0
More minor fixups to `configuration.md`
mrbbot Feb 27, 2024
e4226b5
remove recipe examples. add links to fixtures folder.
admah Feb 27, 2024
6e48e51
add compat date and flag to prereqs
admah Mar 1, 2024
0e73ff6
Replace `Vitest pool` with `Vitest integration`
mrbbot Mar 4, 2024
8942b8c
Update `configuration.md` in response to review
mrbbot Mar 4, 2024
885b75f
Update `migrate-from-miniflare-2.md` in response to review
mrbbot Mar 4, 2024
3c9915e
Update `internal-details.md` in response to review
mrbbot Mar 4, 2024
7b675f7
Update `test-apis.md` in response to review
mrbbot Mar 4, 2024
183639b
fixup! Update `configuration.md` in response to review
mrbbot Mar 4, 2024
6214c0a
update testing section structure. add pages for unit and integration …
admah Mar 4, 2024
be383d7
update testing section description
admah Mar 4, 2024
20e3a5f
add description for vitest integration
admah Mar 4, 2024
ecee377
add vitest integration description
admah Mar 4, 2024
1966150
update docs to reflect api changes for defineWorkersConfig
admah Mar 6, 2024
55002cf
add more info about SELF and auxiliary Workers
admah Mar 10, 2024
aa0e03d
Apply suggestions from code review
deadlypants1973 Mar 11, 2024
d6715fc
PCX review test
deadlypants1973 Mar 12, 2024
8a397b8
Apply suggestions from code review
deadlypants1973 Mar 12, 2024
059671b
Apply suggestions from code review
deadlypants1973 Mar 12, 2024
9b4bd20
PCX review for write your first test and isolation
deadlypants1973 Mar 12, 2024
81751a1
Apply suggestions from code review
admah Mar 12, 2024
39e1841
update api code blocks. add recipe links.
admah Mar 13, 2024
95fd9c3
add partial to reference pages functions. add partial to relevant pages.
admah Mar 13, 2024
2c17dab
add auxiliary worker glossary term. update integration testing page.
admah Mar 13, 2024
9ddf5d2
Merge branch 'production' into admah/vitest-pool-docs
mrbbot Mar 13, 2024
698b2b1
Apply more suggestions from code review
mrbbot Mar 13, 2024
2dd232f
Minor fixups
mrbbot Mar 13, 2024
0821fda
Add known issues
mrbbot Mar 13, 2024
69e7614
edit first test examples to match c3
admah Mar 13, 2024
04c4d34
Fix broken links
mrbbot Mar 13, 2024
7aae21d
Replace `we` with `Cloudflare` per style guide
mrbbot Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions components/CodeCopy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function copyCode(e: MouseEvent) {
width: 2rem;
font-size: 0.9rem;
padding: 0.5rem;
box-sizing: border-box;
mrbbot marked this conversation as resolved.
Show resolved Hide resolved
background: #d9d9d9;
color: #1e1e1e;
border: none;
Expand Down
4 changes: 2 additions & 2 deletions content/workers/observability/_index.md
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 content/workers/observability/local-development-and-testing.md

This file was deleted.

29 changes: 29 additions & 0 deletions content/workers/testing/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
pcx_content_type: navigation
title: Testing
weight: 9
---

# Testing

Review the tools available for testing and debugging Workers and [Pages Functions](/pages/functions/).

{{<directory-listing showDescriptions="true">}}

## Testing comparison matrix

| Feature | Vitest&nbsp;Pool | `unstable_dev()` | Miniflare's&nbsp;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.
72 changes: 72 additions & 0 deletions content/workers/testing/debugging-tools.md
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 {{<glossary-tooltip term_id="workerd" link="https://github.com/cloudflare/workerd">}}`workerd`{{</glossary-tooltip>}}, for a fast, accurate feedback loop.
Loading
Loading