Merge pull request #394 from sharelatex/as-karma-fake-img

Handle fake images in karma, preventing 404 warnings
This commit is contained in:
Alasdair Smith 2018-03-13 11:21:22 +00:00 committed by GitHub
commit 458506ff66

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()
}
}