Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make it work with Harmony/ ES6/ ECMAScript6 ? #282

Closed
BrainCrumbz opened this issue Oct 9, 2014 · 14 comments
Closed

How to make it work with Harmony/ ES6/ ECMAScript6 ? #282

BrainCrumbz opened this issue Oct 9, 2014 · 14 comments
Labels
invalid This wasn't actually an issue

Comments

@BrainCrumbz
Copy link

Hello there. We're trying to setup intern to work with ES6 JavaScript code.
Until now we were able to (temporarily) edit intern-client.cmd (on Windows) so that node runs with --harmony option and so to overcome the initial errors.

But then other errors show up, like here below:

Transformation error; return original code
{ [Error: Line 5: Unexpected token {]
  index: 67,
  lineNumber: 5,
  column: 7,
  description: 'Unexpected token {' }
SyntaxError: Unexpected token {
    at Function.vm.runInThisContext (<some-path>\tb-addon\node_modules\intern\node_modules\istanbul\lib\hook.js:163:16)
    at <some-path>\tb-addon\node_modules\intern\node_modules\dojo\dojo.js:760:8
    at fs.js:271:14
    at Object.oncomplete (fs.js:107:15)

After some search, it seems those are due to Istanbul dep, not being able to handle ES6 (gotwarlost/istanbul#141, gotwarlost/istanbul#66), which in turn depends also on esprima and escodegen for that (gotwarlost/istanbul#129).

We kinda understood that there should be ways to pull this tools from some dedicated Harmony branches, not from the master. Could you please help us to figure out how to set up all that within intern?

Thanks

@csnover
Copy link
Member

csnover commented Oct 15, 2014

Thanks for writing!

In order to keep the bug tracker focused only on the development of Intern itself, we ask that people please follow the contribution guidelines and not submit questions to the bug tracker. Please read the Getting Support wiki for information on where to submit questions.

Once an Istanbul release supports ES6 we will be sure to upgrade dependencies to the supported version so it will Just Work.

Thank you again for your interest!

@csnover csnover closed this as completed Oct 15, 2014
@csnover csnover added the invalid This wasn't actually an issue label Oct 15, 2014
@rightaway
Copy link

Seems it still doesn't work, were you able to figure this out @BrainCrumbz?

@BrainCrumbz
Copy link
Author

No. We just dropped the whole thing at that time.

@RoystonS
Copy link

In case it's of use to you, all of the code and tests we run in Intern are written in ES6. We get it to run by using Babel to cross-compile it all over to ES5 beforehand. (It's all automated in gulp, so it's automatic and instantaneous.)

That might not work for you if you're just interested in pure Harmony execution, but it works for us as we're ultimately targeting browsers that don't do ES6 properly anyway. Also, be aware that one major pain area there is that Istanbul doesn't yet cope with reading in the source maps, so we can't get accurate coverage information against the ES6 source, only against the transpiled ES5.

@csnover
Copy link
Member

csnover commented Jun 15, 2015

If you want to run tests and just not have code coverage for the time being (as you’d get with any other testing system), you can set excludeInstrumentation: true in Intern 3 which will bypass the code instrumenter entirely. You can also probably just set it to /./ in Intern 2.

If full ES6 code instrumentation is something you want I am sure that the esprima/istanbul folks would be happy to receive patches, but I don’t think the native implementations are ready for primetime yet.

@rightaway
Copy link

I don't need instrumentation, but it doesn't seem to work with generators. I run it as iojs --harmony_arrow_functions ./node_modules/.bin/intern-client --config=intern.js and the output is

PASS: main - unit - test (0ms)
0/1 tests failed
0/1 tests failed

It passes but it should fail.

'use strict';

function *delay() {
  return new Promise((resolve, reject) => {
    setTimeout(() => resolve('value'), 1000);
  });
}

define((require) => {
  const bdd = require('intern!bdd');
  const assert = require('intern/dojo/node!assert');
  bdd.describe('unit', () => {
    bdd.it('test', function *() {
      const value = yield delay();
      assert.equal(value, 'wrongvalue');
    });
  });
});

@csnover
Copy link
Member

csnover commented Jun 20, 2015

What do you expect the result to be when you pass a generator instead of a function?

@rightaway
Copy link

The yield delay() would cause the promise to be resolved after a delay of 1000ms with a result string 'value', which would be compared against 'wrongvalue' in the assertion and fail.

Even though Mocha supports ES6 too it still needs the https://www.npmjs.com/package/co-mocha library to be required to automatically make it work with generators. But then code equivalent to what's in my previous message would work as I described. Anything comparable for intern? Or plans to support such a case?

@csnover
Copy link
Member

csnover commented Jun 27, 2015

We can probably support a generator-like function natively but it should be done under a new enhancement request. The API right now doesn’t say you can pass a generator, only a standard function that returns a promise.

@siboulet
Copy link

@csnover Latest version of Istanbul (0.3.17) has an updated esprima dependency which apparently has better support for ES6. Any chances we can get an Istanbul version bump to 0.3.17 for Intern 3.x? gotwarlost/istanbul#66

@parametrization
Copy link

If Istanbul could do ES6 coverage properly, is that all that is in the way of using Intern for both unit and functional tests, complete with coverage? I ask because I'm in the midst of figuring out a new functional framework for my company.

If I don't care about coverage of the app for now, how painful is it to use ES6 features inside the test code?

@dylans
Copy link

dylans commented Jul 25, 2015

@parametrization presumably you are still using Babel to transpile your ES6 code into something that can be run in all browsers today? In that case, it's just a matter of following the steps at https://theintern.github.io/intern/#testing-other-module to test transpiled code (for example, https://github.com/theintern/intern-examples/blob/master/react-example/tests/support/jsx.js is how you could test React code that uses JSX), or to just transpile everything from ES6 modules to AMD modules prior to testing (e.g. like we suggest for TypeScript testing at https://www.sitepen.com/blog/2015/03/24/testing-typescript-with-intern/ ).

So I would think you can write your tests using ES6, and use Babel to transpile your tests into ES5 + AMD modules, and then then run them.

@dylans
Copy link

dylans commented Jul 25, 2015

@siboulet We're late into the release candidate stage for Intern 3, but it's up to @csnover and @jason0x43 to decide on that, or if we wait until 3.1 or 4.0 for a change to Istanbul.

@csnover
Copy link
Member

csnover commented Jul 27, 2015

I opened a separate ticket at #445 for tracking the Istanbul update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This wasn't actually an issue
Projects
None yet
Development

No branches or pull requests

7 participants