Skip to content

Conversation

@emily-shen
Copy link
Contributor

@emily-shen emily-shen commented Mar 25, 2025

Summary

This is a WIP! Opening this in a very rough state to start discussion on structure, and any feedback is welcome 🧡

The testing docs were quite nested before - this PR aims to restructure pages so that the Vitest integration is more prominent, and you get to writing your first test sooner.

Also updates some out of date information along the way.

main structural changes

  • remove unit testing and integration testing pages, and divide up into testing methods
  • get rid of 'getting started' section and just have 'write your first test' at the top level

Screenshots (optional)

Documentation checklist

  • The documentation style guide has been adhered to.
  • If a larger change - such as adding a new page- an issue has been opened in relation to any incorrect or out of date information that this PR fixes.
  • Files which have changed name or location have been allocated redirects.

@github-actions
Copy link
Contributor

This PR changes current filenames or deletes current files. Make sure you have redirects set up to cover the following paths:

  • /workers/testing/integration-testing/
  • /workers/testing/unit-testing/
  • /workers/testing/vitest-integration/get-started/
  • /workers/testing/vitest-integration/get-started/migrate-from-miniflare-2/
  • /workers/testing/vitest-integration/get-started/migrate-from-unstable-dev/
  • /workers/testing/vitest-integration/get-started/write-your-first-test/


- `miniflare`: `SourcelessWorkerOptions & { workers?: WorkerOptions\[]; }` optional

- Use this to provide configuration information that is typically stored within the [Wrangler configuration file](/workers/wrangler/configuration/), such as [bindings](/workers/runtime-apis/bindings/), [compatibility dates](/workers/configuration/compatibility-dates/), and [compatibility flags](/workers/configuration/compatibility-flags/). The `WorkerOptions` interface is defined [here](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare#interface-workeroptions). Use the `main` option above to configure the entry point, instead of the Miniflare `script`, `scriptPath`, or `modules` options.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identified issues

  • Vale Style Guide - (cloudflare.MeaningfulLinkWords-warning) Warning: Rewrite the link text for [here](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare#interface-workeroptions) to be more descriptive. For more information, refer to Descriptive link text.

Proposed fix

Suggested change
- Use this to provide configuration information that is typically stored within the [Wrangler configuration file](/workers/wrangler/configuration/), such as [bindings](/workers/runtime-apis/bindings/), [compatibility dates](/workers/configuration/compatibility-dates/), and [compatibility flags](/workers/configuration/compatibility-flags/). The `WorkerOptions` interface is defined [here](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare#interface-workeroptions). Use the `main` option above to configure the entry point, instead of the Miniflare `script`, `scriptPath`, or `modules` options.
The `WorkerOptions` interface is defined in the [Miniflare documentation](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare#interface-workeroptions).

The link text 'here' is not descriptive. I've changed it to 'in the Miniflare documentation' to provide more context about the link's destination.

The Workers Vitest integration is the recommended way to test Workers and [Pages Functions](/pages/functions/).

[Vitest](https://vitest.dev/) is a popular JavaScript testing framework featuring a very fast watch mode, Jest compatibility, and out-of-the-box support for TypeScript.
The `@cloudflare/vitest-pool-workers` package works by running code inside a Cloudflare Worker where Vitest would usually run inside a [Node.js worker thread](https://nodejs.org/api/worker_threads.html).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identified issues

  • Vale Style Guide - (Terms-error) Use 'Cloudflare' instead of 'cloudflare'.
  • Vale Style Guide - (Terms-error) Use 'Workers' instead of 'workers'.

Proposed fix

Suggested change
The `@cloudflare/vitest-pool-workers` package works by running code inside a Cloudflare Worker where Vitest would usually run inside a [Node.js worker thread](https://nodejs.org/api/worker_threads.html).
The `@cloudflare/vitest-pool-workers` package works by running code inside a Cloudflare Worker where Vitest would usually run inside a [Node.js Worker thread](https://nodejs.org/api/worker_threads.html).

I capitalized 'Cloudflare' and 'Workers' as per the style guide recommendation. The term 'cloudflare' within the package name is a code reference and should not be changed.


For example, to add bindings that will be used in tests, you can add `miniflare` to `defineWorkersConfig`:
For example, this configuration would add a KV namespace `TEST_NAMESPACE` that was only accessible in tests. Using this method, you can add or override existing bindings like Durable Objects or service bindings.
// maybe mention mocking things (e.g. as a service binding) and link to a separate page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identified issues

  • Vale Style Guide - (cloudflare.LatinTerms-warning) Use 'for example' instead of 'e.g.', but consider rewriting the sentence.

Proposed fix

Suggested change
// maybe mention mocking things (e.g. as a service binding) and link to a separate page.
// maybe mention mocking things (for example, as a service binding) and link to a separate page.

I replaced 'e.g.' with 'for example' to comply with the style guide. This change does not affect any code references or restricted areas.

@hyperlint-ai
Copy link
Contributor

hyperlint-ai bot commented Mar 25, 2025

Howdy and thanks for contributing to our repo. The Cloudflare team reviews new, external PRs within two (2) weeks. If it's been two weeks or longer without any movement, please tag the PR Assignees in a comment.

We review internal PRs within 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally.


PR Change Summary

Restructured the Workers testing documentation to enhance clarity and accessibility, emphasizing the Vitest integration and updating outdated information.

  • Restructured testing documentation for better clarity and accessibility.
  • Highlighted the Vitest integration for unit testing.
  • Updated outdated information across various testing pages.
  • Introduced a new page for the unstable_startWorker() API.

Modified Files

  • src/content/docs/workers/testing/index.mdx
  • src/content/docs/workers/testing/miniflare/index.mdx
  • src/content/docs/workers/testing/miniflare/writing-tests.mdx
  • src/content/docs/workers/testing/vitest-integration/configuration.mdx
  • src/content/docs/workers/testing/vitest-integration/index.mdx
  • src/content/docs/workers/testing/vitest-integration/isolation-and-concurrency.mdx
  • src/content/docs/workers/testing/vitest-integration/known-issues.mdx
  • src/content/docs/workers/testing/vitest-integration/recipes.mdx

Added Files

  • src/content/docs/workers/testing/unstable_startWorker.mdx
  • src/content/docs/workers/testing/vitest-integration/migration-guides/index.mdx

Renamed Files

  • src/content/docs/workers/testing/vitest-integration/migration-guides/migrate-from-miniflare-2.mdx
  • src/content/docs/workers/testing/vitest-integration/migration-guides/migrate-from-unstable-dev.mdx
  • src/content/docs/workers/testing/vitest-integration/write-your-first-test.mdx

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

What is Hyperlint?

Hyperlint is an AI agent that helps you write, edit, and maintain your documentation.

Learn more about the Hyperlint AI reviewer and the checks that we can run on your documentation.

@github-actions github-actions bot added product:workers Related to Workers product size/l labels Mar 25, 2025
@github-actions
Copy link
Contributor

Preview URL: https://8427f607.preview.developers.cloudflare.com
Preview Branch URL: https://emily-vitest.preview.developers.cloudflare.com

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/workers/testing/vitest-integration/configuration/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/configuration/
https://developers.cloudflare.com/workers/testing/vitest-integration/write-your-first-test/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/write-your-first-test/
https://developers.cloudflare.com/workers/testing/integration-testing/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/integration-testing/
https://developers.cloudflare.com/workers/testing/unit-testing/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/unit-testing/
https://developers.cloudflare.com/workers/testing/vitest-integration/known-issues/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/known-issues/
https://developers.cloudflare.com/workers/testing/unstable_startworker/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/unstable_startworker/
https://developers.cloudflare.com/workers/testing/vitest-integration/get-started/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/get-started/
https://developers.cloudflare.com/workers/testing/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/
https://developers.cloudflare.com/workers/testing/vitest-integration/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/
https://developers.cloudflare.com/workers/testing/miniflare/writing-tests/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/miniflare/writing-tests/
https://developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/
https://developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-unstable-dev/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-unstable-dev/
https://developers.cloudflare.com/workers/testing/vitest-integration/isolation-and-concurrency/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/isolation-and-concurrency/
https://developers.cloudflare.com/workers/testing/vitest-integration/recipes/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/recipes/
https://developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-miniflare-2/ https://emily-vitest.preview.developers.cloudflare.com/workers/testing/vitest-integration/migration-guides/migrate-from-miniflare-2/

@github-actions
Copy link
Contributor

CI run failed: build logs

@emily-shen emily-shen marked this pull request as draft March 25, 2025 14:38
@emily-shen emily-shen closed this Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:workers Related to Workers product size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants