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