tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

karma.mc.config.js (9895B)


      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, "./tests/unit/unit-entry.js"),
     13 
     14  // A glob-style pattern matching all unit tests
     15  testFilesPattern: "./tests/unit/unit-entry.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: 80,
     76          lines: 80,
     77          functions: 80,
     78          branches: 80,
     79          overrides: {
     80            "modules/AboutWelcomeDefaults.sys.mjs": {
     81              statements: 48.15,
     82              lines: 48.75,
     83              functions: 61.54,
     84              branches: 37.04,
     85            },
     86            "content-src/lib/aboutwelcome-utils.mjs": {
     87              statements: 73.68,
     88              lines: 73.68,
     89              functions: 71.43,
     90              branches: 66.67,
     91            },
     92            "content-src/components/LanguageSwitcher.jsx": {
     93              // This file is covered by the mochitest: browser_aboutwelcome_multistage_languageSwitcher.js
     94              statements: 0,
     95              lines: 0,
     96              functions: 0,
     97              branches: 0,
     98            },
     99            "content-src/components/EmbeddedMigrationWizard.jsx": {
    100              // This file is covered by the mochitest: browser_aboutwelcome_multistage_mr.js
    101              // Can't be unit tested because it relies on the migration-wizard custom element
    102              statements: 0,
    103              lines: 0,
    104              functions: 0,
    105              branches: 0,
    106            },
    107            "content-src/components/AddonsPicker.jsx": {
    108              // This file is covered by the mochitest: browser_aboutwelcome_multistage_addonspicker.js
    109              statements: 0,
    110              lines: 0,
    111              functions: 0,
    112              branches: 0,
    113            },
    114            "content-src/components/SubmenuButton.jsx": {
    115              // Enzyme can't test this file because it relies on XUL elements
    116              // and JS events, which Enzyme can't simulate. Browser tests are
    117              // in browser_feature_callout_panel.js
    118              statements: 0,
    119              lines: 0,
    120              functions: 0,
    121              branches: 0,
    122            },
    123            "content-src/components/EmbeddedBrowser.jsx": {
    124              // Enzyme can't test this file because it relies on XUL elements
    125              // which Enzyme can't simulate. Browser tests are in
    126              // browser_aboutwelcome_embedded_browser.js
    127              statements: 0,
    128              lines: 0,
    129              functions: 0,
    130              branches: 0,
    131            },
    132            "content-src/components/EmbeddedFxBackupOptIn.jsx": {
    133              statements: 60,
    134              lines: 60,
    135              functions: 50,
    136              branches: 60,
    137            },
    138            "content-src/components/MSLocalized.jsx": {
    139              statements: 77.42,
    140              lines: 77.42,
    141              functions: 75,
    142              branches: 73.08,
    143            },
    144            "content-src/components/CTAParagraph.jsx": {
    145              functions: 50,
    146              branches: 75,
    147            },
    148            "content-src/components/HeroImage.jsx": {
    149              branches: 62.5,
    150            },
    151            "content-src/components/LinkParagraph.jsx": {
    152              functions: 75,
    153              branches: 37.5,
    154            },
    155            "content-src/components/MobileDownloads.jsx": {
    156              branches: 56.25,
    157            },
    158            "content-src/components/Themes.jsx": {
    159              branches: 50,
    160            },
    161            "content-src/components/MultiStageAboutWelcome.jsx": {
    162              statements: 78.06,
    163              lines: 79,
    164              functions: 73.17,
    165              branches: 61.74,
    166            },
    167            "content-src/components/AdditionalCTA.jsx": {
    168              branches: 75,
    169            },
    170            "content-src/components/MultiStageProtonScreen.jsx": {
    171              branches: 78,
    172            },
    173            // The install actions and dynamic label of the InstallButton are covered
    174            // in the browser test browser_aboutwelcome_multistage_addonspicker.js.
    175            "content-src/components/InstallButton.jsx": {
    176              statements: 60,
    177              lines: 60,
    178              functions: 60,
    179              branches: 30,
    180            },
    181            "content-src/components/TileButton.jsx": {
    182              // TODO: This file will be covered in a followup by end-to-end tests of the backup component
    183              statements: 0,
    184              lines: 0,
    185              functions: 0,
    186              branches: 0,
    187            },
    188            "content-src/components/TileList.jsx": {
    189              // This file will be covered in a followup by end-to-end tests of the backup component
    190              statements: 0,
    191              lines: 0,
    192              functions: 0,
    193              branches: 0,
    194            },
    195            "content-src/components/ConfirmationChecklist.jsx": {
    196              // This file is will be covered in a followup by end-to-end tests of the backup component
    197              statements: 0,
    198              lines: 0,
    199              functions: 0,
    200              branches: 0,
    201            },
    202          },
    203        },
    204      },
    205    },
    206    files: [PATHS.testEntryFile],
    207    preprocessors,
    208    webpack: {
    209      mode: "none",
    210      devtool: "inline-source-map",
    211      // This resolve config allows us to import with paths relative to the root directory
    212      resolve: {
    213        extensions: [".js", ".jsx"],
    214        modules: [PATHS.moduleResolveDirectory, "node_modules"],
    215        alias: {
    216          asrouter: path.join(__dirname, "../asrouter"),
    217        },
    218      },
    219      plugins: [
    220        // The ResourceUriPlugin handles translating resource URIs in import
    221        // statements in .mjs files to paths on the filesystem.
    222        new ResourceUriPlugin({
    223          resourcePathRegExes: [
    224            [
    225              new RegExp("^resource:///modules/asrouter/"),
    226              path.join(__dirname, "../asrouter/modules/"),
    227            ],
    228          ],
    229        }),
    230        new MozSrcUriPlugin({
    231          baseDir: path.join(__dirname, "..", "..", ".."),
    232        }),
    233        new webpack.DefinePlugin({
    234          "process.env.NODE_ENV": JSON.stringify("development"),
    235        }),
    236      ],
    237      externals: {
    238        // enzyme needs these for backwards compatibility with 0.13.
    239        // see https://github.com/airbnb/enzyme/blob/master/docs/guides/webpack.md#using-enzyme-with-webpack
    240        "react/addons": true,
    241        "react/lib/ReactContext": true,
    242        "react/lib/ExecutionEnvironment": true,
    243      },
    244      module: {
    245        rules: [
    246          {
    247            test: /\.js$/,
    248            exclude: [/node_modules\/(?!@fluent\/).*/, /tests/],
    249            loader: "babel-loader",
    250          },
    251          {
    252            test: /\.jsx$/,
    253            exclude: /node_modules/,
    254            loader: "babel-loader",
    255            options: {
    256              presets: ["@babel/preset-react"],
    257            },
    258          },
    259          {
    260            test: /\.md$/,
    261            use: "raw-loader",
    262          },
    263          {
    264            enforce: "post",
    265            test: /\.m?js[mx]?$/,
    266            loader: "@jsdevtools/coverage-istanbul-loader",
    267            options: { esModules: true },
    268            include: [path.resolve("content-src"), path.resolve("modules")],
    269            exclude: [path.resolve("tests"), path.resolve("../newtab")],
    270          },
    271        ],
    272      },
    273    },
    274    // Silences some overly-verbose logging of individual module builds
    275    webpackMiddleware: { noInfo: true },
    276  });
    277 };