tor-browser

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

karma.mc.config.js (6279B)


      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            "content-src/components/ASRouterAdmin/SimpleHashRouter.jsx": {
     81              statements: 0,
     82              functions: 0,
     83              lines: 0,
     84            },
     85            "content-src/components/ASRouterAdmin/CopyButton.jsx": {
     86              statements: 7.14,
     87              lines: 7.69,
     88              branches: 0,
     89              functions: 0,
     90            },
     91            "content-src/components/ASRouterAdmin/ImpressionsSection.jsx": {
     92              statements: 7.14,
     93              lines: 7.5,
     94              branches: 0,
     95              functions: 0,
     96            },
     97            "content-src/components/ASRouterAdmin/ASRouterAdmin.jsx": {
     98              statements: 39.19,
     99              lines: 39.19,
    100              branches: 47.15,
    101              functions: 32.08,
    102            },
    103          },
    104        },
    105      },
    106    },
    107    files: [PATHS.testEntryFile],
    108    preprocessors,
    109    webpack: {
    110      mode: "none",
    111      devtool: "inline-source-map",
    112      // This resolve config allows us to import with paths relative to the root directory
    113      resolve: {
    114        extensions: [".mjs", ".js", ".jsx"],
    115        modules: [PATHS.moduleResolveDirectory, "node_modules"],
    116      },
    117      plugins: [
    118        // The ResourceUriPlugin handles translating resource URIs in import
    119        // statements in .mjs files to paths on the filesystem.
    120        new ResourceUriPlugin({
    121          resourcePathRegExes: [
    122            [
    123              new RegExp("^resource:///modules/asrouter/"),
    124              path.join(__dirname, "./modules/"),
    125            ],
    126          ],
    127        }),
    128        new MozSrcUriPlugin({
    129          baseDir: path.join(__dirname, "..", "..", ".."),
    130        }),
    131        new webpack.DefinePlugin({
    132          "process.env.NODE_ENV": JSON.stringify("development"),
    133        }),
    134      ],
    135      externals: {
    136        // enzyme needs these for backwards compatibility with 0.13.
    137        // see https://github.com/airbnb/enzyme/blob/master/docs/guides/webpack.md#using-enzyme-with-webpack
    138        "react/addons": true,
    139        "react/lib/ReactContext": true,
    140        "react/lib/ExecutionEnvironment": true,
    141      },
    142      module: {
    143        rules: [
    144          {
    145            test: /\.js$/,
    146            exclude: [/node_modules\/(?!@fluent\/).*/, /tests/],
    147            loader: "babel-loader",
    148          },
    149          {
    150            test: /\.jsx$/,
    151            exclude: /node_modules/,
    152            loader: "babel-loader",
    153            options: {
    154              presets: ["@babel/preset-react"],
    155            },
    156          },
    157          {
    158            test: /\.md$/,
    159            use: "raw-loader",
    160          },
    161          {
    162            enforce: "post",
    163            test: /\.js[x]?$/,
    164            loader: "@jsdevtools/coverage-istanbul-loader",
    165            options: { esModules: true },
    166            include: [path.resolve("content-src"), path.resolve("modules")],
    167            exclude: [
    168              path.resolve("tests"),
    169              path.resolve("../newtab"),
    170              path.resolve("modules/ASRouterTargeting.sys.mjs"),
    171              path.resolve("modules/ASRouterTriggerListeners.sys.mjs"),
    172              path.resolve("modules/CFRMessageProvider.sys.mjs"),
    173              path.resolve("modules/CFRPageActions.sys.mjs"),
    174              path.resolve("modules/OnboardingMessageProvider.sys.mjs"),
    175            ],
    176          },
    177        ],
    178      },
    179    },
    180    // Silences some overly-verbose logging of individual module builds
    181    webpackMiddleware: { noInfo: true },
    182  });
    183 };