2017-08-01 25 views
1

请安置,我已经将我的代码从es6转换为es5,并使用gulp作为任务执行者。我已经完成了伊斯坦布尔的报道报道。它没有显示设置后的测试覆盖率。下面是我的代码如何使用Gulp显示使用gulp-mocha的测试覆盖范围

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'; 

装入大口插件到plugins变量

const plugins = loadPlugins(); 

gulp.task('tests',() => { 
    gulp.src('./server/tests/*.js') 
    .pipe(plugins.babel()) 
    .pipe(mocha()) 
    .pipe(exit()); 
}); 

编译所有通天的Javascript到ES5,地点在蒸馏水文件夹

const paths = { 
    js: ['./**/*.js', '!dist/**', '!node_modules/**'] 
}; 

编译所有通天的Javascript到ES5并将其放入分机目录

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']); 
+0

什么没有显示设置后覆盖报告它呢?它是什么'? – user2347763

回答

1

下面的代码片段走过我是如何解决这个问题有一点点修改每一个变化。

把下面的代码在你gulpfile

import gulp from 'gulp'; 
import loadPlugins from 'gulp-load-plugins'; 
import path from 'path'; 
import shell from 'gulp-shell'; 

// Load the gulp plugins into the `plugins` variable 
const plugins = loadPlugins(); 

// Compile all Babel Javascript into ES5 and place in dist folder 
const paths = { 
    js: ['./**/*.js', '!dist/**', '!node_modules/**', 
    '!./server/tests/**'] 
}; 

// Compile all Babel Javascript into ES5 and put it into the dist dir 
gulp.task('babel',() => 
    gulp.src(paths.js, { base: '.' }) 
    .pipe(plugins.babel()) 
    .pipe(gulp.dest('dist')) 
); 

gulp.task('migrate', shell.task([ 
    'cross-env NODE_ENV=test sequelize db:migrate', 
])); 

gulp.task('coverage', shell.task([ 
    'cross-env NODE_ENV=test nyc mocha ./server/test/**/*.js', 
])); 

// Restart server with on every changes made to file 
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', ['migrate', 'coverage']); 
gulp.task('default', ['nodemon']); 
gulp.task('production', ['babel']); 

然后去到你的package.json然后添加以下

"nyc": { 
    "require": [ 
     "babel-register" 
    ], 
    "reporter": [ 
     "lcov", 
     "text", 
     "html" 
    ], 
    "sourceMap": false, 
    "instrument": false, 
    "exclude": [ 
     "the test file you want to exclude from coverage" 
    ] 
    } 

绝对做

相关问题