-
Notifications
You must be signed in to change notification settings - Fork 555
/
web-test-runner.config.mjs
72 lines (68 loc) · 1.9 KB
/
web-test-runner.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
import { playwrightLauncher } from '@web/test-runner-playwright';
import { snapshotPlugin } from '@web/test-runner-commands/plugins';
import fs from 'node:fs';
import { glob } from '@bundled-es-modules/glob';
import { readZIP } from './lib/utils/convertToDTCG.js';
/** @type {string[]} */
const globResult = (
await glob(
[
'__tests__/__assets/**/*',
'__tests__/__configs/**/*',
'__tests__/__json_files/**/*',
'__tests__/__tokens/**/*',
'__integration__/tokens/**/*',
],
{
fs,
nodir: true,
posix: true,
},
)
) // sort because for some reason glob result is not sorted like filesystem is (alphabetically)
.sort();
/** @type {[string, Record<string, string> | string][]} */
const fileEntriesToMirror = [];
for (const filePath of globResult) {
/** @type {Record<string, string> | string} */
let fileContents;
// ZIP is binary content, so serialize it to string first..
if (filePath.endsWith('.zip')) {
const buf = await fs.promises.readFile(filePath);
fileContents = await readZIP(new Blob([buf], { type: 'application/zip' }));
} else {
fileContents = await fs.promises.readFile(filePath, 'utf-8');
}
fileEntriesToMirror.push([filePath, fileContents]);
}
export default {
nodeResolve: true,
files: ['__(tests|integration)__/**/*.test.js'],
coverageConfig: {
report: true,
reportDir: 'coverage',
threshold: {
statements: 98,
branches: 99,
functions: 95,
lines: 98,
},
},
browsers: [
playwrightLauncher({
product: 'chromium',
}),
],
plugins: [snapshotPlugin()],
testRunnerHtml: (testFramework) => `<html>
<head>
<script blocking="render" type="module" >
import { setup } from './__tests__/__setup.js';
await setup(${JSON.stringify(fileEntriesToMirror)});
</script>
</head>
<body>
<script type="module" src="${testFramework}"></script>
</body>
</html>`,
};