-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathbase.mjs
More file actions
64 lines (60 loc) · 2.36 KB
/
base.mjs
File metadata and controls
64 lines (60 loc) · 2.36 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
import { join } from 'node:path';
import { LWC_VERSION } from '@lwc/shared';
import * as options from '../helpers/options.mjs';
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',
]),
LWC_VERSION,
NODE_ENV: options.NODE_ENV_FOR_TEST,
};
/** @type {import("@web/test-runner").TestRunnerConfig} */
export default {
nodeResolve: true,
rootDir: join(import.meta.dirname, '..'),
plugins: [
{
resolveImport({ source }) {
if (source === 'test-utils') {
return '/helpers/utils.mjs';
} else if (source === 'wire-service') {
// `/__wds-outside-roout__/${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>
<script type="module">
globalThis.process = ${JSON.stringify({ env })};
globalThis.lwcRuntimeFlags = ${JSON.stringify(
pluck(options, ['DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE'])
)};
${maybeImport('@lwc/synthetic-shadow', !options.DISABLE_SYNTHETIC)}
${maybeImport('@lwc/aria-reflection', options.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL)}
</script>
<script type="module" src="./helpers/setup.mjs"></script>
<script type="module" src="${testFramework}"></script>
</head>
</html>`,
};