karma.conf.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* eslint-env node */
  2. /* eslint no-process-env: 0 */
  3. const path = require('path')
  4. const ip = require('ip')
  5. const {
  6. browsers,
  7. browsersKeys
  8. } = require('./browsers')
  9. const jqueryFile = process.env.USE_OLD_JQUERY ? 'https://code.jquery.com/jquery-1.9.1.min.js' : 'node_modules/jquery/dist/jquery.slim.min.js'
  10. const bundle = process.env.BUNDLE === 'true'
  11. const browserStack = process.env.BROWSER === 'true'
  12. const frameworks = [
  13. 'qunit',
  14. 'sinon'
  15. ]
  16. const plugins = [
  17. 'karma-qunit',
  18. 'karma-sinon'
  19. ]
  20. const reporters = ['dots']
  21. const detectBrowsers = {
  22. usePhantomJS: false,
  23. postDetection(availableBrowser) {
  24. if (typeof process.env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.includes('Chrome')) {
  25. return ['ChromeHeadless']
  26. }
  27. if (availableBrowser.includes('Firefox')) {
  28. return ['FirefoxHeadless']
  29. }
  30. throw new Error('Please install Firefox or Chrome')
  31. }
  32. }
  33. const customLaunchers = {
  34. FirefoxHeadless: {
  35. base: 'Firefox',
  36. flags: ['-headless']
  37. }
  38. }
  39. let files = [
  40. 'node_modules/popper.js/dist/umd/popper.min.js',
  41. 'node_modules/hammer-simulator/index.js'
  42. ]
  43. const conf = {
  44. basePath: '../..',
  45. port: 9876,
  46. colors: true,
  47. autoWatch: false,
  48. singleRun: true,
  49. concurrency: Infinity,
  50. client: {
  51. qunit: {
  52. showUI: true
  53. }
  54. }
  55. }
  56. if (bundle) {
  57. frameworks.push('detectBrowsers')
  58. plugins.push(
  59. 'karma-chrome-launcher',
  60. 'karma-firefox-launcher',
  61. 'karma-detect-browsers'
  62. )
  63. conf.customLaunchers = customLaunchers
  64. conf.detectBrowsers = detectBrowsers
  65. files = files.concat([
  66. jqueryFile,
  67. 'dist/js/bootstrap.js'
  68. ])
  69. } else if (browserStack) {
  70. conf.hostname = ip.address()
  71. conf.browserStack = {
  72. username: process.env.BROWSER_STACK_USERNAME,
  73. accessKey: process.env.BROWSER_STACK_ACCESS_KEY,
  74. build: `bootstrap-${new Date().toISOString()}`,
  75. project: 'Bootstrap',
  76. retryLimit: 2
  77. }
  78. plugins.push('karma-browserstack-launcher')
  79. conf.customLaunchers = browsers
  80. conf.browsers = browsersKeys
  81. reporters.push('BrowserStack')
  82. files = files.concat([
  83. 'node_modules/jquery/dist/jquery.slim.min.js',
  84. 'js/dist/util.js',
  85. 'js/dist/tooltip.js',
  86. 'js/dist/!(util|index|tooltip).js' // include all of our js/dist files except util.js, index.js and tooltip.js
  87. ])
  88. } else {
  89. frameworks.push('detectBrowsers')
  90. plugins.push(
  91. 'karma-chrome-launcher',
  92. 'karma-firefox-launcher',
  93. 'karma-detect-browsers',
  94. 'karma-coverage-istanbul-reporter'
  95. )
  96. files = files.concat([
  97. jqueryFile,
  98. 'js/coverage/dist/util.js',
  99. 'js/coverage/dist/tooltip.js',
  100. 'js/coverage/dist/!(util|index|tooltip).js' // include all of our js/dist files except util.js, index.js and tooltip.js
  101. ])
  102. reporters.push('coverage-istanbul')
  103. conf.customLaunchers = customLaunchers
  104. conf.detectBrowsers = detectBrowsers
  105. conf.coverageIstanbulReporter = {
  106. dir: path.resolve(__dirname, '../coverage/'),
  107. reports: ['lcov', 'text-summary'],
  108. thresholds: {
  109. emitWarning: false,
  110. global: {
  111. statements: 90,
  112. branches: 86,
  113. functions: 89,
  114. lines: 90
  115. }
  116. }
  117. }
  118. }
  119. files.push('js/tests/unit/*.js')
  120. conf.frameworks = frameworks
  121. conf.plugins = plugins
  122. conf.reporters = reporters
  123. conf.files = files
  124. module.exports = (karmaConfig) => {
  125. // possible values: karmaConfig.LOG_DISABLE || karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN || karmaConfig.LOG_INFO || karmaConfig.LOG_DEBUG
  126. conf.logLevel = karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN
  127. karmaConfig.set(conf)
  128. }