我从Github下载了ng-boilerplate
app,我正在浏览它以帮助我了解AngularJS和测试。
我做的第一件事就是尝试了解Karma测试的工作原理。所以我在Karma文件夹中打开了一个命令提示符,然后输入:
karma start karma-unit.tpl.js
我期望返回完美的测试结果(因为我没有触及任何代码)。但是,我得到了这个错误:
C:\Users\Imray\stuff\Angular JS\ng-boilerplate\karma\karma-unit.tpl.js:12
<% scripts.forEach( function ( file ) { %>'<%= file %>',
^
ERROR [config]: Invalid config file!
SyntaxError: Unexpected token <
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.parseConfig (C:\Users\Imray\stuff\Angular JS\ng-boilerplate\node_modules\karma\lib\config.js:250:22)
at Object.exports.start (C:\Users\Imray\stuff\Angular JS\ng-boilerplate\node_modules\karma\lib\server.js:286:20)
at Object.exports.run (C:\Users\Imray\stuff\Angular JS\ng-boilerplate\node_modules\karma\lib\cli.js:229:25)
at requireCliAndRun (C:\Users\Imray\AppData\Roaming\npm\node_modules\karma-cli\bin\karma:24:16)
为什么会这样?我做错了什么?
答案 0 :(得分:0)
我不确定但是你可能必须在运行karma start karma-unit.tpl.js
之前运行Grunt任务,因为那里有一些未经处理的字符串。
<% scripts.forEach( function ( file ) { %>'<%= file %>',
看起来不像有效的javascript,但更像是构建字符串
答案 1 :(得分:0)
您缺少karmaconfig任务:
/**
* In order to avoid having to specify manually the files needed for karma to
* run, we use grunt to manage the list for us. The `karma/*` files are
* compiled as grunt templates for use by Karma. Yay!
*/
grunt.registerMultiTask( 'karmaconfig', 'Process karma config templates', function () {
var jsFiles = filterForJS( this.filesSrc );
grunt.file.copy( 'karma/karma-unit.tpl.js', grunt.config( 'build_location' ) + '/karma-unit.js', {
process: function ( contents, path ) {
return grunt.template.process( contents, {
data: {
scripts: jsFiles
}
});
}
});
});
或者您只是删除它,或者忘记在您的业力任务之前添加它:
grunt.registerTask( 'build', [
'clean', 'html2js', 'jshint:source', 'jshint:test', 'karmaconfig',
'karma:continuous', 'karma:coverage'
]);
(删除了一些让它更容易看到的任务.karmaconfig任务也依赖于filterForJs函数。但这都包含在ng-boilerplate中,所以我没有在这里明确添加它)