-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathweb-test-runner.config.mjs
71 lines (66 loc) · 2.16 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
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import { legacyPlugin } from "@web/dev-server-legacy";
import { playwrightLauncher } from "@web/test-runner-playwright";
import { esbuildPlugin } from "@web/dev-server-esbuild";
const mode = process.env.MODE || "dev";
if (!["dev", "prod"].includes(mode)) {
throw new Error(`MODE must be "dev" or "prod", was "${mode}"`);
}
const browsers = {
// Local browser testing via playwright
// ===========
chromium: playwrightLauncher({ product: "chromium" }),
firefox: playwrightLauncher({ product: "firefox" }),
webkit: playwrightLauncher({ product: "webkit" }),
};
// Prepend BROWSERS=x,y to `npm run test` to run a subset of browsers
// e.g. `BROWSERS=chromium,firefox npm run test`
const noBrowser = (b) => {
throw new Error(`No browser configured named '${b}'; using defaults`);
};
let commandLineBrowsers;
try {
commandLineBrowsers = process.env.BROWSERS?.split(",").map(
(b) => browsers[b] ?? noBrowser(b)
);
} catch (e) {
console.warn(e);
}
// https://modern-web.dev/docs/test-runner/cli-and-configuration/
export default {
rootDir: ".",
files: ["./build/test/**/*_test.js"],
nodeResolve: { exportConditions: mode === "dev" ? ["development"] : [] },
preserveSymlinks: true,
browsers: commandLineBrowsers ?? Object.values(browsers),
testFramework: {
// https://mochajs.org/api/mocha
config: {
ui: "tdd",
},
},
plugins: [
// Detect browsers without modules (e.g. IE11) and transform to SystemJS
// (https://modern-web.dev/docs/dev-server/plugins/legacy/).
legacyPlugin({
polyfills: {
webcomponents: true,
// Inject lit's polyfill-support module into test files, which is required
// for interfacing with the webcomponents polyfills
custom: [
{
name: "lit-polyfill-support",
path: "node_modules/lit/polyfill-support.js",
test: "!('attachShadow' in Element.prototype) || !('getRootNode' in Element.prototype) || window.ShadyDOM && window.ShadyDOM.force",
module: false,
},
],
},
}),
esbuildPlugin({ ts: true }),
],
};