Karma runner执行测试用例的问题

时间:2014-04-11 04:30:17

标签: angularjs karma-runner

我正在开发一个使用Karma作为执行测试用例的测试工具的应用程序。问题是,当我尝试执行测试用例时,它不会执行任何测试而不是仅仅停留在某个点上。当我使用此命令时

grunt test --force 

我收到了这个结果

Running "clean:server" (clean) task

Running "concurrent:test" (concurrent) task

Running "compass:dist" (compass) task

Running "compass:server" (compass) task

Done, without errors.

Running "connect:test" (connect) task
Warning: Arguments to path.resolve must be strings Used --force, continuing.

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/

在没有进展之后,它只是停留在这里。这是我的karma.conf.js文件

// Karma configuration

// base path, that will be used to resolve files and exclude
basePath = '';
 module.exports = function(config) {
   config.set({
     frameworks: ['jasmine']
   });
 };
// list of files / patterns to load in the browser
files = [
  'bower_components/angular/angular.min.js',
  'bower_components/angular-route/angular-route.js',
  'bower_components/angular-resource/angular-resource.js',
  'bower_components/angular-animate/angular-animate.js',
  'bower_components/angular-sanitize/angular-sanitize.js',
  'bower_components/ng-grid/lib/jquery-1.9.1.js',
  'bower_components/ng-grid/ng-grid-2.0.7.min.js',
  'bower_components/angular-mocks/angular-mocks.js',
  'bower_components/angular-bootstrap/ui-bootstrap.js',
  'bower_components/momentjs/moment.js',
  'bower_components/nprogress/nprogress.js',
  'bower_components/toastr/toastr.js',
  'app/*.js',
  'app/**/*.js',
  '../sinonjs/test.js'
];

// list of files to exclude
exclude = ['app/out.js'];

preprocessors = {
  'app/*.js': 'coverage',
  'app/**/*.js': 'coverage'
};

// test results reporter to use
// possible values: dots || progress || growl
// for test coverage2 
reporters = ['progress', 'coverage'];
coverageReporter = {
  type : 'html',
  dir : 'coverage/'
}

// test results reporter to use
// possible values: dots || progress || growl
//reporters = ['progress'];

// web server port
port = 8080;

// cli runner port
runnerPort = 9100;

// enable / disable colors in the output (reporters and logs)
colors = true;

// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
//logLevel = LOG_INFO;

// enable / disable watching file and executing tests whenever any file changes
autoWatch = false;

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = ['Chrome'];

// If browser does not capture in given timeout [ms], kill it
captureTimeout = 5000;

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = false;

这可能是什么问题?

当我在logLevel文件中添加karma.conf.js配置时,我得到了以下结果

Running "clean:server" (clean) task

Running "concurrent:test" (concurrent) task

Running "compass:dist" (compass) task

Running "compass:server" (compass) task

Done, without errors.

Running "connect:test" (connect) task
Warning: Arguments to path.resolve must be strings Used --force, continuing.

Running "karma:unit" (karma) task
DEBUG [plugin]: Loading karma-* from E:\wamp\www\balto4forms\node_modules
DEBUG [plugin]: Loading plugin E:\wamp\www\balto4forms\node_modules/karma-chrome
-launcher.
DEBUG [plugin]: Loading plugin E:\wamp\www\balto4forms\node_modules/karma-coffee
-preprocessor.
DEBUG [plugin]: Loading plugin E:\wamp\www\balto4forms\node_modules/karma-firefo
x-launcher.
DEBUG [plugin]: Loading plugin E:\wamp\www\balto4forms\node_modules/karma-html2j
s-preprocessor.
DEBUG [plugin]: Loading plugin E:\wamp\www\balto4forms\node_modules/karma-jasmin
e.
DEBUG [plugin]: Loading plugin E:\wamp\www\balto4forms\node_modules/karma-phanto
mjs-launcher.
DEBUG [plugin]: Loading plugin E:\wamp\www\balto4forms\node_modules/karma-requir
ejs.
DEBUG [plugin]: Loading plugin E:\wamp\www\balto4forms\node_modules/karma-script
-launcher.
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
DEBUG [watcher]: Resolved files:
        E:/wamp/www/balto4forms/node_modules/karma-jasmine/lib/jasmine.js
        E:/wamp/www/balto4forms/node_modules/karma-jasmine/lib/adapter.js

1 个答案:

答案 0 :(得分:1)

我通过包装module.exports功能下的所有配置设置自行解决了这个问题。现在我的karma.conf.js文件看起来像这样;

// Karma configuration

// base path, that will be used to resolve files and exclude

 module.exports = function(config) {
   config.set({
   basePath : '',
     frameworks: ['jasmine'],
     logLevel: config.LOG_INFO,
// list of files / patterns to load in the browser
files : [
  'bower_components/angular/angular.min.js',
  'bower_components/angular-route/angular-route.js',
  'bower_components/angular-resource/angular-resource.js',
  'bower_components/angular-animate/angular-animate.js',
  'bower_components/angular-sanitize/angular-sanitize.js',
  'bower_components/ng-grid/lib/jquery-1.9.1.js',
  'bower_components/ng-grid/ng-grid-2.0.7.min.js',
  'bower_components/angular-mocks/angular-mocks.js',
  'bower_components/angular-bootstrap/ui-bootstrap.js',
  'bower_components/momentjs/moment.js',
  'bower_components/nprogress/nprogress.js',
  'bower_components/toastr/toastr.js',
  'app/*.js',
  'app/**/*.js',
  '../sinonjs/test.js'
],

// list of files to exclude
exclude : ['app/out.js'],

preprocessors : {
  'app/*.js': 'coverage',
  'app/**/*.js': 'coverage',
},

// test results reporter to use
// possible values: dots || progress || growl
// for test coverage2 
reporters : ['progress', 'coverage'],
coverageReporter : {
  type : 'html',
  dir : 'coverage/'
},

// test results reporter to use
// possible values: dots || progress || growl
//reporters : ['progress'];

// web server port
port : 8080,

// cli runner port
runnerPort : 9100,

// enable / disable colors in the output (reporters and logs)
colors : true,

// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
//logLevel : LOG_INFO;

// enable / disable watching file and executing tests whenever any file changes
autoWatch : false,

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers : ['Chrome'],

// If browser does not capture in given timeout [ms], kill it
captureTimeout : 5000,

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun : false
   });
 };

现在所有测试用例都正常运行。