forked from sbb-design-systems/lyne-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web-test-runner.config.js
111 lines (102 loc) · 3.66 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { defaultReporter } from '@web/test-runner';
import { playwrightLauncher } from '@web/test-runner-playwright';
import { puppeteerLauncher } from '@web/test-runner-puppeteer';
import { a11ySnapshotPlugin } from '@web/test-runner-commands/plugins';
import * as sass from 'sass';
import { cpus } from 'node:os';
import {
minimalReporter,
patchedSummaryReporter,
ssrPlugin,
vitePlugin,
} from './tools/web-test-runner/index.js';
const isCIEnvironment = !!process.env.CI || process.argv.includes('--ci');
const isDebugMode = process.argv.includes('--debug');
const firefox = process.argv.includes('--firefox');
const webkit = process.argv.includes('--webkit');
const concurrency = process.argv.includes('--parallel') ? {} : { concurrency: 1 };
const stylesCompiler = new sass.initCompiler();
const renderStyles = () =>
stylesCompiler.compile('./src/components/core/styles/standard-theme.scss', {
loadPaths: ['.', './node_modules/'],
}).css;
const browsers = isCIEnvironment
? [
// Parallelism has problems, we need force concurrency to 1
playwrightLauncher({ product: 'chromium', ...concurrency }),
playwrightLauncher({ product: 'firefox', ...concurrency }),
playwrightLauncher({ product: 'webkit', ...concurrency }),
]
: firefox
? [playwrightLauncher({ product: 'firefox' })]
: webkit
? [playwrightLauncher({ product: 'webkit' })]
: isDebugMode
? [
puppeteerLauncher({
launchOptions: { headless: false, devtools: true },
...concurrency,
}),
]
: [playwrightLauncher({ product: 'chromium' })];
const groupNameOverride = process.argv.includes('--ssr-hydrated')
? 'e2e-ssr-hydrated'
: process.argv.includes('--ssr-non-hydrated')
? 'e2e-ssr-non-hydrated'
: null;
const testRunnerHtml = (testFramework, _config, group) => `
<!DOCTYPE html>
<html>
<head>
<style type="text/css">${renderStyles()}</style>
<script>
globalThis.testEnv = '${isDebugMode ? 'debug' : ''}';
globalThis.testGroup = '${groupNameOverride ?? group?.name ?? 'default'}';
</script>
</head>
<body class="sbb-disable-animation">
<script type="module" src="/src/components/core/testing/test-setup.ts"></script>
<script type="module" src="${testFramework}"></script>
</body>
</html>
`;
// Slow down fast cpus to not run into too much fetches
function resolveConcurrency() {
const localCpus = cpus();
const factor = localCpus.some((el) => el.model.includes('Apple M')) ? 4 : 2;
return Math.floor(localCpus.length / factor);
}
// A list of log messages, that should not be printed to the test console.
const suppressedLogs = [
'Lit is in dev mode. Not recommended for production! See https://lit.dev/msg/dev-mode for more information.',
'[vite] connecting...',
];
/** @type {import('@web/test-runner').TestRunnerConfig} */
export default {
files: ['src/**/*.{e2e,spec}.ts'],
groups: [
// Disable ssr tests until stabilized.
// { name: 'e2e-ssr-hydrated', files: 'src/**/*.e2e.ts', testRunnerHtml },
// { name: 'e2e-ssr-non-hydrated', files: 'src/**/*.e2e.ts', testRunnerHtml },
],
nodeResolve: true,
concurrency: resolveConcurrency(),
reporters:
isDebugMode || !isCIEnvironment
? [defaultReporter(), patchedSummaryReporter()]
: [minimalReporter()],
browsers: browsers,
plugins: [a11ySnapshotPlugin(), ssrPlugin(), vitePlugin()],
testFramework: {
config: {
timeout: '10000',
slow: '1000',
failZero: true,
},
},
coverageConfig: {
exclude: ['**/node_modules/**/*', '**/assets/*.svg', '**/*.scss'],
},
filterBrowserLogs: (log) => !suppressedLogs.includes(log.args[0]),
testRunnerHtml,
};