-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathbase.js
More file actions
78 lines (74 loc) · 3.27 KB
/
base.js
File metadata and controls
78 lines (74 loc) · 3.27 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
import { join } from 'node:path';
import { LWC_VERSION } from '@lwc/shared';
import { importMapsPlugin } from '@web/dev-server-import-maps';
import * as options from '../helpers/options.js';
const pluck = (obj, keys) => Object.fromEntries(keys.map((k) => [k, obj[k]]));
const maybeImport = (file, condition) => (condition ? `await import('${file}');` : '');
/** `process.env` to inject into test environment. */
const env = {
...pluck(options, [
'API_VERSION',
'DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE',
'DISABLE_STATIC_CONTENT_OPTIMIZATION',
'DISABLE_SYNTHETIC',
'ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL',
'ENABLE_SYNTHETIC_SHADOW_IN_HYDRATION',
'ENGINE_SERVER',
'FORCE_NATIVE_SHADOW_MODE_FOR_TEST',
'NATIVE_SHADOW',
'DISABLE_DETACHED_REHYDRATION',
]),
LWC_VERSION,
NODE_ENV: options.NODE_ENV_FOR_TEST,
};
/** @type {import("@web/test-runner").TestRunnerConfig} */
export default {
// FIXME: Parallelism breaks tests that rely on focus/requestAnimationFrame, because they often
// time out before they receive focus. But it also makes the full suite take 3x longer to run...
// Potential workaround: https://github.com/modernweb-dev/web/issues/2588
concurrency: 1,
filterBrowserLogs: () => false,
nodeResolve: true,
rootDir: join(import.meta.dirname, '..'),
plugins: [
importMapsPlugin({ inject: { importMap: { imports: { lwc: './mocks/lwc.js' } } } }),
{
resolveImport({ source }) {
if (source === 'test-utils') {
return '/helpers/utils.js';
} else if (source === 'wire-service') {
// To serve files outside the web root (e.g. node_modules in the monorepo root),
// @web/dev-server provides this "magic" path. It's hacky of us to use it directly.
// `/__wds-outside-root__/${depth}/` === '../'.repeat(depth)
return '/__wds-outside-root__/1/wire-service/dist/index.js';
}
},
async transform(ctx) {
if (ctx.type === 'application/javascript') {
// FIXME: copy/paste Nolan's spiel about why we do this ugly thing
return ctx.body.replace(/process\.env\.NODE_ENV === 'test-karma-lwc'/g, 'true');
}
},
},
],
testRunnerHtml: (testFramework) =>
`<!DOCTYPE html>
<html>
<head>
<!-- scripts are included in the head so that the body can be fully reset between tests -->
<script type="module">
globalThis.process = ${JSON.stringify({ env })};
globalThis.lwcRuntimeFlags = ${JSON.stringify(
pluck(options, [
'DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE',
'DISABLE_DETACHED_REHYDRATION',
])
)};
${maybeImport('@lwc/synthetic-shadow', !options.DISABLE_SYNTHETIC)}
${maybeImport('@lwc/aria-reflection', options.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL)}
</script>
<script type="module" src="./helpers/setup.js"></script>
<script type="module" src="${testFramework}"></script>
</head>
</html>`,
};