問(wèn)題描述
我正在嘗試將我現(xiàn)有的測(cè)試流程集成到現(xiàn)在包含 React,但我在代碼覆蓋率部分上苦苦掙扎.通過(guò)遵循這個(gè)項(xiàng)目/教程,我已經(jīng)能夠讓我的單元測(cè)試正常工作 - https://github.com/danvk/mocha-react - http://www.hammerlab.org/2015/02/14/testing-react-web-apps-with-mocha/
I'm trying to integrate my existing test processes to now include React, but am struggling on the code coverage part. I've been able to get my unit tests working fine by following this project/tutorial - https://github.com/danvk/mocha-react - http://www.hammerlab.org/2015/02/14/testing-react-web-apps-with-mocha/
我一直在使用伊斯坦布爾來(lái)覆蓋我的節(jié)點(diǎn)代碼,它運(yùn)行良好.但是,我無(wú)法讓它覆蓋我在測(cè)試中使用的 jsx 文件.
I've been using Istanbul to cover my node code and it's working pretty well. However, I'm having trouble getting it to cover the jsx files that I'm using in my tests.
這是一個(gè)現(xiàn)有伊斯坦布爾任務(wù)的示例,它在 vanilla js(節(jié)點(diǎn)后端代碼)上也可以正常運(yùn)行
Here's an example of an existing Istanbul task, which also runs fine on vanilla js (node backend code)
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
gulp.task('test-api', function (cb) {
gulp.src(['api/**/*.js'])
.pipe(istanbul()) // Covering files
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
.on('finish', function () {
gulp.src(['test/api/*.js'])
.pipe(mocha())
.pipe(istanbul.writeReports()) // Creating the reports after tests runned
.on('end', cb);
我的問(wèn)題(我認(rèn)為)是我無(wú)法讓伊斯坦布爾識(shí)別 jsx 文件,或者它們沒(méi)有與測(cè)試中運(yùn)行的文件進(jìn)行比較.我嘗試使用 gulp-react 模塊 將 jsx 預(yù)編譯為 js,以便伊斯坦布爾可以使用它,但我'不確定它是否有效.它沒(méi)有以某種方式被覆蓋,我不確定問(wèn)題出在哪里.
My issue ( i think ) is I can't get Istanbul to recognize the jsx files or they're not being compared to what was run in the tests. I tried using the gulp-react module to precompile the jsx to js so it can be used by Istanbul, but I'm not sure if it's working. It's not being covered somehow and I'm not sure where the issue is.
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var react = require('gulp-react');
gulp.task('test-site-example', function (cb) {
gulp.src(["site/jsx/*.jsx"]) //Nothing is being reported by Istanbul (not being picked up)
.pipe(react()) //converts the jsx to js and I think pipes the output to Istanbul
.pipe(istanbul())
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
.on('finish', function () {
gulp.src(['test/site/jsx/*.js'], { //tests run fine in mocha, but nothing being shown as reported by mocha (not covered)
read: false
})
.pipe(mocha({
reporter: 'spec'
}))
.pipe(istanbul.writeReports())
.on('end', cb);
});
;
});
任何想法我做錯(cuò)了什么?或者關(guān)于如何將測(cè)試運(yùn)行器(最好是伊斯坦布爾)集成到 Gulp-Mocha-React 項(xiàng)目中的任何線索?
Any ideas what I'm doing wrong? Or any clue on how to integrate a test runner (preferably Istanbul) into a Gulp-Mocha-React project?
推薦答案
有一個(gè)庫(kù)你可以看看,gulp-jsx-coverage (https://github.com/zordius/gulp-jsx-coverage).
There is a library you can take a look at, gulp-jsx-coverage (https://github.com/zordius/gulp-jsx-coverage).
這篇關(guān)于如何覆蓋伊斯坦布爾的 React jsx 文件?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!