forked from mozilla/addons-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarma.conf.js
173 lines (157 loc) · 4.81 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Karma configuration
/* eslint-disable max-len, no-console, strict, import/no-extraneous-dependencies */
'use strict';
require('babel-register');
const fs = require('fs');
const webpack = require('webpack');
const config = require('config');
const getClientConfig = require('./src/core/utils').getClientConfig;
const webpackConfigProd = require('./webpack.prod.config.babel').default;
const clientConfig = getClientConfig(config);
const babelrc = fs.readFileSync('./.babelrc');
const babelQuery = JSON.parse(babelrc);
const coverageReporters = [{
type: 'text-summary',
}];
babelQuery.plugins.push(['istanbul', { include: 'src/**' }]);
const newWebpackConfig = Object.assign({}, webpackConfigProd, {
plugins: [
new webpack.DefinePlugin({
CLIENT_CONFIG: JSON.stringify(clientConfig),
}),
// Replaces server config module with the subset clientConfig object.
new webpack.NormalModuleReplacementPlugin(/config$/, 'core/client/config.js'),
// Substitutes client only config.
new webpack.NormalModuleReplacementPlugin(/core\/logger$/, 'core/client/logger.js'),
// Use the browser's window for window.
new webpack.NormalModuleReplacementPlugin(/core\/window/, 'core/browserWindow.js'),
// Plugin to show any webpack warnings and prevent tests from running
// Based on: https://gist.github.com/Stuk/6b574049435df532e905
function WebpackWarningPlugin() {
this.plugin('done', (_stats) => {
const stats = _stats;
let flagException = false;
const loggedExceptions = [
'SyntaxError',
];
function strContainsException(str) {
return loggedExceptions.some((substring) => str.includes(substring));
}
['errors', 'warnings'].forEach((key) => {
const loggedStack = stats.compilation[key];
if (loggedStack && loggedStack.length) {
stats.compilation[key].forEach((item) => {
const message = item.message || '';
if (strContainsException(message)) {
console.log(message);
flagException = true;
}
});
}
});
// Bail if syntax errors were encountered and we're not watching.
if (flagException && process.argv.indexOf('--watch') === -1) {
throw new Error('Error encountered, bailing');
}
});
},
],
devtool: 'inline-source-map',
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: babelQuery,
}, {
test: /\.css$/,
loader: 'style!css?importLoaders=2!postcss?outputStyle=expanded',
}, {
test: /\.scss$/,
loader: 'style!css?importLoaders=2!postcss!sass?outputStyle=expanded',
}, {
test: /\.svg$/,
loader: 'url?limit=10000&mimetype=image/svg+xml',
}, {
test: /\.jpg$/,
loader: 'url?limit=10000&mimetype=image/jpeg',
}, {
test: /\.png$/,
loader: 'url?limit=10000&mimetype=image/png',
}, {
test: /\.gif/,
loader: 'url?limit=10000&mimetype=image/gif',
}, {
test: /\.webm$/,
loader: 'url?limit=10000&mimetype=video/webm',
}, {
test: /\.mp4$/,
loader: 'url?limit=10000&mimetype=video/mp4',
}, {
test: /\.otf$/,
loader: 'url?limit=10000&mimetype=application/font-sfnt',
}, {
test: /\.woff$/,
loader: 'url?limit=10000&mimetype=application/font-woff',
}, {
test: /\.woff2$/,
loader: 'url?limit=10000&mimetype=application/font-woff2',
},
],
},
output: undefined,
entry: undefined,
});
const reporters = [
'mocha',
'coverage',
];
if (process.env.TRAVIS) {
console.log('On Travis sending coveralls');
coverageReporters.push({ type: 'lcov', dir: 'coverage' });
reporters.push('coveralls');
} else {
console.log('Not on Travis so not sending coveralls');
coverageReporters.push({ type: 'html', dir: 'coverage', subdir: '.' });
}
module.exports = function karmaConf(conf) {
conf.set({
coverageReporter: {
reporters: coverageReporters,
},
frameworks: ['mocha', 'chai', 'sinon'],
files: [
'test-runner.js',
],
mochaReporter: {
showDiff: true,
},
preprocessors: {
'test-runner.js': ['webpack', 'sourcemap'],
},
reporters,
colors: true,
port: 9876,
plugins: [
'karma-chai',
'karma-coverage',
'karma-coveralls',
'karma-firefox-launcher',
'karma-mocha',
'karma-mocha-reporter',
'karma-sinon',
'karma-sourcemap-loader',
'karma-webpack',
],
browsers: ['Firefox'],
singleRun: false,
concurrency: Infinity,
webpack: newWebpackConfig,
failOnEmptyTestSuite: true,
webpackServer: {
noInfo: true,
quiet: true,
},
});
};