Skip to content

Commit 373eb29

Browse files
Apply suggestions from code review
Co-authored-by: ToriLindsay <[email protected]>
1 parent a6135a6 commit 373eb29

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/content/docs/workers/testing/integration-testing.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ try {
108108

109109
## [Miniflare's API](/workers/testing/miniflare/writing-tests/)
110110

111-
If you would like to write integration tests for multiple Workers, need direct access to [bindings](/workers/runtime-apis/bindings/) outside your Worker in tests, or have another advanced use case, consider using [Miniflare's API](/workers/testing/miniflare) directly. Miniflare is the foundation for the other testing tools on this page, exposing a JavaScript API for the [`workerd` runtime](https://github.com/cloudflare/workerd) and local simulators for the other Developer Platform products. Unlike `unstable_startWorker()`, Miniflare does not automatically load options from your Wrangler configuration file. Refer to the [Writing Tests](/workers/testing/miniflare/writing-tests/) page for an example of how to use Miniflare together with `node:test`.
111+
If you would like to write integration tests for multiple Workers, need direct access to [bindings](/workers/runtime-apis/bindings/) outside your Worker in tests, or have another advanced use case, consider using [Miniflare's API](/workers/testing/miniflare) directly. Miniflare is the foundation for the other testing tools on this page, exposing a JavaScript API for the [`workerd` runtime](https://github.com/cloudflare/workerd) and local simulators for the other Developer Platform products. Unlike `unstable_startWorker()`, Miniflare does not automatically load options from your Wrangler configuration file. Refer to the [Writing tests](/workers/testing/miniflare/writing-tests/) page for an example of how to use Miniflare together with `node:test`.
112112

113113
```js
114114
import assert from "node:assert";

src/content/docs/workers/testing/miniflare/writing-tests.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { TabItem, Tabs, Details } from "~/components";
1515

1616
import { FileTree } from "@astrojs/starlight/components";
1717

18-
This guide will instruct you through setting up [Miniflare](/workers/testing/miniflare) for testing your Workers. Miniflare is a low-level API that allows you to fully control how your Workers are run and tested.
18+
This guide will show you how to set up [Miniflare](/workers/testing/miniflare) to test your Workers. Miniflare is a low-level API that allows you to fully control how your Workers are run and tested.
1919

2020
To use Miniflare, make sure you've installed the latest version of Miniflare v3:
2121

@@ -41,9 +41,9 @@ pnpm add -D miniflare
4141

4242
The rest of this guide demonstrates concepts with the [`node:test`](https://nodejs.org/api/test.html) testing framework, but any testing framework can be used.
4343

44-
Miniflare is a low-level API that exposes a large variety of configuration options for running your Worker. In most cases, your tests will only need a subset of the available options, but you can refer to the [full API reference](/workers/testing/miniflare/get-started/#reference) to explore what's possible with Miniflare.
44+
Miniflare is a low-level API that exposes a large variety of configuration options for running your Worker. In most cases, your tests will only need a subset of the available options, but you can refer to the [full API reference](/workers/testing/miniflare/get-started/#reference) to explore what is possible with Miniflare.
4545

46-
Before writing a test, you'll need to create a Worker. Since Miniflare is a low-level API that emulates the Cloudflare platform primitives, your Worker will need to be written in JavaScript or you'll need to [integrate your own build pipeline](#custom-builds) into your testing setup. Here's an example JavaScript-only Worker:
46+
Before writing a test, you will need to create a Worker. Since Miniflare is a low-level API that emulates the Cloudflare platform primitives, your Worker will need to be written in JavaScript or you'll need to [integrate your own build pipeline](#custom-builds) into your testing setup. Here's an example JavaScript-only Worker:
4747

4848
```js title="src/index.js"
4949
export default {
@@ -53,7 +53,7 @@ export default {
5353
};
5454
```
5555

56-
Next, you'll need to create an initial test file:
56+
Next, you will need to create an initial test file:
5757

5858
```js {12,13,14,15,16,17,18,19} title="src/index.test.js"
5959
import assert from "node:assert";
@@ -93,15 +93,15 @@ describe("worker", () => {
9393

9494
You should be able to run the above test via `node --test`
9595

96-
The highlighted lines of the test file above demonstrate how to set up Miniflare to run a JavaScript Worker. Once Miniflare has been set up, your individual tests can send requests to the running Worker and assert against the responses. This is the main limitation of using Miniflare for testing your Worker as compared to the [Vitest integration](/workers/testing/vitest-integration/)all access to your Worker must be through the `dispatchFetch()` Miniflare API, and you cannot unit test individual functions from your Worker.
96+
The highlighted lines of the test file above demonstrate how to set up Miniflare to run a JavaScript Worker. Once Miniflare has been set up, your individual tests can send requests to the running Worker and assert against the responses. This is the main limitation of using Miniflare for testing your Worker as compared to the [Vitest integration](/workers/testing/vitest-integration/)all access to your Worker must be through the `dispatchFetch()` Miniflare API, and you cannot unit test individual functions from your Worker.
9797

9898
<Details header="What runtime are tests running in?">
9999
When using the [Vitest integration](/workers/testing/vitest-integration/),
100100
your entire test suite runs in
101-
[`workerd`](https://github.com/cloudflare/workerd), which is why it's possible
101+
[`workerd`](https://github.com/cloudflare/workerd), which is why it is possible
102102
to unit test individual functions. By contrast, when using a different testing
103103
framework to run tests via Miniflare, only your Worker itself is running in
104-
[`workerd`](https://github.com/cloudflare/workerd)your test files run in
104+
[`workerd`](https://github.com/cloudflare/workerd)your test files run in
105105
Node.js. This means that importing functions from your Worker into your test
106106
files might exhibit different behaviour than you'd see at runtime if the
107107
functions rely on `workerd`-specific behaviour.
@@ -111,7 +111,7 @@ The highlighted lines of the test file above demonstrate how to set up Miniflare
111111

112112
:::caution
113113

114-
Miniflare does not read [Wrangler's config file](/workers/wrangler/configuration), and so all bindings that your Worker uses need to be specified in the Miniflare API options.
114+
Miniflare does not read [Wrangler's config file](/workers/wrangler/configuration). All bindings that your Worker uses need to be specified in the Miniflare API options.
115115

116116
:::
117117

@@ -139,7 +139,7 @@ describe("worker", () => {
139139
});
140140
```
141141

142-
You can also interact with local resources such as KV and R2, using the same API as you would from a Worker. For example, here's how you would interact with a KV namespace:
142+
You can also interact with local resources such as KV and R2 using the same API as you would from a Worker. For example, here's how you would interact with a KV namespace:
143143

144144
```diff lang="js" title="src/index.test.js"
145145
...
@@ -193,7 +193,7 @@ new Miniflare({
193193

194194
## Custom builds
195195

196-
In many real-world cases, Workers are not written as plain JavaScript, but are instead written as multiple TypeScript files importing from npm packages etc... that are then bundled by a build tool. When testing your Worker via Miniflare directly you need to run this build tool before your tests. Exactly how this build is run will depend on the specific test framework you use, but for `node:test` it would likely be in a `setup()` hook. For example, if you use [Wrangler](/workers/wrangler/) to build and deploy your Worker, you could spawn a `wrangler build` command:
196+
In many real-world cases, Workers are not written in plain JavaScript but instead consist of multiple TypeScript files that import from npm packages and other dependencies, which are then bundled by a build tool. When testing your Worker via Miniflare directly you need to run this build tool before your tests. Exactly how this build is run will depend on the specific test framework you use, but for `node:test` it would likely be in a `setup()` hook. For example, if you use [Wrangler](/workers/wrangler/) to build and deploy your Worker, you could spawn a `wrangler build` command like this:
197197

198198
```js
199199
before(() => {

src/content/docs/workers/wrangler/api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Wrangler offers APIs to programmatically interact with your Cloudflare Workers.
1818

1919
## `unstable_startWorker`
2020

21-
This API exposes the internals of Wrangler's dev server, and allows you to customise how it runs. For example, you could use `unstable_startWorker()` to run integration tests against your Worker (the below example is with `node:test`, but this should work in any testing framework):
21+
This API exposes the internals of Wrangler's dev server, and allows you to customise how it runs. For example, you could use `unstable_startWorker()` to run integration tests against your Worker. This example uses `node:test`, but should apply to any testing framework:
2222

2323
```js
2424
import assert from "node:assert";

0 commit comments

Comments
 (0)