karma.conf.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. 'test/unit_frontend/bootstrap.js',
  16. // Include scripts that are injected into the page outside of webpack
  17. 'public/js/libs/angular-1.6.4.min.js',
  18. 'public/js/libs/jquery-1.11.1.min.js',
  19. // Allow mocking of angular
  20. 'public/js/libs/angular-mocks.js',
  21. // Import all tests (see comment in the file for why this is necessary)
  22. 'test/unit_frontend/import_tests.js',
  23. // Include CSS (there is some in js/libs dir)
  24. 'public/stylesheets/**/*.css',
  25. 'public/js/libs/**/*.css'
  26. ],
  27. middleware: ['fake-img'],
  28. preprocessors: {
  29. // Run files through webpack
  30. 'test/unit_frontend/import_tests.js': ['webpack']
  31. },
  32. frameworks: ['mocha', 'chai-sinon'],
  33. // Configure webpack in the tests
  34. webpack: webpackConfig,
  35. // Configure the webpack dev server used to serve test files
  36. webpackMiddleware: {
  37. // Disable noisy CLI output
  38. stats: 'errors-only'
  39. },
  40. plugins: [
  41. require('karma-chrome-launcher'),
  42. require('karma-mocha'),
  43. require('karma-chai-sinon'),
  44. require('karma-webpack'),
  45. require('karma-mocha-reporter'),
  46. { 'middleware:fake-img': ['factory', fakeImgMiddlewareFactory] }
  47. ],
  48. reporters: ['mocha']
  49. })
  50. }
  51. /**
  52. * Handle fake images
  53. */
  54. function fakeImgMiddlewareFactory() {
  55. return function(req, res, next) {
  56. if (req.originalUrl.startsWith('/fake/')) {
  57. return res.end('fake img response')
  58. }
  59. next()
  60. }
  61. }