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)
|
2019-12-16 10:02:29 -05:00
|
|
|
'test/frontend/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
|
2019-11-05 09:00:13 -05:00
|
|
|
'test/frontend/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: {
|
|
|
|
// 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
|
|
|
}
|