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

Add Miniflare/startWorker() + node:test tutorial #19254

Merged
merged 11 commits into from
Feb 12, 2025

Conversation

penalosa
Copy link
Contributor

Summary

This PR adds a tutorial for how to test using Miniflare & node:test. Still to come, a tutorial for how to test using startWorker() and node:test.

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.

Copy link
Contributor

@hyperlint-ai hyperlint-ai bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 total issue(s) found.

Copy link
Contributor

@hyperlint-ai hyperlint-ai bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 total issue(s) found.

Copy link
Contributor

@hyperlint-ai hyperlint-ai bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 total issue(s) found.

Copy link

cloudflare-workers-and-pages bot commented Jan 16, 2025

Deploying cloudflare-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: bf3abd8
Status: ✅  Deploy successful!
Preview URL: https://e65f1bc6.cloudflare-docs-7ou.pages.dev
Branch Preview URL: https://penalosa-improve-testing-doc.cloudflare-docs-7ou.pages.dev

View logs

Copy link
Contributor

github-actions bot commented Jan 16, 2025

@penalosa penalosa changed the title Add Miniflare + node:test tutorial Add Miniflare/startWorker() + node:test tutorial Jan 16, 2025
Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>
When using the [Vitest integration](/workers/testing/vitest-integration/), your entire test suite runs in [`workerd`](https://github.com/cloudflare/workerd), which is why it's possible to unit test individual functions. By contrast, when using a different testing framework to run tests via Miniflare, only your Worker itself is running in [`workerd`](https://github.com/cloudflare/workerd)—your test files run in Node.js. This means that importing functions from your Worker into your test files might exhibit different behaviour than you'd see at runtime if the functions rely on `workerd`-specific behaviour.
</Details>

## Interacting with Bindings
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is already sufficiently obvious, but could be worth noting (somewhere on this page) that all bindings specified in your wrangler config file have to be passed into Miniflare's config options. (And mention that these could be mocked, even if there isn't an example for now - I see you opened an issue to track that for later)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add that in a followup PR

Copy link
Contributor

github-actions bot commented Feb 11, 2025

Preview URL: https://3a175b86.preview.developers.cloudflare.com
Preview Branch URL: https://penalosa-improve-testing-docs.preview.developers.cloudflare.com

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/workers/testing/miniflare/writing-tests/ https://penalosa-improve-testing-docs.preview.developers.cloudflare.com/workers/testing/miniflare/writing-tests/
https://developers.cloudflare.com/workers/testing/ https://penalosa-improve-testing-docs.preview.developers.cloudflare.com/workers/testing/
https://developers.cloudflare.com/workers/wrangler/api/ https://penalosa-improve-testing-docs.preview.developers.cloudflare.com/workers/wrangler/api/
https://developers.cloudflare.com/workers/testing/integration-testing/ https://penalosa-improve-testing-docs.preview.developers.cloudflare.com/workers/testing/integration-testing/
https://developers.cloudflare.com/workers/local-development/ https://penalosa-improve-testing-docs.preview.developers.cloudflare.com/workers/local-development/

penalosa and others added 2 commits February 11, 2025 16:16
Co-authored-by: ToriLindsay <tgalatro@cloudflare.com>
@penalosa penalosa enabled auto-merge (squash) February 12, 2025 20:28
@penalosa penalosa merged commit b9304f7 into production Feb 12, 2025
11 checks passed
@penalosa penalosa deleted the penalosa/improve-testing-docs branch February 12, 2025 21:20
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/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants