2019-10-16 06:10:54 -04:00
|
|
|
const webpackConfig = require('./webpack.config.test')
|
2018-02-22 12:45:31 -05:00
|
|
|
|
2019-08-06 08:20:02 -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)
|
|
|
|
flags: ['--no-sandbox']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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)
|
2020-07-09 09:56:33 -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
|
2020-07-09 09:56:33 -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: {
|
|
|
|
ignored: [/node_modules/, /frontend/, /test/]
|
|
|
|
},
|
|
|
|
|
2018-02-22 12:45:31 -05:00
|
|
|
// Disable noisy CLI output
|
|
|
|
stats: 'errors-only'
|
|
|
|
},
|
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'),
|
|
|
|
{ 'middleware:fake-img': ['factory', fakeImgMiddlewareFactory] }
|
2018-02-12 11:48:09 -05:00
|
|
|
],
|
2018-02-22 09:04:22 -05: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() {
|
|
|
|
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
|
|
|
}
|