-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.browser.config.ts
More file actions
90 lines (84 loc) · 2.67 KB
/
Copy pathvitest.browser.config.ts
File metadata and controls
90 lines (84 loc) · 2.67 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
import { defineConfig } from "vitest/config";
import { playwright } from "@vitest/browser-playwright";
import { readFileSync } from "fs";
import { resolve, dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
function resolveTsFromJs() {
return {
name: "resolve-ts-from-js",
resolveId(source: string, importer: string | undefined) {
if (!source.endsWith(".js") || !importer) return null;
const tsPath = source.replace(/\.js$/, ".ts");
const resolved = resolve(dirname(importer), tsPath);
try {
readFileSync(resolved);
return resolved;
} catch {
return null;
}
},
};
}
function stringPlugin() {
return {
name: "string",
transform(code: string, id: string) {
if (id.endsWith(".proto")) {
return { code: `export default ${JSON.stringify(code)};`, map: null };
}
},
};
}
function curveNodeShimPlugin() {
const wasmJsPath = resolve(__dirname, "build", "curve25519_compiled.js");
return {
name: "curve-node-shim",
resolveId(id: string) {
if (id.includes("curve25519_compiled") && !id.endsWith(".wasm")) {
return wasmJsPath;
}
return null;
},
load(id: string) {
if (id === wasmJsPath) {
const js = readFileSync(wasmJsPath, "utf8");
return js.replace(
"scriptDirectory = __dirname + '/';",
`scriptDirectory = new URL('.', import.meta.url).pathname + '/';`
);
}
return null;
},
};
}
export default defineConfig({
plugins: [resolveTsFromJs(), stringPlugin(), curveNodeShimPlugin()],
test: {
globals: true,
include: ["test/**/*.ts"],
exclude: [
"test/support/**",
"test/utils.ts",
"test/testvectors.ts",
"test/omemo2-vector.ts",
// Node-only: writes a capture artifact via node:fs (manual, gated).
"test/omemo2-sender-capture.test.ts",
"test/identity-key-store.ts",
"test/prekey-store.ts",
"test/session-store.ts",
"test/signed-prekey-store.ts",
],
setupFiles: ["test/support/vitest-setup.ts"],
testTimeout: 20000,
browser: {
enabled: true,
provider: playwright(),
instances: [{ browser: "chromium" }],
headless: true,
},
},
esbuild: {
target: "es2020",
},
});