karma.config.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. const { writeFileSync } = require('./scripts/lib/util')
  2. let cmdArgs = process.argv.slice(2)
  3. let isRealCiEnv = Boolean(process.env.CI)
  4. let isCi = isRealCiEnv || cmdArgs.indexOf('ci') !== -1
  5. writeFileSync(
  6. 'tmp/tests/config.js',
  7. 'window.karmaConfig = ' + JSON.stringify({
  8. isCi: isRealCiEnv
  9. })
  10. )
  11. module.exports = function(config) {
  12. config.set({
  13. singleRun: isCi,
  14. autoWatch: !isCi,
  15. browsers: isCi ? [ 'ChromeHeadless_custom' ] : [],
  16. // base path, that will be used to resolve files and exclude
  17. basePath: '',
  18. plugins: [
  19. require('karma-chrome-launcher'),
  20. require('karma-jasmine'),
  21. require('karma-sourcemap-loader'),
  22. require('karma-verbose-reporter')
  23. ],
  24. // frameworks to use
  25. frameworks: [ 'jasmine' ],
  26. // list of files / patterns to load in the browser
  27. files: [
  28. 'tmp/tests/config.js',
  29. 'tmp/tests/all.js',
  30. { pattern: 'tmp/tests/all.js.map', included: false }
  31. ],
  32. // make console errors aware of source files
  33. preprocessors: {
  34. 'tmp/tests/*.js': [ 'sourcemap' ]
  35. },
  36. // test results reporter to use
  37. // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage', 'verbose'
  38. reporters: [ 'dots' ],
  39. // web server port
  40. port: 9876,
  41. // enable / disable colors in the output (reporters and logs)
  42. colors: true,
  43. // level of logging
  44. // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  45. logLevel: config.LOG_INFO,
  46. // If browser does not capture in given timeout [ms], kill it
  47. captureTimeout: 60000,
  48. customLaunchers: {
  49. ChromeHeadless_custom: {
  50. base: 'ChromeHeadless',
  51. flags: [
  52. '--no-sandbox', // needed for TravisCI: https://docs.travis-ci.com/user/chrome#Sandboxing
  53. '--window-size=1280,1696' // some tests only work with larger window (w?, h?)
  54. ]
  55. }
  56. }
  57. })
  58. }
  59. // ...getJsFilesFromHtml('tmp/tests/all.html').map((shortPath) => (
  60. // 'tmp/tests/' + shortPath
  61. // ))
  62. // function getJsFilesFromHtml(htmlPath) {
  63. // let html = readFileSync(htmlPath)
  64. // let matches = [ ...html.matchAll(/src=['"]([^'"]*)['"]/g) ] // iterator->array
  65. // return matches.map((match) => match[1])
  66. // }