karma.conf.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const webpackConfig = require('./webpack.config.test')
  2. module.exports = function(config) {
  3. config.set({
  4. customLaunchers: {
  5. ChromeCustom: {
  6. base: 'ChromeHeadless',
  7. // We must disable the Chrome sandbox when running Chrome inside Docker
  8. // (Chrome's sandbox needs more permissions than Docker allows by
  9. // default)
  10. flags: ['--no-sandbox']
  11. }
  12. },
  13. browsers: ['ChromeCustom'],
  14. files: [
  15. // Import all tests (see comment in the file for why this is necessary)
  16. 'test/frontend/import_tests.js'
  17. ],
  18. middleware: ['fake-img'],
  19. preprocessors: {
  20. // Run files through webpack
  21. 'test/frontend/import_tests.js': ['webpack']
  22. },
  23. frameworks: ['mocha', 'chai-sinon'],
  24. // Configure webpack in the tests
  25. webpack: webpackConfig,
  26. // Configure the webpack dev server used to serve test files
  27. webpackMiddleware: {
  28. // Disable noisy CLI output
  29. stats: 'errors-only'
  30. },
  31. plugins: [
  32. require('karma-chrome-launcher'),
  33. require('karma-mocha'),
  34. require('karma-chai-sinon'),
  35. require('karma-webpack'),
  36. require('karma-mocha-reporter'),
  37. { 'middleware:fake-img': ['factory', fakeImgMiddlewareFactory] }
  38. ],
  39. reporters: ['mocha']
  40. })
  41. }
  42. /**
  43. * Handle fake images
  44. */
  45. function fakeImgMiddlewareFactory() {
  46. return function(req, res, next) {
  47. if (req.originalUrl.startsWith('/fake/')) {
  48. return res.end('fake img response')
  49. }
  50. next()
  51. }
  52. }