forked from adobecom/milo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web-test-runner.config.mjs
105 lines (101 loc) · 4.07 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
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
import { importMapsPlugin } from '@web/dev-server-import-maps';
import { defaultReporter, summaryReporter } from '@web/test-runner';
import { playwrightLauncher } from '@web/test-runner-playwright';
const GITHUB_ACTIONS = process.env.GITHUB_ACTIONS === 'true';
function customReporter() {
return {
async reportTestFileResults({ logger, sessionsForTestFile }) {
sessionsForTestFile.forEach((session) => {
session.testResults.tests.forEach((test) => {
if (!test.passed && !test.skipped) {
logger.log(test);
}
});
});
},
};
}
export default {
playwright: true,
browsers: [
playwrightLauncher({ product: 'chromium', launchOptions: { headless: true } }),
],
coverageConfig: {
include: [
'**/libs/**',
'**/tools/**',
'**/build/**',
],
exclude: [
'**/mocks/**',
'**/node_modules/**',
'**/test/**',
'**/deps/**',
'**/imslib/imslib.min.js',
'**/features/spectrum-web-components/**',
// TODO: folders below need to have tests written for 100% coverage
'**/ui/controls/**',
'**/blocks/library-config/**',
'**/hooks/**',
'**/special/tacocat/**',
'**/libs/martech/martech.js', // ticket to add unit test: https://jira.corp.adobe.com/browse/MWPW-145975
'**/blocks/bulk-publish/**', // this block is not in use
],
},
testFramework: { config: { retries: GITHUB_ACTIONS ? 1 : 0 } },
plugins: [importMapsPlugin({})],
reporters: [
defaultReporter({ reportTestResults: true, reportTestProgress: true }),
customReporter(),
],
testRunnerHtml: (testFramework) => `
<html>
<head>
<link rel="icon" href="/libs/img/favicons/favicon.ico" size="any">
<script type='module'>
const oldFetch = window.fetch;
window.fetch = async (resource, options) => {
if (!resource.startsWith('/') && !resource.startsWith('http://localhost')) {
console.error(
'** fetch request for an external resource is disallowed in unit tests, please find a way to mock! https://github.com/orgs/adobecom/discussions/814#discussioncomment-6060759 provides guidance on how to fix the issue.',
resource
);
}
return oldFetch.call(window, resource, options);
};
const oldXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = async function (...args) {
let [method, url, asyn] = args;
if (!resource.startsWith('/') && url.startsWith('http://localhost')) {
console.error(
'** XMLHttpRequest request for an external resource is disallowed in unit tests, please find a way to mock! https://github.com/orgs/adobecom/discussions/814#discussioncomment-6060759 provides guidance on how to fix the issue.',
url
);
}
return oldXHROpen.apply(this, args);
};
const observer = new MutationObserver((mutationsList, observer) => {
for(let mutation of mutationsList) {
if (mutation.type === 'childList') {
for(let node of mutation.addedNodes) {
if(node.nodeName === 'SCRIPT' && node.src && !node.src.startsWith('http://localhost')) {
console.error(
'** An external 3rd script has been added. This is disallowed in unit tests, please find a way to mock! https://github.com/orgs/adobecom/discussions/814#discussioncomment-6060891 provides guidance on how to fix the issue.',
node.src
);
}
}
}
}
});
observer.observe(document.head, { childList: true });
</script>
</head>
<body>
<script type='module' src='${testFramework}'></script>
</body>
</html>`,
// Comment in the files for selectively running test suites
// npm run test:file:watch allows to you to run single test file & view the result in a browser.
// files: ['**/utils.test.js'],
};