拜托,我已经使用 gulp 作为任务运行器将我的代码从 es6 转换为 es5。我已经在伊斯坦布尔完成了我的报道。设置后它没有显示测试覆盖率。下面是我的代码
import gulp from 'gulp';
import loadPlugins from 'gulp-load-plugins';
import path from 'path';
import mocha from 'gulp-mocha';
import exit from 'gulp-exit';
import coveralls from 'gulp-coveralls';
import cover from 'gulp-coverage';
将 gulp 插件加载到plugins
变量中
const plugins = loadPlugins();
gulp.task('tests', () => {
gulp.src('./server/tests/*.js')
.pipe(plugins.babel())
.pipe(mocha())
.pipe(exit());
});
将所有 Babel Javascript 编译成 ES5 并放在 dist 文件夹中
const paths = {
js: ['./**/*.js', '!dist/**', '!node_modules/**']
};
将所有 Babel Javascript 编译成 ES5 并放入 dist 目录
gulp.task('babel', () =>
gulp.src(paths.js, { base: '.' })
.pipe(plugins.babel())
.pipe(gulp.dest('dist'))
);
gulp.task('coverage', () => {
gulp.src('server/test/**/*.js', { read: false })
.pipe(cover.instrument({
pattern: ['server/controllers/**/*.js'],
debugDirectory: 'debug'
}))
.pipe(mocha())
.pipe(cover.gather())
.pipe(cover.format())
.pipe(gulp.dest('reports'));
});
gulp.task('coveralls', () => gulp.src('./coverage/lcov')
.pipe(coveralls()));
每次对文件进行更改时重新启动服务器
gulp.task('nodemon', ['babel'], () =>
plugins.nodemon({
script: path.join('dist', 'index.js'),
ignore: ['README.md', 'node_modules/**/*.js', 'dist/**/*.js'],
ext: 'js',
tasks: ['babel']
})
);
gulp.task('test', ['tests']);
gulp.task('default', ['nodemon']);
gulp.task('production', ['babel']);