This repository has been archived by the owner on Aug 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
/
karma.conf.js
65 lines (62 loc) · 1.93 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
const webpackConfig = require('./webpack.config.test')
module.exports = function (config) {
config.set({
customLaunchers: {
ChromeCustom: {
base: 'ChromeHeadless',
// We must disable the Chrome sandbox when running Chrome inside Docker
// (Chrome's sandbox needs more permissions than Docker allows by
// default)
flags: ['--no-sandbox'],
},
},
browsers: ['ChromeCustom'],
files: [
// Import all tests (see comment in the file for why this is necessary)
'test/karma/import_tests.js',
],
middleware: ['fake-img'],
preprocessors: {
// Run files through webpack
'test/karma/import_tests.js': ['webpack'],
},
frameworks: ['mocha', 'chai-sinon'],
// Configure webpack in the tests
webpack: webpackConfig,
// Configure the webpack dev server used to serve test files
webpackMiddleware: {
// Disable file-watching -- it is of no use in CI, we use single runs.
// https://webpack.js.org/configuration/watch/
watch: false,
// ^ does not work when placed in webpack.config.test.
// webpack-dev-middleware overrides it :/
// v seems to be supported, according to
// https://www.npmjs.com/package/webpack-dev-middleware#watchoptions
watchOptions: {
ignored: [/node_modules/, /frontend/, /test/],
},
// Disable noisy CLI output
stats: 'errors-only',
},
plugins: [
require('karma-chrome-launcher'),
require('karma-mocha'),
require('karma-chai-sinon'),
require('karma-webpack'),
require('karma-mocha-reporter'),
{ 'middleware:fake-img': ['factory', fakeImgMiddlewareFactory] },
],
reporters: ['mocha'],
})
}
/**
* Handle fake images
*/
function fakeImgMiddlewareFactory() {
return function (req, res, next) {
if (req.originalUrl.startsWith('/fake/')) {
return res.end('fake img response')
}
next()
}
}