-
Notifications
You must be signed in to change notification settings - Fork 328
/
karma.conf.cjs
117 lines (105 loc) · 3.67 KB
/
karma.conf.cjs
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
106
107
108
109
110
111
112
113
114
115
116
117
const istanbul = require('rollup-plugin-istanbul');
const json = require('@rollup/plugin-json');
const resolve = require('@rollup/plugin-node-resolve').default;
const yargs = require('yargs');
const env = process.env.NODE_ENV;
module.exports = async function(karma) {
const args = yargs
.option('verbose', {default: false})
.argv;
// Use the same rollup config as our dist files: when debugging (npm run dev),
// 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 builds = (await import('./rollup.config.js')).default;
const jasmineSeedReporter = (await import('./test/seed-reporter.js')).default;
const regex = karma.autoWatch ? /chartjs-plugin-annotation\.cjs$/ : /chartjs-plugin-annotation\.min\.js$/;
const build = builds.filter(v => v.output.file && v.output.file.match(regex))[0];
if (env === 'test') {
build.plugins = [
json(),
resolve(),
istanbul({exclude: ['node_modules/**/*.js', 'package.json']})
];
}
karma.set({
frameworks: ['jasmine'],
plugins: ['karma-*', jasmineSeedReporter],
reporters: ['progress', 'kjhtml', 'jasmine-seed'],
browsers: (args.browsers || 'chrome,firefox').split(','),
logLevel: karma.LOG_INFO,
client: {
jasmine: {
stopOnSpecFailure: !!karma.autoWatch
}
},
// 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
// Since FF 110, in FF GPU-accelerated Canvas2D is enabled by default on macOS and Linux.
// This is braking fixture test cases, therefore is disabled by setting gfx.canvas.accelerated
customLaunchers: {
chrome: {
base: 'Chrome',
flags: [
'--disable-accelerated-2d-canvas',
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows',
'--disable-renderer-backgrounding'
]
},
firefox: {
base: 'Firefox',
prefs: {
'layers.acceleration.disabled': true,
'gfx.canvas.accelerated': false
}
}
},
files: [
{pattern: 'test/fixtures/**/*.js', included: false},
{pattern: 'test/fixtures/**/*.png', included: false},
{pattern: 'node_modules/chart.js/dist/chart.umd.js'},
{pattern: 'src/index.js', watched: false, type: 'js'},
{pattern: 'test/index.js'},
{pattern: 'test/specs/**/**.js'}
],
preprocessors: {
'src/index.js': ['sources'],
'test/index.js': ['rollup']
},
rollupPreprocessor: {
plugins: [
resolve(),
],
output: {
name: 'test',
format: 'umd',
sourcemap: karma.autoWatch ? 'inline' : false
}
},
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
captureTimeout: 120000,
browserDisconnectTimeout: 120000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 120000,
});
if (env === 'test') {
karma.reporters.push('coverage');
karma.coverageReporter = {
dir: 'coverage/',
reporters: [
{type: 'html', subdir: 'html'},
{type: 'lcovonly', subdir: (browser) => browser.toLowerCase().split(/[ /-]/)[0]}
]
};
}
};