-
Notifications
You must be signed in to change notification settings - Fork 1
/
karma.mc.config.js
350 lines (341 loc) · 11.3 KB
/
karma.mc.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const path = require("path");
const webpack = require("webpack");
const { ResourceUriPlugin } = require("./tools/resourceUriPlugin");
const PATHS = {
// Where is the entry point for the unit tests?
testEntryFile: path.resolve(__dirname, "test/unit/unit-entry.js"),
// A glob-style pattern matching all unit tests
testFilesPattern: "test/unit/**/*.js",
// The base directory of all source files (used for path resolution in webpack importing)
moduleResolveDirectory: __dirname,
// a RegEx matching all Cu.import statements of local files
resourcePathRegEx: /^resource:\/\/activity-stream\//,
coverageReportingPath: "logs/coverage/",
};
// When tweaking here, be sure to review the docs about the execution ordering
// semantics of the preprocessors array, as they are somewhat odd.
const preprocessors = {};
preprocessors[PATHS.testFilesPattern] = [
"webpack", // require("karma-webpack")
"sourcemap", // require("karma-sourcemap-loader")
];
module.exports = function(config) {
const isTDD = config.tdd;
const browsers = isTDD ? ["Firefox"] : ["FirefoxHeadless"]; // require("karma-firefox-launcher")
config.set({
singleRun: !isTDD,
browsers,
customLaunchers: {
FirefoxHeadless: {
base: "Firefox",
flags: ["--headless"],
},
},
frameworks: [
"chai", // require("chai") require("karma-chai")
"mocha", // require("mocha") require("karma-mocha")
"sinon", // require("sinon") require("karma-sinon")
],
reporters: [
"coverage-istanbul", // require("karma-coverage")
"mocha", // require("karma-mocha-reporter")
// for bin/try-runner.js to parse the output easily
"json", // require("karma-json-reporter")
],
jsonReporter: {
// So this doesn't get interleaved with other karma output
stdout: false,
outputFile: path.join("logs", "karma-run-results.json"),
},
coverageIstanbulReporter: {
reports: ["lcov", "text-summary"], // for some reason "lcov" reallys means "lcov" and "html"
"report-config": {
// so the full m-c path gets printed; needed for https://coverage.moz.tools/ integration
lcov: {
projectRoot: "../../..",
},
},
dir: PATHS.coverageReportingPath,
// This will make karma fail if coverage reporting is less than the minimums here
thresholds: !isTDD && {
each: {
statements: 100,
lines: 100,
functions: 100,
branches: 66,
overrides: {
"lib/AboutPreferences.jsm": {
statements: 98,
lines: 98,
functions: 100,
branches: 66,
},
"lib/ASRouter.jsm": {
statements: 75,
lines: 75,
functions: 64,
branches: 66,
},
"lib/ASRouterDefaultConfig.jsm": {
statements: 0,
lines: 0,
functions: 0,
branches: 0,
},
"content-src/asrouter/asrouter-utils.js": {
statements: 66,
lines: 66,
functions: 100,
branches: 63,
},
"lib/TelemetryFeed.jsm": {
statements: 99,
lines: 99,
functions: 100,
branches: 95,
},
"lib/ASRouterParentProcessMessageHandler.jsm": {
statements: 98,
lines: 98,
functions: 100,
branches: 88,
},
"content-src/lib/init-store.js": {
statements: 98,
lines: 98,
functions: 100,
branches: 100,
},
"lib/ActivityStreamStorage.jsm": {
statements: 100,
lines: 100,
functions: 100,
branches: 83,
},
"lib/PlacesFeed.jsm": {
statements: 98,
lines: 98,
functions: 100,
branches: 84,
},
"lib/UTEventReporting.jsm": {
statements: 100,
lines: 100,
functions: 100,
branches: 75,
},
"lib/TopSitesFeed.jsm": {
statements: 70,
lines: 75,
functions: 80,
branches: 60,
},
"lib/Screenshots.jsm": {
statements: 94,
lines: 94,
functions: 100,
branches: 84,
},
"lib/DownloadsManager.jsm": {
statements: 100,
lines: 100,
functions: 100,
branches: 78,
},
"lib/*.jsm": {
statements: 100,
lines: 100,
functions: 100,
branches: 84,
},
"content-src/components/DiscoveryStreamComponents/CardGrid/CardGrid.jsx": {
statements: 87.5,
lines: 87.5,
functions: 85.71,
branches: 61.9,
},
"content-src/components/DiscoveryStreamComponents/**/*.jsx": {
statements: 90.48,
lines: 90.48,
functions: 85.71,
branches: 68.75,
},
"content-src/asrouter/**/*.jsx": {
statements: 57,
lines: 58,
functions: 60,
branches: 50,
},
"content-src/components/ASRouterAdmin/*.jsx": {
statements: 0,
lines: 0,
functions: 0,
branches: 0,
},
"content-src/components/CustomizeMenu/**/*.jsx": {
statements: 0,
lines: 0,
functions: 0,
branches: 0,
},
"content-src/components/CustomizeMenu/*.jsx": {
statements: 0,
lines: 0,
functions: 0,
branches: 0,
},
"content-src/lib/aboutwelcome-utils.js": {
statements: 50,
lines: 50,
functions: 100,
branches: 0,
},
"content-src/lib/link-menu-options.js": {
statements: 96,
lines: 96,
functions: 96,
branches: 70,
},
"content-src/aboutwelcome/components/LanguageSwitcher.jsx": {
// This file is covered by the mochitest: browser_aboutwelcome_multistage_languageSwitcher.js
statements: 0,
lines: 0,
functions: 0,
branches: 0,
},
"content-src/aboutwelcome/**/*.jsx": {
statements: 62,
lines: 60,
functions: 50,
branches: 50,
},
"content-src/components/**/*.jsx": {
statements: 51.1,
lines: 52.38,
functions: 31.2,
branches: 31.2,
},
},
},
},
},
files: [PATHS.testEntryFile],
preprocessors,
webpack: {
mode: "none",
devtool: "inline-source-map",
// This loader allows us to override required files in tests
resolveLoader: {
alias: { inject: path.join(__dirname, "loaders/inject-loader") },
},
// This resolve config allows us to import with paths relative to the root directory, e.g. "lib/ActivityStream.jsm"
resolve: {
extensions: [".js", ".jsx"],
modules: [PATHS.moduleResolveDirectory, "node_modules"],
fallback: {
stream: require.resolve("stream-browserify"),
buffer: require.resolve("buffer"),
},
},
plugins: [
// The ResourceUriPlugin handles translating resource URIs in import
// statements in .mjs files, in a similar way to what
// babel-jsm-to-commonjs does for jsm files.
new ResourceUriPlugin({
resourcePathRegEx: PATHS.resourcePathRegEx,
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("development"),
}),
],
externals: {
// enzyme needs these for backwards compatibility with 0.13.
// see https://github.com/airbnb/enzyme/blob/master/docs/guides/webpack.md#using-enzyme-with-webpack
"react/addons": true,
"react/lib/ReactContext": true,
"react/lib/ExecutionEnvironment": true,
},
module: {
rules: [
// This rule rewrites importing/exporting in .jsm files to be compatible with esmodules
{
test: /\.jsm$/,
exclude: [/node_modules/],
use: [
{
loader: "babel-loader", // require("babel-core")
options: {
plugins: [
// Converts .jsm files into common-js modules
[
"./tools/babel-jsm-to-commonjs.js",
{
basePath: PATHS.resourcePathRegEx,
removeOtherImports: true,
replace: true,
},
],
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-class-properties",
],
},
},
],
},
{
test: /\.js$/,
exclude: [/node_modules\/(?!(fluent|fluent-react)\/).*/, /test/],
loader: "babel-loader",
options: {
// This is a workaround for bug 1787278. It can be removed once
// that bug is fixed.
plugins: ["@babel/plugin-proposal-optional-chaining"],
},
},
{
test: /\.jsx$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
presets: ["@babel/preset-react"],
plugins: [
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining",
],
},
},
{
test: /\.md$/,
use: "raw-loader",
},
{
enforce: "post",
test: /\.js[mx]?$/,
loader: "istanbul-instrumenter-loader",
options: { esModules: true },
include: [
path.resolve("content-src"),
path.resolve("lib"),
path.resolve("common"),
],
exclude: [
path.resolve("test"),
path.resolve("vendor"),
path.resolve("lib/ASRouterTargeting.jsm"),
path.resolve("lib/ASRouterTriggerListeners.jsm"),
path.resolve("lib/OnboardingMessageProvider.jsm"),
path.resolve("lib/CFRMessageProvider.jsm"),
path.resolve("lib/CFRPageActions.jsm"),
],
},
],
},
},
// Silences some overly-verbose logging of individual module builds
webpackMiddleware: { noInfo: true },
});
};