-
Notifications
You must be signed in to change notification settings - Fork 61
/
karma.conf.js
141 lines (130 loc) · 3.33 KB
/
karma.conf.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const path = require('path');
const coverage = process.argv.find((arg) => arg.includes('coverage'));
const reporters = coverage ? ['mocha', 'coverage-istanbul'] : ['mocha'];
let customLaunchers = {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--disable-gpu', '--no-sandbox'],
},
FirefoxHeadless: {
base: 'Firefox',
flags: ['-headless'],
},
};
if (process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY) {
customLaunchers = {
sl_latest_chrome: {
base: 'SauceLabs',
browserName: 'chrome',
platform: 'Windows 10',
version: 'latest',
},
sl_latest_edge: {
base: 'SauceLabs',
browserName: 'microsoftedge',
platform: 'Windows 10',
version: 'latest',
},
sl_latest_firefox: {
base: 'SauceLabs',
browserName: 'firefox',
platform: 'Windows 10',
version: '98.0',
geckodriverVersion: '0.30.0',
},
sl_latest_safari: {
base: 'SauceLabs',
browserName: 'safari',
platform: 'macOS 12',
version: 'latest',
},
};
reporters.push('saucelabs');
}
module.exports = (config) => {
const sauceLabs = {};
if (config.record) {
sauceLabs.recordVideo = true;
} else if (config.sauceRunName) {
sauceLabs.testName = config.sauceRunName;
}
config.set({
sauceLabs,
hostname: '127.0.0.1',
basePath: '',
singleRun: true,
browsers: config.browsers && config.browsers.length > 0 ? config.browsers : Object.keys(customLaunchers),
browserDisconnectTimeout: 10 * 1000,
browserDisconnectTolerance: 1,
browserNoActivityTimeout: 5 * 60 * 1000,
customLaunchers,
middleware: ['static'],
static: {
path: path.join(process.cwd(), ''),
},
files: [
{
pattern: `test/*${config.grep || '*.test.js'}`,
type: 'module',
},
{
pattern: `addons/*/test/*${config.grep || '*.test.js'}`,
type: 'module',
},
],
plugins: [
// load plugin
require.resolve('@open-wc/karma-esm'),
// fallback: resolve any karma- plugins
'karma-*',
],
frameworks: ['esm', 'mocha', 'sinon-chai', 'source-map-support'],
esm: {
// prevent auto loading of polyfills
compatibility: 'none',
coverage,
// if you are using 'bare module imports' you will need this option
nodeResolve: true,
// needed for npm link or lerna support
preserveSymlinks: true,
},
reporters,
port: 9876,
colors: true,
browserConsoleLogOptions: {
level: 'error',
},
logLevel: config.LOG_WARN,
/** Some errors come in JSON format with a message property. */
formatError(error) {
try {
if (typeof error !== 'string') {
return error;
}
const parsed = JSON.parse(error);
if (typeof parsed !== 'object' || !parsed.message) {
return error;
}
return parsed.message;
} catch (_) {
return error;
}
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly', 'text-summary'],
dir: path.join(__dirname, 'coverage'),
combineBrowserReports: true,
skipFilesWithNoCoverage: true,
},
client: {
mocha: {
reporter: 'html',
ui: 'tdd',
timeout: 3000,
},
chai: {
includeStack: true,
},
},
});
};