karma.conf.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/karma/import_tests.js',
  17. ],
  18. middleware: ['fake-img'],
  19. preprocessors: {
  20. // Run files through webpack
  21. 'test/karma/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 file-watching -- it is of no use in CI, we use single runs.
  29. // https://webpack.js.org/configuration/watch/
  30. watch: false,
  31. // ^ does not work when placed in webpack.config.test.
  32. // webpack-dev-middleware overrides it :/
  33. // v seems to be supported, according to
  34. // https://www.npmjs.com/package/webpack-dev-middleware#watchoptions
  35. watchOptions: {
  36. ignored: [/node_modules/, /frontend/, /test/],
  37. },
  38. // Disable noisy CLI output
  39. stats: 'errors-only',
  40. },
  41. plugins: [
  42. require('karma-chrome-launcher'),
  43. require('karma-mocha'),
  44. require('karma-chai-sinon'),
  45. require('karma-webpack'),
  46. require('karma-mocha-reporter'),
  47. { 'middleware:fake-img': ['factory', fakeImgMiddlewareFactory] },
  48. ],
  49. reporters: ['mocha'],
  50. })
  51. }
  52. /**
  53. * Handle fake images
  54. */
  55. function fakeImgMiddlewareFactory() {
  56. return function (req, res, next) {
  57. if (req.originalUrl.startsWith('/fake/')) {
  58. return res.end('fake img response')
  59. }
  60. next()
  61. }
  62. }