-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathweb-test-runner.config.js
68 lines (63 loc) · 1.99 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
/**
* @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'
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' })
}
// 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: ['./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
}
]
}
})
]
}