karma.mc.config.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. const path = require("path");
  2. const PATHS = {
  3. // Where is the entry point for the unit tests?
  4. testEntryFile: path.resolve(__dirname, "test/unit/unit-entry.js"),
  5. // A glob-style pattern matching all unit tests
  6. testFilesPattern: "test/unit/**/*.js",
  7. // The base directory of all source files (used for path resolution in webpack importing)
  8. moduleResolveDirectory: __dirname,
  9. // a RegEx matching all Cu.import statements of local files
  10. resourcePathRegEx: /^resource:\/\/activity-stream\//,
  11. coverageReportingPath: "logs/coverage/",
  12. };
  13. // When tweaking here, be sure to review the docs about the execution ordering
  14. // semantics of the preprocessors array, as they are somewhat odd.
  15. const preprocessors = {};
  16. preprocessors[PATHS.testFilesPattern] = [
  17. "webpack", // require("karma-webpack")
  18. "sourcemap", // require("karma-sourcemap-loader")
  19. ];
  20. module.exports = function(config) {
  21. const isTDD = config.tdd;
  22. const browsers = isTDD ? ["Firefox"] : ["FirefoxHeadless"]; // require("karma-firefox-launcher")
  23. config.set({
  24. singleRun: !isTDD,
  25. browsers,
  26. customLaunchers: {
  27. FirefoxHeadless: {
  28. base: "Firefox",
  29. flags: ["--headless"],
  30. },
  31. },
  32. frameworks: [
  33. "chai", // require("chai") require("karma-chai")
  34. "mocha", // require("mocha") require("karma-mocha")
  35. "sinon", // require("sinon") require("karma-sinon")
  36. ],
  37. reporters: [
  38. "coverage-istanbul", // require("karma-coverage")
  39. "mocha", // require("karma-mocha-reporter")
  40. ],
  41. coverageIstanbulReporter: {
  42. reports: ["html", "text-summary"],
  43. dir: PATHS.coverageReportingPath,
  44. // This will make karma fail if coverage reporting is less than the minimums here
  45. thresholds: !isTDD && {
  46. each: {
  47. statements: 100,
  48. lines: 100,
  49. functions: 100,
  50. branches: 66,
  51. overrides: {
  52. "lib/ActivityStreamStorage.jsm": {
  53. statements: 100,
  54. lines: 100,
  55. functions: 100,
  56. branches: 83,
  57. },
  58. "lib/UTEventReporting.jsm": {
  59. statements: 100,
  60. lines: 100,
  61. functions: 100,
  62. branches: 75,
  63. },
  64. "lib/*.jsm": {
  65. statements: 100,
  66. lines: 100,
  67. functions: 100,
  68. branches: 84,
  69. },
  70. "content-src/components/DiscoveryStreamComponents/**/*.jsx": {
  71. statements: 65.2,
  72. lines: 65.2,
  73. functions: 50,
  74. branches: 50,
  75. },
  76. "content-src/asrouter/**/*.jsx": {
  77. statements: 57,
  78. lines: 58,
  79. functions: 60,
  80. branches: 50,
  81. },
  82. "content-src/components/ASRouterAdmin/*.jsx": {
  83. statements: 0,
  84. lines: 0,
  85. functions: 0,
  86. branches: 0,
  87. },
  88. "content-src/components/**/*.jsx": {
  89. statements: 51.1,
  90. lines: 53.6,
  91. functions: 31.2,
  92. branches: 31.2,
  93. },
  94. },
  95. },
  96. },
  97. },
  98. files: [PATHS.testEntryFile],
  99. preprocessors,
  100. webpack: {
  101. mode: "none",
  102. devtool: "inline-source-map",
  103. // This loader allows us to override required files in tests
  104. resolveLoader: {alias: {inject: path.join(__dirname, "loaders/inject-loader")}},
  105. // This resolve config allows us to import with paths relative to the root directory, e.g. "lib/ActivityStream.jsm"
  106. resolve: {
  107. extensions: [".js", ".jsx"],
  108. modules: [
  109. PATHS.moduleResolveDirectory,
  110. "node_modules",
  111. ],
  112. },
  113. externals: {
  114. // enzyme needs these for backwards compatibility with 0.13.
  115. // see https://github.com/airbnb/enzyme/blob/master/docs/guides/webpack.md#using-enzyme-with-webpack
  116. "react/addons": true,
  117. "react/lib/ReactContext": true,
  118. "react/lib/ExecutionEnvironment": true,
  119. },
  120. module: {
  121. rules: [
  122. // This rule rewrites importing/exporting in .jsm files to be compatible with esmodules
  123. {
  124. test: /\.jsm$/,
  125. exclude: [/node_modules/],
  126. use: [{
  127. loader: "babel-loader", // require("babel-core")
  128. options: {
  129. plugins: [
  130. // Converts .jsm files into common-js modules
  131. ["jsm-to-commonjs", {basePath: PATHS.resourcePathRegEx, removeOtherImports: true, replace: true}], // require("babel-plugin-jsm-to-commonjs")
  132. ],
  133. },
  134. }],
  135. },
  136. {
  137. test: /\.js$/,
  138. exclude: [/node_modules\/(?!(fluent|fluent-react)\/).*/, /test/],
  139. loader: "babel-loader",
  140. },
  141. {
  142. test: /\.jsx$/,
  143. exclude: /node_modules/,
  144. loader: "babel-loader",
  145. options: {
  146. presets: ["@babel/preset-react"],
  147. },
  148. },
  149. {
  150. test: /\.md$/,
  151. use: "raw-loader",
  152. },
  153. {
  154. enforce: "post",
  155. test: /\.js[mx]?$/,
  156. loader: "istanbul-instrumenter-loader",
  157. options: {esModules: true},
  158. include: [
  159. path.resolve("content-src"),
  160. path.resolve("lib"),
  161. path.resolve("common"),
  162. ],
  163. exclude: [
  164. path.resolve("test"),
  165. path.resolve("vendor"),
  166. path.resolve("lib/ASRouterTargeting.jsm"),
  167. path.resolve("lib/ASRouterTriggerListeners.jsm"),
  168. path.resolve("lib/OnboardingMessageProvider.jsm"),
  169. path.resolve("lib/CFRMessageProvider.jsm"),
  170. path.resolve("lib/CFRPageActions.jsm"),
  171. ],
  172. },
  173. ],
  174. },
  175. },
  176. // Silences some overly-verbose logging of individual module builds
  177. webpackMiddleware: {noInfo: true},
  178. });
  179. };