You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/testing/vitest-integration/configuration.mdx
+100-8Lines changed: 100 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,25 +46,117 @@ Custom Vitest `environment`s or `runner`s are not supported when using the Worke
46
46
47
47
:::
48
48
49
-
## Functions
49
+
## APIs
50
50
51
-
The following functions are exported from the `@cloudflare/vitest-pool-workers/config` module.
51
+
The following APIs are exported from the `@cloudflare/vitest-pool-workers/config` module.
52
52
53
+
### `defineWorkersConfig(options)`
53
54
55
+
Ensures Vitest is configured to use the Workers integration with the correct module resolution settings, and provides type checking for [WorkersPoolOptions](#workerspooloptions). This should be used in place of the [`defineConfig()`](https://vitest.dev/config/file.html) function from Vitest. The `defineWorkersConfig()` function also accepts a `Promise` of `options`, or an optionally-`async` function returning `options`.
* Ensures Vitest is configured to use the Workers integration with the correct module resolution settings, and provides type checking for `WorkersPoolOptions`. This should be used in place of the [`defineConfig()`](https://vitest.dev/config/file.html) function from Vitest. The `defineWorkersConfig()` function also accepts a `Promise` of `options`, or an optionally-`async` function returning `options`.
*Ensures Vitest is configured to use the Workers integration with the correct module resolution settings, and provides type checking for `WorkersPoolOptions`. This should be used in place of the [`defineProject()`](https://vitest.dev/guide/workspace) function from Vitest. The `defineWorkersProject()` function also accepts a `Promise` of `options`, or an optionally-`async` function returning `options`.
73
+
Ensures Vitest is configured to use the Workers integration with the correct module resolution settings, and provides type checking for [WorkersPoolOptions](#workerspooloptions) similar to `defineWorkersConfig`, except this should be used in place of the [`defineProject()`](https://vitest.dev/guide/workspace) function from Vitest. The `defineWorkersProject()` function also accepts a `Promise` of `options`, or an optionally-`async` function returning `options`.
Creates a Pages ASSETS binding that serves files insides the `assetsPath`. This is required if you uses `createPagesEventContext()` to test your Pages function. Refer to the [Pages recipe](/workers/testing/vitest-integration/recipes) for an example on testing Pages function.
64
101
65
-
* Reads all [D1 migrations](/d1/reference/migrations/) stored at `migrationsPath` and returns them ordered by migration number. Each migration will have its contents split into an array of individual SQL queries. Call the [`applyD1Migrations()`](/workers/testing/vitest-integration/test-apis/#d1) function inside a test or [setup file](https://vitest.dev/config/#setupfiles) to apply migrations. Refer to the [D1 recipe](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/d1) for an example project using migrations.
102
+
```ts
103
+
importpathfrom"node:path";
104
+
import {
105
+
buildPagesASSETSBinding,
106
+
defineWorkersProject,
107
+
} from"@cloudflare/vitest-pool-workers/config";
108
+
109
+
exportdefaultdefineWorkersProject(async () => {
110
+
const assetsPath =path.join(__dirname, "public");
111
+
112
+
return {
113
+
test: {
114
+
poolOptions: {
115
+
workers: {
116
+
miniflare: {
117
+
serviceBindings: {
118
+
ASSETS: awaitbuildPagesASSETSBinding(assetsPath),
119
+
},
120
+
},
121
+
},
122
+
},
123
+
},
124
+
};
125
+
});
66
126
127
+
```
67
128
129
+
### `readD1Migrations(migrationsPath)`
130
+
131
+
Reads all [D1 migrations](/d1/reference/migrations/) stored at `migrationsPath` and returns them ordered by migration number. Each migration will have its contents split into an array of individual SQL queries. Call the [`applyD1Migrations()`](/workers/testing/vitest-integration/test-apis/#d1) function inside a test or [setup file](https://vitest.dev/config/#setupfiles) to apply migrations. Refer to the [D1 recipe](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/d1) for an example project using migrations.
132
+
133
+
```ts
134
+
importpathfrom"node:path";
135
+
import {
136
+
defineWorkersProject,
137
+
readD1Migrations,
138
+
} from"@cloudflare/vitest-pool-workers/config";
139
+
140
+
exportdefaultdefineWorkersProject(async () => {
141
+
// Read all migrations in the `migrations` directory
Copy file name to clipboardExpand all lines: src/content/docs/workers/testing/vitest-integration/recipes.mdx
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,10 @@ description: Examples that demonstrate how to write unit tests and integration
10
10
11
11
Recipes are examples that help demonstrate how to write unit tests and integration tests for Workers projects using the [`@cloudflare/vitest-pool-workers`](https://www.npmjs.com/package/@cloudflare/vitest-pool-workers) package.
12
12
13
-
-[Basic unit and integration tests using `SELF`](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/basics-unit-integration-self)
13
+
-[Basic unit and integration tests for Workers using `SELF`](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/basics-unit-integration-self)
14
+
-[Basic unit and integration tests for Pages function using `SELF`](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/pages-functions-unit-integration-self)
14
15
-[Basic integration tests using an auxiliary Worker](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/basics-integration-auxiliary)
15
-
-[Basic integration test for a Worker with static assets](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/workers-assets)
16
+
-[Basic integration test for Workers with static assets](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/workers-assets)
16
17
-[Isolated tests using KV, R2 and the Cache API](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/kv-r2-caches)
17
18
-[Isolated tests using D1 with migrations](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/d1)
18
19
-[Isolated tests using Durable Objects with direct access](https://github.com/cloudflare/workers-sdk/tree/main/fixtures/vitest-pool-workers-examples/durable-objects)
0 commit comments