karma.conf.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const path = require('path')
  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/js/bootstrap.js',
  16. // Angular must be loaded before requirejs to set up angular global
  17. 'public/js/libs/angular-1.6.4.min.js',
  18. 'public/js/libs/angular-mocks.js',
  19. 'public/js/libs/jquery-1.11.1.min.js',
  20. // Set up requirejs
  21. 'test/unit_frontend/js/test-main.js',
  22. // Include source & test files, but don't "include" them as requirejs
  23. // handles this for us
  24. { pattern: 'public/js/**/*.js', included: false },
  25. { pattern: 'test/unit_frontend/js/**/*.js', included: false },
  26. // Include ES test files
  27. 'test/unit_frontend/es/**/*.js'
  28. ],
  29. middleware: ['fake-img'],
  30. preprocessors: {
  31. // Run ES test files through webpack (which will then include source
  32. // files in bundle)
  33. 'test/unit_frontend/es/**/*.js': ['webpack']
  34. },
  35. frameworks: ['requirejs', 'mocha', 'chai-sinon'],
  36. // Configure webpack in the tests
  37. webpack: {
  38. resolve: {
  39. alias: {
  40. // Alias Src in import pathnames to public/es
  41. // Cuts down on the amount of ../../ etc
  42. Src: path.join(__dirname, 'public/es/')
  43. }
  44. }
  45. },
  46. // Configure the webpack dev server used to serve test files
  47. webpackMiddleware: {
  48. // Disable noisy CLI output
  49. stats: 'errors-only'
  50. },
  51. plugins: [
  52. require('karma-chrome-launcher'),
  53. require('karma-requirejs'),
  54. require('karma-mocha'),
  55. require('karma-chai-sinon'),
  56. require('karma-webpack'),
  57. require('karma-mocha-reporter'),
  58. { 'middleware:fake-img': ['factory', fakeImgMiddlewareFactory] }
  59. ],
  60. reporters: ['mocha']
  61. });
  62. }
  63. /**
  64. * Handle fake images
  65. */
  66. function fakeImgMiddlewareFactory () {
  67. return function (req, res, next) {
  68. if (req.originalUrl.startsWith('/fake/')) {
  69. return res.end('fake img response')
  70. }
  71. next()
  72. }
  73. }