karma.conf.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. var ip = require('ip');
  3. var browserConfig = require('./browsers');
  4. var browserStack = process.env.BROWSER === 'true';
  5. module.exports = function (config) {
  6. var conf = {
  7. basePath: '../',
  8. frameworks: ['qunit'],
  9. plugins: ['karma-qunit'],
  10. // list of files / patterns to load in the browser
  11. files: [
  12. 'js/tests/vendor/jquery.min.js',
  13. 'js/tooltip.js',
  14. 'js/!(tooltip).js',
  15. 'js/tests/unit/*.js'
  16. ],
  17. reporters: ['dots'],
  18. port: 9876,
  19. colors: true,
  20. // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  21. logLevel: config.LOG_ERROR || config.LOG_WARN,
  22. autoWatch: false,
  23. singleRun: true,
  24. concurrency: Infinity,
  25. client: {
  26. qunit: {
  27. showUI: true
  28. }
  29. }
  30. };
  31. if (browserStack) {
  32. conf.hostname = ip.address();
  33. conf.browserStack = {
  34. username: process.env.BROWSER_STACK_USERNAME,
  35. accessKey: process.env.BROWSER_STACK_ACCESS_KEY,
  36. build: 'bootstrap-v3-' + new Date().toISOString(),
  37. project: 'Bootstrap v3',
  38. retryLimit: 1
  39. };
  40. conf.plugins.push('karma-browserstack-launcher');
  41. conf.customLaunchers = browserConfig.list;
  42. conf.browsers = browserConfig.keys;
  43. conf.reporters.push('BrowserStack');
  44. } else {
  45. conf.frameworks.push('detectBrowsers');
  46. conf.plugins.push(
  47. 'karma-chrome-launcher',
  48. 'karma-firefox-launcher',
  49. 'karma-detect-browsers'
  50. );
  51. conf.detectBrowsers = {
  52. usePhantomJS: false,
  53. postDetection: function (availableBrowser) {
  54. if (typeof process.env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.includes('Chrome')) {
  55. return ['ChromeHeadless'];
  56. }
  57. if (availableBrowser.includes('Firefox')) {
  58. return ['FirefoxHeadless'];
  59. }
  60. throw new Error('Please install Firefox or Chrome');
  61. }
  62. };
  63. conf.customLaunchers = {
  64. FirefoxHeadless: {
  65. base: 'Firefox',
  66. flags: ['-headless']
  67. }
  68. };
  69. }
  70. config.set(conf);
  71. };