karma.mc.config.js (15635B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const path = require("path"); 6 const webpack = require("webpack"); 7 const { ResourceUriPlugin } = require("../../tools/resourceUriPlugin"); 8 const { MozSrcUriPlugin } = require("../../tools/mozsrcUriPlugin"); 9 10 const PATHS = { 11 // Where is the entry point for the unit tests? 12 testEntryFile: path.resolve(__dirname, "test/unit/unit-entry.js"), 13 14 // A glob-style pattern matching all unit tests 15 testFilesPattern: "test/unit/**/*.js", 16 17 // The base directory of all source files (used for path resolution in webpack importing) 18 moduleResolveDirectory: __dirname, 19 20 // a RegEx matching all Cu.import statements of local files 21 resourcePathRegEx: /^resource:\/\/activity-stream\//, 22 23 coverageReportingPath: "logs/coverage/", 24 }; 25 26 // When tweaking here, be sure to review the docs about the execution ordering 27 // semantics of the preprocessors array, as they are somewhat odd. 28 const preprocessors = {}; 29 preprocessors[PATHS.testFilesPattern] = [ 30 "webpack", // require("karma-webpack") 31 "sourcemap", // require("karma-sourcemap-loader") 32 ]; 33 34 module.exports = function (config) { 35 const isTDD = config.tdd; 36 const browsers = isTDD ? ["Firefox"] : ["FirefoxHeadless"]; // require("karma-firefox-launcher") 37 config.set({ 38 singleRun: !isTDD, 39 browsers, 40 customLaunchers: { 41 FirefoxHeadless: { 42 base: "Firefox", 43 flags: ["--headless"], 44 }, 45 }, 46 frameworks: [ 47 "chai", // require("chai") require("karma-chai") 48 "mocha", // require("mocha") require("karma-mocha") 49 "sinon", // require("sinon") require("karma-sinon") 50 ], 51 reporters: [ 52 "coverage-istanbul", // require("karma-coverage") 53 "mocha", // require("karma-mocha-reporter") 54 55 // for bin/try-runner.js to parse the output easily 56 "json", // require("karma-json-reporter") 57 ], 58 jsonReporter: { 59 // So this doesn't get interleaved with other karma output 60 stdout: false, 61 outputFile: path.join("logs", "karma-run-results.json"), 62 }, 63 coverageIstanbulReporter: { 64 reports: ["lcov", "text-summary"], // for some reason "lcov" reallys means "lcov" and "html" 65 "report-config": { 66 // so the full m-c path gets printed; needed for https://coverage.moz.tools/ integration 67 lcov: { 68 projectRoot: "../../..", 69 }, 70 }, 71 dir: PATHS.coverageReportingPath, 72 // This will make karma fail if coverage reporting is less than the minimums here 73 thresholds: !isTDD && { 74 each: { 75 statements: 100, 76 lines: 100, 77 functions: 100, 78 branches: 66, 79 overrides: { 80 "lib/AboutPreferences.sys.mjs": { 81 statements: 98, 82 lines: 98, 83 functions: 94, 84 branches: 66, 85 }, 86 /** 87 * TelemetryFeed.sys.mjs is tested via an xpcshell test 88 */ 89 "lib/TelemetryFeed.sys.mjs": { 90 statements: 10, 91 lines: 10, 92 functions: 9, 93 branches: 0, 94 }, 95 "content-src/lib/init-store.js": { 96 statements: 98, 97 lines: 98, 98 functions: 100, 99 branches: 100, 100 }, 101 "lib/DownloadsManager.sys.mjs": { 102 statements: 100, 103 lines: 100, 104 functions: 100, 105 branches: 78, 106 }, 107 /** 108 * PlacesFeed.sys.mjs is tested via an xpcshell test 109 */ 110 "lib/PlacesFeed.sys.mjs": { 111 statements: 7, 112 lines: 7, 113 functions: 8, 114 branches: 0, 115 }, 116 "lib/UTEventReporting.sys.mjs": { 117 statements: 100, 118 lines: 100, 119 functions: 100, 120 branches: 75, 121 }, 122 "lib/Screenshots.sys.mjs": { 123 statements: 94, 124 lines: 94, 125 functions: 75, 126 branches: 84, 127 }, 128 /** 129 * Store.sys.mjs is tested via an xpcshell test 130 */ 131 "lib/Store.sys.mjs": { 132 statements: 8, 133 lines: 8, 134 functions: 0, 135 branches: 0, 136 }, 137 /** 138 * TopSitesFeed.sys.mjs is tested via an xpcshell test 139 */ 140 "lib/TopSitesFeed.sys.mjs": { 141 statements: 9, 142 lines: 9, 143 functions: 5, 144 branches: 0, 145 }, 146 /** 147 * TopStoresFeed.sys.mjs is not tested in automation and is slated 148 * for eventual removal. 149 */ 150 "lib/TopStoriesFeed.sys.mjs": { 151 statements: 0, 152 lines: 0, 153 functions: 0, 154 branches: 0, 155 }, 156 /** 157 * WallpaperFeed.sys.mjs is tested via an xpcshell test 158 */ 159 "lib/Wallpapers/WallpaperFeed.sys.mjs": { 160 statements: 0, 161 lines: 0, 162 functions: 0, 163 branches: 0, 164 }, 165 "content-src/components/DiscoveryStreamComponents/PersonalizedCard/PersonalizedCard.jsx": 166 { 167 statements: 0, 168 lines: 0, 169 functions: 0, 170 branches: 0, 171 }, 172 "content-src/components/Base/Base.jsx": { 173 statements: 0, 174 lines: 0, 175 functions: 0, 176 branches: 0, 177 }, 178 "content-src/components/DiscoveryStreamComponents/FeatureHighlight/FollowSectionButtonHighlight.jsx": 179 { 180 statements: 88, 181 lines: 88, 182 functions: 80, 183 }, 184 "content-src/components/DiscoveryStreamComponents/FeatureHighlight/FeatureHighlight.jsx": 185 { 186 statements: 88, 187 lines: 88, 188 functions: 80, 189 }, 190 // for all other components in FeatureHighlight that dont have bespoke functionality 191 "content-src/components/DiscoveryStreamComponents/FeatureHighlight/!(FeatureHighlight).jsx": 192 { 193 statements: 0, 194 lines: 0, 195 functions: 0, 196 branches: 0, 197 }, 198 "content-src/components/DiscoveryStreamComponents/ReportContent/ReportContent.jsx": 199 { 200 statements: 0, 201 lines: 0, 202 functions: 0, 203 branches: 0, 204 }, 205 /** 206 * TopicSelection.jsx is tested via an xpcshell test 207 */ 208 "content-src/components/DiscoveryStreamComponents/TopicSelection/*.jsx": 209 { 210 statements: 0, 211 lines: 0, 212 functions: 0, 213 branches: 0, 214 }, 215 /** 216 * Tests for inline topic selection are coming in a follow-up task 217 */ 218 "content-src/components/DiscoveryStreamComponents/InterestPicker/*.jsx": 219 { 220 statements: 0, 221 lines: 0, 222 functions: 0, 223 branches: 0, 224 }, 225 "content-src/components/DiscoveryStreamComponents/DSCard/DSCard.jsx": 226 { 227 statements: 94.94, 228 lines: 94.84, 229 functions: 9.91, 230 branches: 70.72, 231 }, 232 "content-src/components/DiscoveryStreamComponents/CardSections/CardSections.jsx": 233 { 234 statements: 83.11, 235 lines: 82.52, 236 functions: 79.31, 237 branches: 52.8, 238 }, 239 "content-src/components/DiscoveryStreamComponents/SectionContextMenu/SectionContextMenu.jsx": 240 { 241 statements: 0, 242 lines: 0, 243 functions: 0, 244 branches: 0, 245 }, 246 "content-src/components/DiscoveryStreamComponents/AdBanner/AdBanner.jsx": 247 { 248 statements: 94.12, 249 lines: 94.12, 250 functions: 75, 251 branches: 60, 252 }, 253 "content-src/components/DiscoveryStreamComponents/AdBannerContextMenu/AdBannerContextMenu.jsx": 254 { 255 statements: 84, 256 lines: 84, 257 functions: 83, 258 }, 259 /** 260 * PromoCard currently has no functionality and is a placeholder component 261 */ 262 "content-src/components/DiscoveryStreamComponents/PromoCard/PromoCard.jsx": 263 { 264 statements: 0, 265 lines: 0, 266 functions: 0, 267 branches: 0, 268 }, 269 "content-src/components/DiscoveryStreamComponents/**/*.jsx": { 270 statements: 80.95, 271 lines: 80.95, 272 functions: 71.43, 273 branches: 70.9, 274 }, 275 /** 276 * WallpaperCategories.jsx is tested via an xpcshell test 277 */ 278 "content-src/components/WallpaperCategories/WallpaperCategories.jsx": 279 { 280 statements: 0, 281 lines: 0, 282 functions: 0, 283 branches: 0, 284 }, 285 /** 286 * Notifications.jsx is tested via an xpcshell test 287 */ 288 "content-src/components/Notifications/**/*.jsx": { 289 statements: 0, 290 lines: 0, 291 functions: 0, 292 branches: 0, 293 }, 294 "content-src/components/Weather/Weather.jsx": { 295 statements: 50, 296 lines: 50.94, 297 functions: 31.2, 298 branches: 31.2, 299 }, 300 "content-src/components/Widgets/WeatherForecast/WeatherForecast.jsx": 301 { 302 statements: 0, 303 lines: 0, 304 functions: 0, 305 branches: 0, 306 }, 307 "content-src/components/Weather/LocationSearch.jsx": { 308 statements: 0, 309 lines: 0, 310 functions: 0, 311 branches: 0, 312 }, 313 "content-src/components/DiscoveryStreamAdmin/*.jsx": { 314 statements: 0, 315 lines: 0, 316 functions: 0, 317 branches: 0, 318 }, 319 /** 320 * TODO: Bug 1985362 - Write SectionsMgmtPanel Unit Tests 321 */ 322 "content-src/components/CustomizeMenu/SectionsMgmtPanel/*.jsx": { 323 statements: 0, 324 lines: 0, 325 functions: 0, 326 branches: 0, 327 }, 328 "content-src/components/CustomizeMenu/ContentSection/*.jsx": { 329 statements: 80, 330 lines: 80, 331 functions: 99, 332 branches: 62, 333 }, 334 "content-src/components/CustomizeMenu/**/*.jsx": { 335 statements: 68, 336 lines: 66, 337 functions: 80, 338 branches: 16, 339 }, 340 "content-src/components/CustomizeMenu/*.jsx": { 341 statements: 98, 342 lines: 98, 343 functions: 98, 344 branches: 98, 345 }, 346 "content-src/lib/link-menu-options.js": { 347 statements: 96, 348 lines: 96, 349 functions: 96, 350 branches: 70, 351 }, 352 "content-src/lib/utils.jsx": { 353 branches: 60, 354 statements: 95.56, 355 lines: 95.4, 356 functions: 92.86, 357 }, 358 "content-src/components/MessageWrapper/MessageWrapper.jsx": { 359 lines: 50, 360 statements: 51.1, 361 functions: 31.2, 362 branches: 31.2, 363 }, 364 "content-src/components/Search/Search.jsx": { 365 statements: 38, 366 lines: 39, 367 functions: 28, 368 branches: 25, 369 }, 370 "content-src/components/**/*.jsx": { 371 statements: 51.1, 372 lines: 52.38, 373 functions: 31.2, 374 branches: 31.2, 375 }, 376 }, 377 }, 378 }, 379 }, 380 files: [PATHS.testEntryFile], 381 preprocessors, 382 webpack: { 383 mode: "none", 384 devtool: "inline-source-map", 385 // This resolve config allows us to import with paths relative to the root directory, e.g. "lib/ActivityStream.sys.mjs" 386 resolve: { 387 extensions: [".js", ".jsx", ".mjs"], 388 modules: [PATHS.moduleResolveDirectory, "node_modules"], 389 }, 390 plugins: [ 391 // The ResourceUriPlugin handles translating resource URIs in import 392 // statements in .mjs files to paths on the filesystem. 393 new ResourceUriPlugin({ 394 resourcePathRegExes: [ 395 [new RegExp("^resource://newtab/"), path.join(__dirname, "./")], 396 [ 397 new RegExp("^resource:///modules/asrouter/"), 398 path.join(__dirname, "../../components/asrouter/modules/"), 399 ], 400 [ 401 new RegExp("^resource:///modules/topsites/"), 402 path.join(__dirname, "../../components/topsites/"), 403 ], 404 [ 405 new RegExp( 406 "^moz-src:///toolkit/components/search/SearchShortcuts.sys.mjs" 407 ), 408 path.join( 409 __dirname, 410 "../../../toolkit/components/search/SearchShortcuts.sys.mjs" 411 ), 412 ], 413 [ 414 new RegExp("^resource:///modules/Dedupe.sys.mjs"), 415 path.join(__dirname, "../../modules/Dedupe.sys.mjs"), 416 ], 417 ], 418 }), 419 new MozSrcUriPlugin({ 420 baseDir: path.join(__dirname, "..", "..", ".."), 421 }), 422 423 new webpack.DefinePlugin({ 424 "process.env.NODE_ENV": JSON.stringify("development"), 425 }), 426 ], 427 externals: { 428 // enzyme needs these for backwards compatibility with 0.13. 429 // see https://github.com/airbnb/enzyme/blob/master/docs/guides/webpack.md#using-enzyme-with-webpack 430 "react/addons": true, 431 "react/lib/ReactContext": true, 432 "react/lib/ExecutionEnvironment": true, 433 }, 434 module: { 435 rules: [ 436 { 437 test: /\.js$/, 438 exclude: [/node_modules\/(?!@fluent\/).*/, /test/], 439 loader: "babel-loader", 440 }, 441 { 442 test: /\.jsx$/, 443 exclude: /node_modules/, 444 loader: "babel-loader", 445 options: { 446 presets: ["@babel/preset-react"], 447 }, 448 }, 449 { 450 test: /\.md$/, 451 use: "raw-loader", 452 }, 453 { 454 enforce: "post", 455 test: /\.js[x]?$/, 456 loader: "@jsdevtools/coverage-istanbul-loader", 457 options: { esModules: true }, 458 include: [ 459 path.resolve("content-src"), 460 path.resolve("lib"), 461 path.resolve("common"), 462 ], 463 exclude: [path.resolve("test"), path.resolve("vendor")], 464 }, 465 ], 466 }, 467 }, 468 // Silences some overly-verbose logging of individual module builds 469 webpackMiddleware: { noInfo: true }, 470 }); 471 };