Handle fake images in karma, preventing 404 warnings

This commit is contained in:
Alasdair Smith 2018-03-12 15:06:58 +00:00
parent d93f5fa6be
commit ef0b550234

View file

@ -27,6 +27,7 @@ module.exports = function (config) {
// Include ES test files // Include ES test files
'test/unit_frontend/es/**/*.js' 'test/unit_frontend/es/**/*.js'
], ],
middleware: ['fake-img'],
preprocessors: { preprocessors: {
// Run ES test files through webpack (which will then include source // Run ES test files through webpack (which will then include source
// files in bundle) // files in bundle)
@ -54,8 +55,21 @@ module.exports = function (config) {
require('karma-mocha'), require('karma-mocha'),
require('karma-chai-sinon'), require('karma-chai-sinon'),
require('karma-webpack'), require('karma-webpack'),
require('karma-mocha-reporter') require('karma-mocha-reporter'),
{ 'middleware:fake-img': ['factory', fakeImgMiddlewareFactory] }
], ],
reporters: ['mocha'] reporters: ['mocha']
}); });
} }
/**
* Handle fake images
*/
function fakeImgMiddlewareFactory () {
return function (req, res, next) {
if (req.originalUrl.startsWith('/fake/')) {
return res.end('fake img response')
}
next()
}
}