From ef0b550234795c84a62b68079adc2360f8cdf3db Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 12 Mar 2018 15:06:58 +0000 Subject: [PATCH] Handle fake images in karma, preventing 404 warnings --- services/web/karma.conf.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/services/web/karma.conf.js b/services/web/karma.conf.js index 867b6f4ceb..60674079f2 100644 --- a/services/web/karma.conf.js +++ b/services/web/karma.conf.js @@ -27,6 +27,7 @@ module.exports = function (config) { // Include ES test files 'test/unit_frontend/es/**/*.js' ], + middleware: ['fake-img'], preprocessors: { // Run ES test files through webpack (which will then include source // files in bundle) @@ -54,8 +55,21 @@ module.exports = function (config) { require('karma-mocha'), require('karma-chai-sinon'), require('karma-webpack'), - require('karma-mocha-reporter') + require('karma-mocha-reporter'), + { 'middleware:fake-img': ['factory', fakeImgMiddlewareFactory] } ], reporters: ['mocha'] }); } + +/** + * Handle fake images + */ +function fakeImgMiddlewareFactory () { + return function (req, res, next) { + if (req.originalUrl.startsWith('/fake/')) { + return res.end('fake img response') + } + next() + } +} \ No newline at end of file