Repository navigation
Expand file tree
/
Copy pathweb-test-runner.config.mjs
More file actions
127 lines (125 loc) · 6.79 KB
/
Copy pathweb-test-runner.config.mjs
File metadata and controls
127 lines (125 loc) · 6.79 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import path from 'node:path';
// When tests are launched from an element directory (cd elements/<name> &&
// yarn test), scope coverage collection to that element's own sources.
// Workspace symlinks pull sibling elements' files (d-d-d, simple-icon, ...)
// into the browser session, and because those resolve to real paths inside
// the monorepo root they land in the coverage report with tiny
// partial-execution percentages that dilute the element's own number.
// When launched from the monorepo root (yarn test:all), keep collecting
// everything so the aggregate stays a true whole-project number.
const cwd = process.cwd();
const relativeToRoot = path.relative(path.resolve(cwd, '../../'), cwd);
const isElementDir =
relativeToRoot.split(path.sep).length === 2 &&
relativeToRoot.split(path.sep)[0] === 'elements';
export default {
concurrency: 5,
// mocha defaults to a 2s timeout per test. Many tests await several axe
// audits back to back (see the a11y-* and accent-card suites), and on a
// shared CI runner with 5 browser pages competing for CPU a single audit
// can occasionally take longer than that. When a test times out its axe
// run is still in flight (axe._running stays true), so the next tests in
// that file fail instantly with "Axe is already running. Use `await
// axe.run()` to wait for the previous run to finish" until the slow run
// completes. That produced a handful of false failures out of ~1000 audits.
// Giving each test generous headroom stops the first timeout, and with it
// the whole cascade. Individual tests can still set a tighter this.timeout.
testFramework: {
config: {
timeout: 10000,
},
},
nodeResolve: true,
// in a monorepo you need to set set the root dir to resolve modules
rootDir: '../../',
// @web/test-runner-coverage-v8 doesn't know how to resolve the
// /__wds-outside-root__/{depth}/... virtual path prefix used for
// monorepo packages living outside of an element's own directory,
// so it throws harmless ENOENT errors trying to read coverage for
// them. Exclude these from coverage collection entirely to silence
// the noise; this doesn't affect coverage of an element's own source.
coverageConfig: {
// only collect the element's own files when testing a single element
...(isElementDir ? { include: [`${cwd}/**`] } : {}),
// vendored third-party builds under lib/*/dist are upstream code, not
// the element's own source, so leave them out of the coverage numbers
exclude: [
'**/__wds-outside-root__/**',
'**/node_modules/**',
'**/lib/*/dist/**',
// lib/vmsg-fork.js (voice-recorder) is a vendored fork whose
// inlineWorker body is stringified into a Blob Worker, so its
// statements are unreachable to coverage instrumentation by
// construction (159 of them); it is upstream-style code, not the
// element's own source (haxtheweb/issues#3101)
'**/lib/vmsg-fork.js',
// lib/marked.js (utils) is a vendored, generated build of the
// upstream `marked` markdown parser library (file header reads
// "DO NOT EDIT THIS FILE - generated from files in ./src/");
// it is not the element's own source, so its internal parsing
// branches shouldn't count toward the package's coverage number
'**/lib/marked.js',
],
},
testRunnerHtml: testFramework =>
`<!DOCTYPE html>
<html lang="en">
<body>
<script>window.process = { env: { NODE_ENV: "development" } }</script>
<script>
// WebKit reports "ResizeObserver loop completed with undelivered
// notifications" as a window error; it is benign (a resize caused
// another resize in the same frame) and was failing unrelated tests
window.addEventListener("error", function (e) {
if (/ResizeObserver loop/.test(e.message || "")) {
e.stopImmediatePropagation();
e.preventDefault();
}
});
</script>
<script>document.body.removeAttribute('no-js');window.__appCDN="./node_modules/";window.__appForceUpgrade=false;</script>
<script>
window.WCAutoloadRegistryFile = "\/elements\/haxcms-elements\/demo\/wc-registry.json";
window.WCAutoloadBasePath = "/node_modules/";
window.WCGlobalBasePath = "/node_modules/";
// set this in order to simulate the published form of the site
//window.HAXCMSContext="published";
// set the below to simulate running a demo / end points to load data
// this will let you simulate more operations without having a backend
window.HAXCMSContext="demo";
window.appSettings = {
"demo": true,
"getSitesList": "sites.json",
"createNodePath": "elements\/haxcms-elements\/demo\/dist\/dev\/createNodePath.json",
"saveOutlinePath": "elements\/haxcms-elements\/demo\/dist\/dev\/saveNode.json",
"saveManifestPath": "elements\/haxcms-elements\/demo\/dist\/dev\/saveManifestPath.json",
"getSiteFieldsPath": "elements\/haxcms-elements\/demo\/dist\/dev\/getSiteFieldsPath.json",
"deleteNodePath": "elements\/haxcms-elements\/demo\/dist\/dev\/saveNode.json",
"saveNodePath": "elements\/haxcms-elements\/demo\/dist\/dev\/saveNode.json",
"getUserDataPath": "elements\/haxcms-elements\/demo\/dist\/dev\/userData.json",
"login": "elements\/haxcms-elements\/demo\/dist\/dev\/login.json",
"refreshUrl": "elements\/haxcms-elements\/demo\/dist\/dev\/refreshUrl.json",
"logout": "elements\/haxcms-elements\/demo\/dist\/dev\/logout.json",
"connectionSettings": "elements\/haxcms-elements\/demo\/dist\/dev\/connectionSettings.json",
"publishSitePath": "elements\/haxcms-elements\/demo\/dist\/dev\/saveNode.json",
"revertSitePath": "elements\/haxcms-elements\/demo\/dist\/dev\/saveNode.json",
"getFieldsToken": "adskjadshjudfu823u823u8fu8fij",
"appStore": {
"url": "dist\/dev\/appstore.json"
},
"jwt": "made-up-thing",
// add your custom theme here if testing locally and wanting to emulate the theme selector
// this isn't really nessecary though
"themes": {
"haxcms-dev-theme": {
"element": "haxcms-dev-theme",
"path": "@haxtheweb/haxcms-elements/lib/haxcms-dev-theme.js",
"name": "Developer theme"
}
}
};
</script>
<script type="module" src="${testFramework}"></script>
</body>
</html>`,
};