-
Notifications
You must be signed in to change notification settings - Fork 6
/
web-test-runner.config.js
91 lines (80 loc) · 3.03 KB
/
web-test-runner.config.js
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
import {symlinkSync, existsSync, unlinkSync, lstatSync} from 'node:fs';
import {relative, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';
import {parseArgs} from 'node:util';
import {chromeLauncher} from '@web/test-runner';
import {esbuildPlugin} from '@web/dev-server-esbuild';
let args = null;
let positionals = null;
try {
({values: args, positionals: positionals} = parseArgs({
options: {
grep: {type: 'string', short: 'g'},
watch: {type: 'boolean', short: 'w'},
deploy: {type: 'string', short: 'd'},
'no-headless': {type: 'boolean', default: false},
},
allowPositionals: true,
}));
} catch (e) {
console.error('Failed to parse command line arguments, reason:', e);
process.exit(1);
}
args.deploy = args.deploy ?? process.env['DEPLOY_FOLDER'] ?? '../../../../deploy/';
/* We need to relink every run in case the env var changed,
* so first remove old link (or old deploy copy) */
if (existsSync('deploy') && lstatSync('deploy').isSymbolicLink()) {
unlinkSync('deploy');
}
const deployRoot = resolve(args.deploy);
if (!lstatSync(deployRoot, {throwIfNoEntry: false})?.isDirectory()) {
console.error(`deploy folder '${deployRoot}' isn't a directory`);
process.exit(1);
}
console.log(`Creating symlink 'deploy' to '${deployRoot}'`);
symlinkSync(deployRoot, 'deploy', 'junction');
/* When running in docker on Ubuntu, headless set to `true` always forces the
* browser to use the SwiftShader backend which we don't want.
*
* The 'new' mode also create animation loop issues, we do not use it. */
const headless = !args['no-headless'];
const Config = {
nodeResolve: true,
files: positionals.length > 0 ? positionals : ['*.test.ts', '!**/node_modules/**/*'],
watch: args.watch,
browsers: [
chromeLauncher({
launchOptions: {
headless,
devtools: false,
args: ['--no-sandbox', '--use-gl=angle', '--ignore-gpu-blocklist']
},
createPage: async ({context}) => {
/* By default, tests are run in separate pages, in the same browser context.
* However, the entire engine relies on RAF, which is throttled in inactive page.
*
* Running in an unfocused tab can cause the animation loop to be stuck (an so our job system).
*
* Creating one browser context per test allows to run tests concurrently without
* having focusing issues. */
return (await context.browser().createIncognitoBrowserContext()).newPage();
},
}),
],
/* Mocha configuration */
testFramework: {
config: {
ui: 'bdd',
timeout: '15000',
allowUncaught: false,
grep: args.grep
},
},
plugins: [
esbuildPlugin({
ts: true,
tsconfig: fileURLToPath(new URL('../api/tsconfig.json', import.meta.url)),
})
],
};
export default Config;