-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathvitest.config.mts
More file actions
99 lines (91 loc) · 2.1 KB
/
Copy pathvitest.config.mts
File metadata and controls
99 lines (91 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { cloudflareTest } from "@cloudflare/vitest-pool-workers";
import { defineConfig } from "vitest/config";
// Stub Worker A - Returns HTML with asset references for testing URL rewriting
const workerAScript = /* javascript */ `
export default {
async fetch(request) {
const url = new URL(request.url);
const html = \`<!DOCTYPE html>
<html>
<head>
<title>Worker A</title>
<link rel="stylesheet" href="/assets/style.css">
<link rel="icon" href="/favicon.ico">
</head>
<body>
<h1>Worker A</h1>
<p>Path: \${url.pathname}</p>
<img src="/assets/logo.png" alt="Logo">
<script src="/static/app.js"></script>
</body>
</html>\`;
return new Response(html, {
headers: { "Content-Type": "text/html" },
});
},
};
`;
// Stub Worker B - Returns HTML and handles redirects/cookies for testing
const workerBScript = /* javascript */ `
export default {
async fetch(request) {
const url = new URL(request.url);
// Test redirect handling
if (url.pathname === "/redirect-test") {
return new Response(null, {
status: 302,
headers: { Location: "/redirected" },
});
}
// Test cookie path handling
if (url.pathname === "/set-cookie") {
return new Response("Cookie set", {
headers: { "Set-Cookie": "session=abc123; Path=/" },
});
}
const html = \`<!DOCTYPE html>
<html>
<head>
<title>Worker B</title>
<link rel="stylesheet" href="/build/style.css">
</head>
<body>
<h1>Worker B</h1>
<p>Path: \${url.pathname}</p>
<img src="/assets/image.png" alt="Image">
</body>
</html>\`;
return new Response(html, {
headers: { "Content-Type": "text/html" },
});
},
};
`;
export default defineConfig({
plugins: [
cloudflareTest({
wrangler: {
configPath: "./wrangler.jsonc",
},
miniflare: {
workers: [
{
name: "worker-a",
modules: [
{ type: "ESModule", path: "index.js", contents: workerAScript },
],
compatibilityDate: "2024-01-01",
},
{
name: "worker-b",
modules: [
{ type: "ESModule", path: "index.js", contents: workerBScript },
],
compatibilityDate: "2024-01-01",
},
],
},
}),
],
test: {},
});