karma.conf.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* eslint-env es6 */
  2. const commonjs = require('rollup-plugin-commonjs');
  3. const istanbul = require('rollup-plugin-istanbul');
  4. const resolve = require('rollup-plugin-node-resolve');
  5. const builds = require('./rollup.config');
  6. module.exports = function(karma) {
  7. const args = karma.args || {};
  8. // Use the same rollup config as our dist files: when debugging (--watch),
  9. // we will prefer the unminified build which is easier to browse and works
  10. // better with source mapping. In other cases, pick the minified build to
  11. // make sure that the minification process (terser) doesn't break anything.
  12. const regex = args.watch ? /Chart\.js$/ : /Chart\.min\.js$/;
  13. const build = builds.filter(v => v.output.file.match(regex))[0];
  14. if (args.watch) {
  15. build.output.sourcemap = 'inline';
  16. }
  17. karma.set({
  18. frameworks: ['jasmine'],
  19. reporters: ['progress', 'kjhtml'],
  20. browsers: ['chrome', 'firefox'],
  21. logLevel: karma.LOG_WARN,
  22. // Explicitly disable hardware acceleration to make image
  23. // diff more stable when ran on Travis and dev machine.
  24. // https://github.com/chartjs/Chart.js/pull/5629
  25. customLaunchers: {
  26. chrome: {
  27. base: 'Chrome',
  28. flags: [
  29. '--disable-accelerated-2d-canvas'
  30. ]
  31. },
  32. firefox: {
  33. base: 'Firefox',
  34. prefs: {
  35. 'layers.acceleration.disabled': true
  36. }
  37. }
  38. },
  39. files: [
  40. {pattern: 'test/fixtures/**/*.js', included: false},
  41. {pattern: 'test/fixtures/**/*.json', included: false},
  42. {pattern: 'test/fixtures/**/*.png', included: false},
  43. 'node_modules/moment/min/moment.min.js',
  44. 'test/index.js',
  45. 'src/index.js'
  46. ].concat(args.inputs),
  47. preprocessors: {
  48. 'test/index.js': ['rollup'],
  49. 'src/index.js': ['sources']
  50. },
  51. rollupPreprocessor: {
  52. plugins: [
  53. resolve(),
  54. commonjs()
  55. ],
  56. output: {
  57. name: 'test',
  58. format: 'umd'
  59. }
  60. },
  61. customPreprocessors: {
  62. sources: {
  63. base: 'rollup',
  64. options: build
  65. }
  66. },
  67. // These settings deal with browser disconnects. We had seen test flakiness from Firefox
  68. // [Firefox 56.0.0 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
  69. // https://github.com/jasmine/jasmine/issues/1327#issuecomment-332939551
  70. browserDisconnectTolerance: 3
  71. });
  72. // https://swizec.com/blog/how-to-run-javascript-tests-in-chrome-on-travis/swizec/6647
  73. if (process.env.TRAVIS) {
  74. karma.customLaunchers.chrome.flags.push('--no-sandbox');
  75. }
  76. if (args.coverage) {
  77. karma.reporters.push('coverage');
  78. karma.coverageReporter = {
  79. dir: 'coverage/',
  80. reporters: [
  81. {type: 'html', subdir: 'html'},
  82. {type: 'lcovonly', subdir: '.'}
  83. ]
  84. };
  85. [
  86. karma.rollupPreprocessor,
  87. karma.customPreprocessors.sources.options
  88. ].forEach(v => {
  89. (v.plugins || (v.plugins = [])).unshift(
  90. istanbul({
  91. include: 'src/**/*.js'
  92. }));
  93. });
  94. }
  95. };