【发布时间】:2015-09-06 12:16:39
【问题描述】:
我正在通过Gulp 使用Jasmine 测试一些JavaScript。我想创建自己的记者。在这个时候,我的记者是最基本的。它看起来像这样:
'use strict';
var myCustomReporter = {
jasmineStarted: function(suiteInfo) {
console.log('Running suite with ' + suiteInfo.totalSpecsDefined);
console.log('Reporting via MyCustomReporter');
},
suiteStarted: function(result) {
console.log('Suite started: ' + result.description + ' whose full description is: ' + result.fullName);
},
specStarted: function(result) {
console.log('Spec started: ' + result.description + ' whose full description is: ' + result.fullName);
},
specDone: function(result) {
},
suiteDone: function(result) {
},
jasmineDone: function() {
console.log('Finished suite');
}
};
上面的代码本质上就是Jasmine提供的example custom reporter。我的挑战是,我无法弄清楚如何让 Jasmine 真正使用它。不知怎么的,我添加不正确。我是这样添加的:
gulp.task('test', function() {
// Load the reporters to use with Jasmine
var myReporter = require('./reporters/myCustomReporter');
var reporters = [
myReporter
];
return gulp.src(input.tests)
.pipe(jasmine({ reporter: reporters }))
;
});
当我通过 Gulp 执行 test 任务时,我得到以下输出:
[08:04:15] Using gulpfile ~/MyProject/gulpfile.js
[08:04:15] Starting 'test'...
[08:04:20] 'test' errored after 5.25 s
[08:04:20] Error in plugin 'gulp-jasmine'
Message:
Tests failed
如果我在调用 Jasmine 时没有传递 { reporter: reporters },我的测试运行良好。我正在尝试学习如何 a) 添加我的记者和 b) 仍然使用默认记者。本质上,我试图弄清楚如何将结果发送给多个记者。我认为我的做法是正确的。显然,结果表明我错了。
【问题讨论】:
-
茉莉花的哪个版本?你读过文档吗?
-
@DanielA.White 我确实阅读了文档。这就是为什么我对它不起作用感到非常困惑。在我的 package.json 文件中,我有
"gulp-jasmine": "^2.0.1" -
@DanielA.White 我的语法基于此处显示的内容:github.com/sindresorhus/gulp-jasmine
-
只是为了确定,您是否在第一个 sn-p 中导出了 myCustomReporter?
-
@hege_hegedus - 我没有进行导出。当我添加
module.exports = myCustomReporter;时,记者跑了。但是,它仍然没有显示默认报告器。
标签: javascript jasmine gulp gulp-jasmine