Нет описания

karma.conf.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Karma configuration file
  2. var karma = require("karma");
  3. var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
  4. var DEFAULT_NG_VERSION = "1.6";
  5. /**
  6. * This returns a Karma 'files configuration'.
  7. * http://karma-runner.github.io/0.8/config/files.html
  8. *
  9. * Specifies which files can be served by the Karma web server
  10. *
  11. * included: true -- files that are always served to the browser (like <script> tag)
  12. * included: false -- files *available to be served* by karma, for instance via require()
  13. */
  14. function karmaServedFiles(ngVersion) {
  15. // Returns necessary files for a specific version of angular
  16. function angular(version) {
  17. console.log('Using Angular ' + ngVersion + ' from test/angular/' + version + '/angular.js');
  18. return [
  19. 'test/angular/' + version + '/angular.js',
  20. 'test/angular/' + version + '/angular-mocks.js',
  21. 'test/angular/' + version + '/angular-animate.js',
  22. ];
  23. }
  24. var angularFiles = angular(ngVersion).map(function (pattern) {
  25. return { watched: false, included: true, nocache: true, pattern: pattern };
  26. });
  27. return angularFiles.concat('test/index.js');
  28. }
  29. var webpackConfig = module.exports = {
  30. resolve: {
  31. modules: ['node_modules'],
  32. extensions: ['.js', '.jsx', '.ts', '.tsx']
  33. },
  34. devtool: 'inline-source-map',
  35. module: {
  36. rules: [
  37. { test: /\.tsx?$/, loader: 'ts-loader', options: { transpileOnly: true } }
  38. ]
  39. },
  40. stats: false,
  41. plugins: [
  42. new ForkTsCheckerWebpackPlugin(),
  43. ],
  44. externals: [ 'angular' ]
  45. };
  46. module.exports = function(config) {
  47. var ngVersion = config.ngversion || DEFAULT_NG_VERSION;
  48. config.set({
  49. singleRun: true,
  50. autoWatch: false,
  51. autoWatchInterval: 0,
  52. // level of logging
  53. // possible values: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
  54. logLevel: "warn",
  55. // possible values: 'dots', 'progress'
  56. reporters: 'dots',
  57. colors: true,
  58. port: 8080,
  59. // base path, that will be used to resolve files and exclude
  60. basePath: '.',
  61. // Start these browsers, currently available:
  62. // Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
  63. browsers: ['PhantomJS'],
  64. frameworks: ['jasmine'],
  65. plugins: [
  66. require('karma-webpack'),
  67. require('karma-sourcemap-loader'),
  68. require('karma-jasmine'),
  69. require('karma-phantomjs-launcher'),
  70. require('karma-chrome-launcher')
  71. ],
  72. webpack: webpackConfig,
  73. webpackMiddleware: {
  74. stats: { chunks: false },
  75. },
  76. /* Files *available to be served* by karma, i.e., anything that will be require()'d */
  77. files: karmaServedFiles(ngVersion),
  78. preprocessors: {
  79. 'test/index.js': ['webpack', 'sourcemap'],
  80. '../src/ng1': ['webpack', 'sourcemap'],
  81. },
  82. });
  83. };