2019-10-16 06:10:54 -04:00
|
|
|
const webpackConfig = require('./webpack.config.test')
|
2018-02-22 12:45:31 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
module.exports = function (config) {
|
2018-02-12 11:48:09 -05:00
|
|
|
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)
|
2021-04-27 03:52:58 -04:00
|
|
|
flags: ['--no-sandbox'],
|
|
|
|
},
|
2018-02-12 11:48:09 -05:00
|
|
|
},
|
|
|
|
browsers: ['ChromeCustom'],
|
2018-02-12 08:03:36 -05:00
|
|
|
files: [
|
2019-10-16 06:10:54 -04:00
|
|
|
// Import all tests (see comment in the file for why this is necessary)
|
2021-04-27 03:52:58 -04:00
|
|
|
'test/karma/import_tests.js',
|
2018-02-12 08:03:36 -05:00
|
|
|
],
|
2018-03-12 11:06:58 -04:00
|
|
|
middleware: ['fake-img'],
|
2018-02-22 12:45:31 -05:00
|
|
|
preprocessors: {
|
2019-10-16 06:10:54 -04:00
|
|
|
// Run files through webpack
|
2021-04-27 03:52:58 -04:00
|
|
|
'test/karma/import_tests.js': ['webpack'],
|
2018-02-22 12:45:31 -05:00
|
|
|
},
|
2019-10-16 06:10:54 -04:00
|
|
|
frameworks: ['mocha', 'chai-sinon'],
|
2018-02-22 12:45:31 -05:00
|
|
|
// Configure webpack in the tests
|
2019-10-16 06:10:54 -04:00
|
|
|
webpack: webpackConfig,
|
2018-02-22 12:45:31 -05:00
|
|
|
// Configure the webpack dev server used to serve test files
|
|
|
|
webpackMiddleware: {
|
2021-02-17 05:05:25 -05:00
|
|
|
// 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: {
|
2021-04-27 03:52:58 -04:00
|
|
|
ignored: [/node_modules/, /frontend/, /test/],
|
2021-02-17 05:05:25 -05:00
|
|
|
},
|
|
|
|
|
2018-02-22 12:45:31 -05:00
|
|
|
// Disable noisy CLI output
|
2021-04-27 03:52:58 -04:00
|
|
|
stats: 'errors-only',
|
2018-02-22 12:45:31 -05:00
|
|
|
},
|
2018-02-12 11:48:09 -05:00
|
|
|
plugins: [
|
2018-02-22 12:45:31 -05:00
|
|
|
require('karma-chrome-launcher'),
|
2018-02-12 11:48:09 -05:00
|
|
|
require('karma-mocha'),
|
|
|
|
require('karma-chai-sinon'),
|
2018-02-22 12:45:31 -05:00
|
|
|
require('karma-webpack'),
|
2018-03-12 11:06:58 -04:00
|
|
|
require('karma-mocha-reporter'),
|
2021-04-27 03:52:58 -04:00
|
|
|
{ 'middleware:fake-img': ['factory', fakeImgMiddlewareFactory] },
|
2018-02-12 11:48:09 -05:00
|
|
|
],
|
2021-04-27 03:52:58 -04:00
|
|
|
reporters: ['mocha'],
|
2019-08-06 08:20:02 -04:00
|
|
|
})
|
2018-02-12 11:48:09 -05:00
|
|
|
}
|
2018-03-12 11:06:58 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle fake images
|
|
|
|
*/
|
2019-08-06 08:20:02 -04:00
|
|
|
function fakeImgMiddlewareFactory() {
|
2021-04-14 09:17:21 -04:00
|
|
|
return function (req, res, next) {
|
2018-03-12 11:06:58 -04:00
|
|
|
if (req.originalUrl.startsWith('/fake/')) {
|
|
|
|
return res.end('fake img response')
|
|
|
|
}
|
|
|
|
next()
|
|
|
|
}
|
2018-03-29 12:11:17 -04:00
|
|
|
}
|