問題描述
我正在嘗試將我現有的測試流程集成到現在包含 React,但我在代碼覆蓋率部分上苦苦掙扎.通過遵循這個項目/教程,我已經能夠讓我的單元測試正常工作 - 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/
我一直在使用伊斯坦布爾來覆蓋我的節點代碼,它運行良好.但是,我無法讓它覆蓋我在測試中使用的 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.
這是一個現有伊斯坦布爾任務的示例,它在 vanilla js(節點后端代碼)上也可以正常運行
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);
我的問題(我認為)是我無法讓伊斯坦布爾識別 jsx 文件,或者它們沒有與測試中運行的文件進行比較.我嘗試使用 gulp-react 模塊 將 jsx 預編譯為 js,以便伊斯坦布爾可以使用它,但我'不確定它是否有效.它沒有以某種方式被覆蓋,我不確定問題出在哪里.
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);
});
;
});
任何想法我做錯了什么?或者關于如何將測試運行器(最好是伊斯坦布爾)集成到 Gulp-Mocha-React 項目中的任何線索?
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?
推薦答案
有一個庫你可以看看,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).
這篇關于如何覆蓋伊斯坦布爾的 React jsx 文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!