karma.conf.js 2.6 KB

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