karma.conf.js 2.5 KB

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