-
Notifications
You must be signed in to change notification settings - Fork 132
/
vitest.config.mjs
98 lines (93 loc) · 2.49 KB
/
vitest.config.mjs
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
import { defineConfig } from "vitest/config";
import { promises as fs } from "fs";
// https://github.com/tachibana-shin/vite-plugin-arraybuffer/blob/main/src/main.ts
function vitePluginArraybuffer() {
return {
name: "array-buffer-loader",
async load(id) {
if (id.endsWith("?arraybuffer")) {
const filePath = id.replace(/\?arraybuffer$/, "");
const fileBuffer = await fs.readFile(filePath);
return {
code: `export default new Uint8Array([${new Uint8Array(fileBuffer).join(",")}]).buffer`,
map: { mappings: "" },
};
}
},
};
}
function getBrowserConfig(browser) {
switch (browser) {
case "chrome":
return {
enabled: true,
name: "chrome",
provider: "webdriverio",
headless: true,
providerOptions: {
capabilities: {
"goog:chromeOptions": {
args: [
"--autoplay-policy=no-user-gesture-required",
"--enable-precise-memory-info",
"--js-flags=--expose-gc",
],
},
},
},
};
case "firefox":
return {
enabled: true,
name: "firefox",
provider: "webdriverio",
headless: true,
providerOptions: {
capabilities: {
"moz:firefoxOptions": {
prefs: {
"media.autoplay.default": 0,
"media.autoplay.enabled.user-gestures-needed": false,
"media.autoplay.block-webaudio": false,
"media.autoplay.ask-permission": false,
"media.autoplay.block-event.enabled": false,
"media.block-autoplay-until-in-foreground": false,
},
},
},
},
};
default:
return {
enabled: false,
};
}
}
export default defineConfig({
plugins: [vitePluginArraybuffer()],
define: {
// global variables
__TEST_CONTENT_SERVER__: {
URL: "127.0.0.1",
PORT: 3000,
},
__ENVIRONMENT__: {
PRODUCTION: 0,
DEV: 1,
CURRENT_ENV: 1,
},
__LOGGER_LEVEL__: {
CURRENT_LEVEL: '"NONE"',
},
__BROWSER_NAME__: JSON.stringify(process.env.BROWSER_CONFIG),
},
test: {
watch: false,
globals: false,
reporters: "dot",
include: ["tests/**/*.[jt]s?(x)"],
exclude: ["tests/performance/**/*.[jt]s?(x)"],
globalSetup: "tests/contents/server.mjs",
browser: getBrowserConfig(process.env.BROWSER_CONFIG),
},
});