I'm building a REST API in which I have many unit tests.
I need now to have some information about them, like code coverage.
I've read many articles dealing with Istanbul and Isparta, and their ability to run test coverage (with mocha's help) of ES6 code (this article) so I wanted to use them.
I'm working with NodeJS 0.12.7, and I use Babel transpiler to convert my ES6 code to ES5.
I use gulp tasks like following:
/* Unit test task */
gulp.task('pre-test', function() {
return gulp.src(['src/app/**/*.js'])
.pipe(plumber())
.pipe(istanbul({
instrumenter: isparta.Instrumenter,
includeUntested: true
}))
.pipe(istanbul.hookRequire());
});
gulp.task('test:unit', ['pre-test'], function() {
return gulp.src(['src/test/unit/**/*.js'])
.pipe(mocha({
reporter: 'spec'
}))
.pipe(istanbul.writeReports({}));
});
However, when trying to use the tools like below, I have these kinds of errors:
C:\projects\nodejs\project\src\test\unit\core\TestConfReader.js:1
(function (exports, require, module, __filename, __dirname) { import ConfReade
^^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
It means that istanbul isn't able to recognize ES6 code. I'm probably missing something right there.
So my question is:
How can I unit tests and apply test coverage on my ES6 code (and not on the ES5 code, that has many generated code like a try/catch in each class constructor) with Node 0.12.7?