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