karma.conf.base.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @file karma自动化测试配置
  3. * @author fe.xiaowu@gmail.com
  4. */
  5. /**
  6. * 源文件
  7. *
  8. * @type {Array}
  9. */
  10. var sourceFileMap = [
  11. 'src/layui.js',
  12. 'src/lay/modules/jquery.js',
  13. 'src/lay/modules/carousel.js',
  14. 'src/lay/modules/code.js',
  15. 'src/lay/modules/element.js',
  16. 'src/lay/modules/flow.js',
  17. 'src/lay/modules/form.js',
  18. 'src/lay/modules/laydate.js',
  19. 'src/lay/modules/layedit.js',
  20. 'src/lay/modules/layer.js',
  21. 'src/lay/modules/laypage.js',
  22. 'src/lay/modules/laytpl.js',
  23. 'src/lay/modules/table.js',
  24. 'src/lay/modules/tree.js',
  25. 'src/lay/modules/upload.js',
  26. 'src/lay/modules/util.js',
  27. 'src/lay/modules/mobile/zepto.js',
  28. 'src/lay/modules/mobile/layer-mobile.js',
  29. 'src/lay/modules/mobile/upload-mobile.js'
  30. ];
  31. /**
  32. * 测试覆盖率文件, 要忽略 jquery.js、zepto.js
  33. *
  34. * @type {Object}
  35. */
  36. var coverageFileMap = {};
  37. sourceFileMap.filter(function (uri) {
  38. return !/(jquery|zepto)\.js$/.test(uri);
  39. }).forEach(function (uri) {
  40. coverageFileMap[uri] = ['coverage'];
  41. });
  42. module.exports = function (config) {
  43. return {
  44. // base path that will be used to resolve all patterns (eg. files, exclude)
  45. basePath: '',
  46. // Important: 所有插件必须在此声明
  47. plugins: ['karma-*'],
  48. // frameworks to use
  49. // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
  50. // Important: 下列数组中文件将『逆序载入』
  51. frameworks: ['mocha', 'chai', 'chai-sinon'],
  52. // list of files / patterns to load in the browser
  53. files: sourceFileMap.concat('test/**/*.js').concat({
  54. pattern: 'src/css/**/*',
  55. included: false
  56. }, {
  57. pattern: 'src/font/**/*',
  58. included: false
  59. }, {
  60. pattern: 'src/images/**/*',
  61. included: false
  62. }),
  63. // list of files to exclude
  64. exclude: [],
  65. // preprocess matching files before serving them to the browser
  66. // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
  67. preprocessors: coverageFileMap,
  68. // test results reporter to use
  69. // possible values: 'dots', 'progress'
  70. // available reporters: https://npmjs.org/browse/keyword/karma-reporter
  71. reporters: [
  72. 'mocha'
  73. // 'coverage'
  74. ],
  75. coverageReporter: {
  76. // specify a common output directory
  77. dir: '.',
  78. reporters: [
  79. // { type: 'html', subdir: 'report-html' },
  80. {
  81. type: 'lcov',
  82. subdir: 'coverage'
  83. },
  84. {
  85. type: 'text-summary'
  86. }
  87. ]
  88. },
  89. // web server port
  90. port: 9876,
  91. // enable / disable colors in the output (reporters and logs)
  92. colors: true,
  93. // level of logging
  94. // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  95. // Note: 如果要调试Karma,请设置为DEBUG
  96. logLevel: config.LOG_INFO,
  97. // start these browsers
  98. // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
  99. browsers: [
  100. 'PhantomJS'
  101. ],
  102. // enable / disable watching file and executing tests whenever any file changes
  103. // Note: 代码改动自动运行测试,需要singleRun为false
  104. autoWatch: false,
  105. // Continuous Integration mode
  106. // if true, Karma captures browsers, runs the tests and exits
  107. // 脚本调用请设为 true
  108. singleRun: true
  109. };
  110. };