3

I would like to build my Javascript ES6 application using Gulp, Karma and PhantomJS but Phantom doesn't want to hear about any ES6 expression. I'm using PhantomJS v2.1 which is supposed to support ES6. I've also tried without browserify and babelify but no more success.

Any idea what am I missing here?

Here's my test code:

index.js:

"use strict";

const a = 5;

gulpfile.js:

'use strict';

var gulp = require('gulp');
var karma = require('gulp-karma');

function testClientCode() {
    return gulp.src('index.js')
      .pipe(karma({
          configFile: 'karma.conf.js',
          action: 'run'
       }))
      .on('error', function(err) {
          throw err;
       });
}

gulp.task('test-client', testClientCode);

karma.conf.js:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['browserify'],
    reporters: ['spec'],
    port: 9876,
    urlRoot: '/',
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false,
    browsers: ['PhantomJS'],
    singleRun: false,

    browserify: {
      debug: true,
      transform: [ 'babelify' ]
    }

  });
};

And here's what I got when launching gulp:

[12:45:57] Using gulpfile /media/data/dev/testes6/gulpfile.js
[12:45:57] Starting 'test-client'...
[12:45:58] Starting Karma server...
27 05 2016 12:45:59.384:INFO [framework.browserify]: bundle built
27 05 2016 12:45:59.390:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
27 05 2016 12:45:59.397:INFO [launcher]: Starting browser PhantomJS
27 05 2016 12:45:59.587:INFO [PhantomJS 2.1.1 (Linux 0.0.0)]: Connected on socket /#eWK70DGTBDXsN94xAAAA with id 72822062
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  SyntaxError: Unexpected token 'const'
  at /media/data/dev/testes6/index.js:3

Thanks!

Tdy
  • 863
  • 12
  • 28
  • Hi, did you find a solution for that? – amgohan Jul 27 '16 at 03:58
  • No, I didn't find any solution. After hours of research, I just decided not to use ES6 on my frontend code for now. If I have time, maybe I'll take another look to find a solution. I have the feeling that it can be done with browserify or babel or something, but didn't find out the right way – Tdy Jul 27 '16 at 06:29

1 Answers1

0

This guy here is saying that using gulp-babel might help, take a look at the section called "Karma testing suite and ES6". I have the same problem so far, but haven't tried it yet.