karma.conf.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Karma configuration
  2. var deepExtend = require('deep-extend');
  3. var path = require('path');
  4. module.exports = getConfig();
  5. module.exports.getConfig = getConfig;
  6. function getConfig(context) {
  7. context = context || 'dev';
  8. var ci = context === 'ci';
  9. var webpackConfig = require('./webpack.config').getConfig(ci ? 'test:ci' : 'test');
  10. var testConfig = deepExtend({}, webpackConfig, {
  11. watch: !ci,
  12. entry: './index.test.js'
  13. });
  14. delete testConfig.externals.angular; // need angular in test context
  15. var entry = path.join(testConfig.context, testConfig.entry);
  16. var preprocessors = {};
  17. preprocessors[entry] = ['webpack'];
  18. return function(config) {
  19. config.set({
  20. // base path that will be used to resolve all patterns (eg. files, exclude)
  21. basePath: './',
  22. frameworks: ['mocha'],
  23. files: [entry],
  24. exclude: [],
  25. // preprocess matching files before serving them to the browser
  26. // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
  27. preprocessors: preprocessors,
  28. webpack: testConfig,
  29. // test results reporter to use
  30. // possible values: 'dots', 'progress'
  31. // available reporters: https://npmjs.org/browse/keyword/karma-reporter
  32. reporters: ['progress'],
  33. // web server port
  34. port: 9876,
  35. // enable / disable colors in the output (reporters and logs)
  36. colors: true,
  37. // level of logging
  38. // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  39. logLevel: config.LOG_INFO,
  40. // enable / disable watching file and executing tests whenever any file changes
  41. autoWatch: !ci,
  42. // start these browsers
  43. // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
  44. browsers: ci ? ['Firefox'] : ['Chrome'],
  45. // Continuous Integration mode
  46. // if true, Karma captures browsers, runs the tests and exits
  47. singleRun: ci,
  48. browserNoActivityTimeout: 180000,
  49. plugins: [
  50. require('karma-webpack'),
  51. 'karma-mocha',
  52. 'karma-chai',
  53. 'karma-chrome-launcher',
  54. 'karma-firefox-launcher'
  55. ]
  56. });
  57. };
  58. }