forked from ppy/osu-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
74 lines (64 loc) · 1.96 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
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.
// karma-webpack doesn't exit on compile error.
// This plugin makes it exit on compile error.
class ExitOnErrorWebpackPlugin {
apply(compiler) {
compiler.hooks.done.tap('ExitOnErrorWebpackPlugin', (stats) => {
if (stats && stats.hasErrors()) {
stats.toJson().errors.forEach((error) => {
console.error(error);
});
process.exit(1);
}
});
}
}
/**
* Blocks until the webpack config is read.
*/
function readWebpackConfig() {
const { argv } = require('yargs');
if (!argv.singleRun) {
argv.watch = true;
}
const configFn = require('./webpack.config.js');
return configFn(null, argv);
}
process.env.SKIP_MANIFEST = true;
const webpackConfig = readWebpackConfig();
webpackConfig.plugins.push(new ExitOnErrorWebpackPlugin());
webpackConfig.mode = 'development';
webpackConfig.devtool = 'inline-source-map';
delete webpackConfig.optimization; // karma doesn't work with splitChunks...or runtimeChunk
delete webpackConfig.entry; // test runner doesn't use the entry points
const testIndex = './tests/karma/index.ts';
const files = [
'./tests/karma/globals.js', // shims for tests
testIndex,
];
const preprocessors = {};
preprocessors[testIndex] = ['webpack', 'sourcemap'];
module.exports = function(config) {
config.set({
autoWatch: true,
basePath: '.',
browsers: ['ChromeHeadless'],
colors: true,
concurrency: Infinity,
exclude: [],
files,
frameworks: ['jasmine', 'webpack'],
logLevel: config.LOG_INFO,
mime: { 'text/x-typescript': ['ts', 'tsx'] },
port: 9876,
preprocessors,
reporters: ['mocha'],
singleRun: false, // set to true for the process to exit after completing.
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true,
stats: 'errors-only',
},
});
};