Reputation: 11108
I am trying to use gulp-babel with gulp-mocha as following:
var mocha = require('gulp-mocha');
var babel = require('gulp-babel');
gulp.task('test', function() {
return gulp.src('test/*.js', {read: false})
.pipe(babel({presets: ['es2015']}))
.pipe(mocha());
});
But that doesn't seem to work, with error such as
(function (exports, require, module, __filename, __dirname) { import {assert}
^^^^^^
Unexpected reserved word
I have documented this case here https://github.com/tnguyen14/babel-gulp-mocha-test
I am not sure if I am doing something wrong? Any help would be hugely appreciated.
EDIT: please try this with node 0.12. Node 4.x will just work, but won't prove anything as it already supports the ES2015 method in the test here, i.e. endsWith
.
Upvotes: 3
Views: 1041
Reputation: 11108
What I was missing is babel-polyfill
. The es2015
preset does not provide new ES2015 functionality, it just helps with the newer syntax.
Adding the polyfill solves this problem. See more details at this issue here https://phabricator.babeljs.io/T2967
Upvotes: 2
Reputation: 2023
It works with the following, combined with .babelrc:
var gulp = require('gulp');
var babel = require('gulp-babel');
var mocha = require('gulp-mocha');
require("babel-core/register");
gulp.task('test', function () {
return gulp.src('test/*.js', {read: false})
.pipe(babel())
.pipe(mocha({
ui: 'tdd'
}));
});
Upvotes: 1