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