-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathplugin.ts
More file actions
45 lines (37 loc) · 1.2 KB
/
plugin.ts
File metadata and controls
45 lines (37 loc) · 1.2 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
import type { Vite } from "vitest/node";
import { readDirectory } from "./commands";
const COEP = "Cross-Origin-Embedder-Policy";
const COOP = "Cross-Origin-Opener-Policy";
/**
* Vitest [plugin](https://vitest.dev/advanced/api/plugin.html#plugin-api) for configuring
* WebContainer related options.
*/
export function vitestWebContainers(): Vite.Plugin {
return {
name: "vitest:webcontainers",
config(config, env) {
if (env.mode !== "test") {
return;
}
config.test ||= {};
config.test.browser ||= {};
config.test.browser.commands ||= {};
config.test.browser.commands.readDirectory = readDirectory;
config.server ||= {};
config.server.headers ||= {};
const headers = config.server.headers;
if (headers[COEP] && headers[COEP] !== "require-corp") {
console.warn(
`[vitest:webcontainers] Overriding ${COEP} header during test run`,
);
}
if (headers[COOP] && headers[COOP] !== "same-origin") {
console.warn(
`[vitest:webcontainers] Overriding ${COOP} header during test run`,
);
}
headers[COEP] = "require-corp";
headers[COOP] = "same-origin";
},
};
}