Jasmine -使用自定义Reporter
Jasmine - Using a Custom Reporter
我正在通过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提供的示例自定义报告程序。我的挑战是,我不知道怎么让贾思敏真正使用它。不知怎么的,我加错了。我像这样添加:
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
如果我没有将{ reporter: reporters }
传递给Jasmine,我的测试运行得很好。我正在努力学习如何a)添加我的记者和b)仍然使用默认的记者。从本质上讲,我正在设法弄清楚如何将结果发送给多个记者。我认为我的方法是正确的。很明显,结果表明我错了。
首先确保您导出了自定义报告器,如module.exports = myCustomReporter;
。
根据gulp-jasmine的源代码,默认报告器不公开。相关代码:
var Reporter = require('jasmine-terminal-reporter');
...
module.exports = function(options) {
...
var color = process.argv.indexOf('--no-color') === -1;
var reporter = options.reporter;
if (reporter) {
(Array.isArray(reporter) ? reporter : [reporter]).forEach(function (el) {
jasmine.addReporter(el);
});
} else {
jasmine.addReporter(new Reporter({
isVerbose: options.verbose,
showColors: color,
includeStackTrace: options.includeStackTrace
}));
}
...
};
你可以像这样添加默认的报告器:
gulp.task('test', function() {
// Load the reporters to use with Jasmine
var myReporter = require('./reporters/myCustomReporter');
var Reporter = require('jasmine-terminal-reporter');
var defaultReporter = new Reporter({
isVerbose: false,
showColors: true,
includeStackTrace: false
});
var reporters = [
defaultReporter,
myReporter
];
return gulp.src(input.tests)
.pipe(jasmine({ reporter: reporters }))
;
});
相关文章:
- Dojo不解析自定义小部件的模板html中的小部件声明性
- 在自定义mean.io包中使用angular-chart.js作为依赖项
- jQuery自定义验证比较多个输入的序列
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- 在wordpress一定时间后更改自定义字段
- 表达式引擎扩展开发-向呈现的条目添加自定义javascript
- 自定义函数中的光标位置
- 用于检查数组中是否存在元素的javascript自定义方法
- 绑定时将Parsley minlength消息作为选项传递时,未对其进行自定义
- Meteor-添加用户自定义字段的方法不起作用
- 自定义表单验证和提交
- jQuery工具验证器自定义效果-添加&消除影响
- 可以't计算自定义谷歌地图的js
- 谷歌水印未显示在自定义搜索框中
- vaadin:使用自定义布局集成angular js
- DataTables-创建自定义分页样式(加载更多样式)
- 实现一个建立在google.com之上的自定义搜索引擎
- 添加自定义标记以自动完成
- 如何使用自定义标头跨域执行AJAX POST
- Jasmine -使用自定义Reporter