Skip to content

Commit 32cd576

Browse files
[fixtures] Extend vitest.shared.ts in vitest-pool-workers-examples projects (#13709)
1 parent 87b094e commit 32cd576

28 files changed

Lines changed: 557 additions & 469 deletions

File tree

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
2-
import { defineConfig } from "vitest/config";
2+
import { defineProject, mergeConfig } from "vitest/config";
3+
import configShared from "../../../vitest.shared";
34

4-
export default defineConfig({
5-
plugins: [
6-
cloudflareTest({
7-
remoteBindings: false,
8-
wrangler: { configPath: "./wrangler.jsonc" },
9-
}),
10-
],
11-
12-
test: {
13-
globalSetup: ["./global-setup.ts"],
14-
},
15-
});
5+
export default mergeConfig(
6+
configShared,
7+
defineProject({
8+
plugins: [
9+
cloudflareTest({
10+
remoteBindings: false,
11+
wrangler: { configPath: "./wrangler.jsonc" },
12+
}),
13+
],
14+
test: {
15+
globalSetup: ["./global-setup.ts"],
16+
},
17+
})
18+
);
Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
11
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
2-
import { defineConfig } from "vitest/config";
2+
import { defineProject, mergeConfig } from "vitest/config";
3+
import configShared from "../../../vitest.shared";
34

4-
export default defineConfig({
5-
plugins: [
6-
cloudflareTest({
7-
miniflare: {
8-
// Configuration for the test runner Worker
9-
compatibilityDate: "2024-01-01",
10-
compatibilityFlags: [
11-
// This illustrates a Worker that in production only wants v1 of Node.js compatibility.
12-
// The Vitest pool integration will need to remove this flag since the `MockAgent` requires v2.
13-
"no_nodejs_compat_v2",
14-
"nodejs_compat",
15-
// Required to use `WORKER.scheduled()`. This is an experimental
16-
// compatibility flag, and cannot be enabled in production.
17-
"service_binding_extra_handlers",
18-
],
19-
serviceBindings: {
20-
WORKER: "worker-under-test",
21-
},
22-
23-
workers: [
24-
// Configuration for the "auxiliary" Worker under test.
25-
// Unfortunately, auxiliary Workers cannot load their configuration
26-
// from `wrangler.toml` files, and must be configured with Miniflare
27-
// `WorkerOptions`.
28-
{
29-
name: "worker-under-test",
30-
modules: true,
31-
scriptPath: "./dist/index.js", // Built by `global-setup.ts`
32-
compatibilityDate: "2024-01-01",
33-
compatibilityFlags: ["nodejs_compat"],
5+
export default mergeConfig(
6+
configShared,
7+
defineProject({
8+
plugins: [
9+
cloudflareTest({
10+
miniflare: {
11+
// Configuration for the test runner Worker
12+
compatibilityDate: "2024-01-01",
13+
compatibilityFlags: [
14+
// This illustrates a Worker that in production only wants v1 of Node.js compatibility.
15+
// The Vitest pool integration will need to remove this flag since the `MockAgent` requires v2.
16+
"no_nodejs_compat_v2",
17+
"nodejs_compat",
18+
// Required to use `WORKER.scheduled()`. This is an experimental
19+
// compatibility flag, and cannot be enabled in production.
20+
"service_binding_extra_handlers",
21+
],
22+
serviceBindings: {
23+
WORKER: "worker-under-test",
3424
},
35-
],
36-
},
37-
}),
38-
],
3925

40-
test: {
41-
globalSetup: ["./global-setup.ts"],
42-
},
43-
});
26+
workers: [
27+
// Configuration for the "auxiliary" Worker under test.
28+
// Unfortunately, auxiliary Workers cannot load their configuration
29+
// from `wrangler.toml` files, and must be configured with Miniflare
30+
// `WorkerOptions`.
31+
{
32+
name: "worker-under-test",
33+
modules: true,
34+
scriptPath: "./dist/index.js", // Built by `global-setup.ts`
35+
compatibilityDate: "2024-01-01",
36+
compatibilityFlags: ["nodejs_compat"],
37+
},
38+
],
39+
},
40+
}),
41+
],
42+
test: {
43+
globalSetup: ["./global-setup.ts"],
44+
},
45+
})
46+
);
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
2-
import { defineConfig } from "vitest/config";
2+
import { defineProject, mergeConfig } from "vitest/config";
3+
import configShared from "../../../vitest.shared";
34

4-
export default defineConfig({
5-
plugins: [
6-
cloudflareTest({
7-
miniflare: {
8-
// Required to use `exports.default.scheduled()`. This is an experimental
9-
// compatibility flag, and cannot be enabled in production.
10-
compatibilityFlags: ["service_binding_extra_handlers"],
11-
},
12-
wrangler: {
13-
configPath: "./wrangler.jsonc",
14-
},
15-
}),
16-
],
17-
18-
test: {},
19-
});
5+
export default mergeConfig(
6+
configShared,
7+
defineProject({
8+
plugins: [
9+
cloudflareTest({
10+
miniflare: {
11+
// Required to use `exports.default.scheduled()`. This is an experimental
12+
// compatibility flag, and cannot be enabled in production.
13+
compatibilityFlags: ["service_binding_extra_handlers"],
14+
},
15+
wrangler: {
16+
configPath: "./wrangler.jsonc",
17+
},
18+
}),
19+
],
20+
})
21+
);
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
2-
import { defineConfig } from "vitest/config";
2+
import { defineProject, mergeConfig } from "vitest/config";
3+
import configShared from "../../../vitest.shared";
34

4-
export default defineConfig({
5-
plugins: [
6-
cloudflareTest({
7-
wrangler: { configPath: "./wrangler.jsonc" },
8-
}),
9-
],
10-
11-
test: {},
12-
});
5+
export default mergeConfig(
6+
configShared,
7+
defineProject({
8+
plugins: [
9+
cloudflareTest({
10+
wrangler: { configPath: "./wrangler.jsonc" },
11+
}),
12+
],
13+
})
14+
);
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
2-
import { defineConfig } from "vitest/config";
2+
import { defineProject, mergeConfig } from "vitest/config";
3+
import configShared from "../../../vitest.shared";
34

45
// Configuration for the "auxiliary" Worker under test.
56
// Unfortunately, auxiliary Workers cannot load their configuration
@@ -16,26 +17,28 @@ export const auxiliaryWorker = {
1617
},
1718
};
1819

19-
export default defineConfig({
20-
plugins: [
21-
cloudflareTest({
22-
wrangler: { configPath: "./src/wrangler.jsonc" },
23-
miniflare: {
24-
workers: [auxiliaryWorker],
20+
export default mergeConfig(
21+
configShared,
22+
defineProject({
23+
plugins: [
24+
cloudflareTest({
25+
wrangler: { configPath: "./src/wrangler.jsonc" },
26+
miniflare: {
27+
workers: [auxiliaryWorker],
28+
},
29+
additionalExports: {
30+
// This entrypoint is wildcard re-exported from a virtual module so we cannot automatically infer it.
31+
ConfiguredVirtualEntryPoint: "WorkerEntrypoint",
32+
},
33+
}),
34+
],
35+
test: {
36+
globalSetup: ["./global-setup.ts"],
37+
alias: {
38+
// This alias is used to simulate a virtual module that Vitest and TypeScript can understand,
39+
// but esbuild (used by the vitest-pool-workers to guess exports) cannot.
40+
"@virtual-module": "./virtual.ts",
2541
},
26-
additionalExports: {
27-
// This entrypoint is wildcard re-exported from a virtual module so we cannot automatically infer it.
28-
ConfiguredVirtualEntryPoint: "WorkerEntrypoint",
29-
},
30-
}),
31-
],
32-
33-
test: {
34-
globalSetup: ["./global-setup.ts"],
35-
alias: {
36-
// This alias is used to simulate a virtual module that Vitest and TypeScript can understand,
37-
// but esbuild (used by the vitest-pool-workers to guess exports) cannot.
38-
"@virtual-module": "./virtual.ts",
3942
},
40-
},
41-
});
43+
})
44+
);

fixtures/vitest-pool-workers-examples/d1/vitest.config.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@ import {
33
cloudflareTest,
44
readD1Migrations,
55
} from "@cloudflare/vitest-pool-workers";
6-
import { defineConfig } from "vitest/config";
6+
import { defineConfig, defineProject, mergeConfig } from "vitest/config";
7+
import configShared from "../../../vitest.shared";
78

89
export default defineConfig(async () => {
910
// Read all migrations in the `migrations` directory
1011
const migrationsPath = path.join(__dirname, "migrations");
1112
const migrations = await readD1Migrations(migrationsPath);
1213

13-
return {
14-
plugins: [
15-
cloudflareTest({
16-
wrangler: {
17-
configPath: "./wrangler.jsonc",
18-
environment: "production",
19-
},
20-
miniflare: {
21-
// Add a test-only binding for migrations, so we can apply them in a
22-
// setup file
23-
bindings: { TEST_MIGRATIONS: migrations },
24-
},
25-
}),
26-
],
27-
test: {
28-
setupFiles: ["./test/apply-migrations.ts"],
29-
},
30-
};
14+
return mergeConfig(
15+
configShared,
16+
defineProject({
17+
plugins: [
18+
cloudflareTest({
19+
wrangler: {
20+
configPath: "./wrangler.jsonc",
21+
environment: "production",
22+
},
23+
miniflare: {
24+
// Add a test-only binding for migrations, so we can apply them in a
25+
// setup file
26+
bindings: { TEST_MIGRATIONS: migrations },
27+
},
28+
}),
29+
],
30+
test: {
31+
setupFiles: ["./test/apply-migrations.ts"],
32+
},
33+
})
34+
);
3135
});
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
2-
import { defineConfig } from "vitest/config";
2+
import { defineProject, mergeConfig } from "vitest/config";
3+
import configShared from "../../../vitest.shared";
34

4-
export default defineConfig({
5-
plugins: [
6-
cloudflareTest({
7-
wrangler: {
8-
configPath: "./wrangler.jsonc",
9-
},
10-
}),
11-
],
12-
13-
test: {
14-
name: "@scoped/durable-objects",
15-
},
16-
});
5+
export default mergeConfig(
6+
configShared,
7+
defineProject({
8+
plugins: [
9+
cloudflareTest({
10+
wrangler: {
11+
configPath: "./wrangler.jsonc",
12+
},
13+
}),
14+
],
15+
test: {
16+
name: "@scoped/durable-objects",
17+
},
18+
})
19+
);
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
2-
import { defineConfig } from "vitest/config";
2+
import { defineProject, mergeConfig } from "vitest/config";
3+
import configShared from "../../../vitest.shared";
34

4-
export default defineConfig({
5-
plugins: [
6-
cloudflareTest({
7-
wrangler: {
8-
configPath: "./wrangler.jsonc",
9-
},
10-
}),
11-
],
12-
13-
test: {},
14-
});
5+
export default mergeConfig(
6+
configShared,
7+
defineProject({
8+
plugins: [
9+
cloudflareTest({
10+
wrangler: {
11+
configPath: "./wrangler.jsonc",
12+
},
13+
}),
14+
],
15+
})
16+
);

0 commit comments

Comments
 (0)