Sfoglia il codice sorgente

Handle fake images in karma, preventing 404 warnings

Alasdair Smith 8 anni fa
parent
commit
ef0b550234
1 ha cambiato i file con 15 aggiunte e 1 eliminazioni
  1. 15 1
      services/web/karma.conf.js

+ 15 - 1
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()
+  }
+}