1

I am creating a hapi api seed project. I have opted to use es6 syntax in the source of the project. I am using hapi-lab as my testing framework. Its integrated and I can run it using 'npm test' via a reference in the package.json file.

"scripts": {
    "test": "lab -T ./node_modules/lab-babel -I __core-js_shared__"
  }
  ...
  //from the cmd line
  npm test

This is working fine - although I am using es6 syntax in the test:

import Server from '../../src/server.js';
import Code from 'code';
import Lab from  'lab';

I want to be able to run the tests from gulp. I am using 'gulp-lab'. It starts to run but then throws an error.

SyntaxError: Unexpected reserved word 

Its pointing to the use of import - which I get as its es6. So I tried to pipe the test js through babel before sending it to lab (see below). Unfortunately I get the same error.

Here is the relevant section of my gulp file - any suggestions?

import gulp from 'gulp';
import babel from 'gulp-babel';
import lab from 'gulp-lab';   

    gulp.task('test', function () {
        return gulp.src('test/**/*.js')
            .pipe(babel())
            .pipe(lab());
       });

I can post the rest of the gulp file if it would be useful to see how the build works.

Here is my .babelrc file:

//use es2015 preset to convert es6 js to es5 equivalent
{
    "presets": [ "es2015" ],
    'plugins': [
        'transform-es2015-template-literals',
        'transform-es2015-block-scoping'
    ]
}
simon-p-r
  • 3,623
  • 2
  • 20
  • 35
Scott Wright
  • 186
  • 1
  • 11
  • Usually you may want to use build tool (Gulp) to build the rest of the app. It is a 'who will build a builder' problem. The easiest way to handle this is to not use ES6 features that are not supported by Node (ES6 modules) in parts you don't intend to transpile. – Estus Flask Oct 22 '16 at 18:13
  • I still want to be able to use es6 syntax across the project. But I see where my issue is now. Although my tests were being transpiled successfully the tests themselves are importing src/server.js which is the non-transpiled version of the code. A possible fix, (just tried and it works) for the issue is to point the tests at the 'build' or trasnpiled directory. But this could present future issues. Anyone with anything better? – Scott Wright Oct 22 '16 at 18:35

0 Answers0