我正在尝试将我的测试集成到竹子中。使用竹子,我似乎需要测试结果为junit xml格式。因此,我需要让我的“grunt jasmine”执行以 xml 格式输出测试结果。我是 jasmine/grunt/junit 的新手,并且花费的时间比我愿意承认的要多得多。我遵循了各种教程和板(主要是https://gist.github.com/asabaylus/3059886),但只是卡住了。
当我从 gitbash 运行“grunt jasmine”时,规范运行成功,但没有生成输出文件,并且出现以下错误...“处理模板时发生错误(无法调用未定义的方法 'indexO f')。使用 --force 继续。
因警告而中止。”
我必须更改任何其他文件吗?谁能帮我解决这个问题?
请和谢谢!抄送
grunt.js 文件
/*global module:false*/
module.exports = function ( grunt ) {
// Project configuration.
grunt.initConfig({
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
},
lint: {
files: ['grunt.js', 'src/**/*.js']
},
jasmine: {
all: ['./SpecRunner.html'],
junit: {
dest: 'test-results'
}
},
concat: {
dist: {
src : ['<banner:meta.banner>', '<file_strip_banner:src/buyitnow.js>'],
dest: 'dist/buyitnow/<%= meta.version %>/buyitnow.js'
}
},
min: {
dist: {
src : ['<banner:meta.banner>', '<config:concat.dist.dest>'],
dest: 'dist/buyitnow/<%= meta.version %>/buyitnow.min.js'
}
},
watch: {
files: '<config:lint.files>',
tasks: 'lint'
},
jshint: {
options: {
curly : true,
eqeqeq : true,
immed : true,
latedef: true,
newcap : true,
noarg : true,
sub : true,
undef : true,
boss : true,
eqnull : true,
browser: true,
jquery : true,
node : true
},
globals: {}
},
uglify: {}
});
grunt.loadNpmTasks('grunt-jasmine-task');
// Default task.
grunt.registerTask('default', 'lint jasmine concat min cssmin');};
我的 specrunner.html 文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine.async.min.js"></script>
<script type="text/javascript" src="lib/sinon-1.6.0.js"></script>
<!-- For JUnit output of test results include the following link to Lary Myer's JUnit reporter -->
<script type="text/javascript" src="node_modules/jasmine-reporters/src/jasmine.junit_reporter.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/binSpec.js"></script>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
// Specify target test results folder as below, for now
var junitReporter = new jasmine.JUnitXmlReporter('test-results/');
jasmineEnv.addReporter(junitReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>