我有一个使用Mocha json reporter的示例吞咽任务。我想把这个json输出写到一个文件中。会很感谢你的一些建议。
下面是我的代码:
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var util = require('gulp-util');
gulp.task('myreport', function() {
return gulp.src(['tests.js'], { read: false })
.pipe(mocha({ reporter: 'json' })) //how do I write this to a file?
.on('error', util.log);
});发布于 2016-01-21 00:46:20
我已经通过查看源代码使它工作起来了。看起来gulp-mocha并没有遵循gulp管道来推动它的外包。您可以在任务执行期间临时映射结果,但可以使用process.stdout.write。
这里有一个简单的例子。
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
gutil = require('gulp-util'),
fs = require('fs');
gulp.task('test', function () {
//pipe process.stdout.write during the process
fs.writeFileSync('./test.json', '');
process.stdout.write = function( chunk ){
fs.appendFile( './test.json', chunk );
};
return gulp.src(['hello/a.js'], { read: false })
.pipe(mocha({ reporter: 'json' }))
.on('error', gutil.log);
});发布于 2016-03-06 21:26:37
使用mochawesome,你会得到JSON输出,还有更多:https://www.npmjs.com/package/mochawesome
使用这个报告器的另一个好处是,你不会破坏你的JSON,在console.log消息上写流,等等。
.pipe(mocha({reporter: 'mochawesome'}))

发布于 2016-03-07 05:57:10
你就不能直接用管道把它传给gulp.dest吗
.pipe(gulp.dest('./somewhere')); https://stackoverflow.com/questions/34878744
复制相似问题