douglasduteil/isparta

Babel 6 Support

Closed this issue ยท 60 comments

Can't run tests under a project that uses babel 6 because isparta depends on babel 5...

Hi @spudly
I will spend some time on it tomorrow.

It doesn't require much work I think to upgrade the version, but some tests could fail because of Babel known issues. (class properties are one of them for example)

one issue I'm seeing is .babelrc presets flag blowing up. Thanks for your assistance and work!

Trying to run tests and getting the next error

Transformation error; return original code
[ReferenceError: [BABEL] /Users/ghaiklor/Library/Projects/passport-amazon-token/src/index.js: Unknown option: /Users/ghaiklor/Library/Projects/passport-amazon-token/.babelrc.presets]

The presets warning is shown because isparta depends on babel-code@5.x, which doesn't have a presets option.

testing my fork shortly. hopefully I'll have a PR for you before long

eh.... it's building, but failing tests. feel free to take a look, hopefully my work can help you along.

What are the errors? Did you try to remove the es6 classes tests?

Hmm I just tried and got this error, but no idea where it comes from.

Invariant Violation: To get a node path the parent needs to exist

Ok, I think I have it ready, but it looks like:
export * from
is broken in babel6 currently.
Otherwise I think my fork is nearly ready.

Great @mikeallisonJS ๐Ÿ‘
I know I opened an issue about that babel/babel#2763

Here's what I'm seeing with Babel 6.0.15

.babelrc:

{
  "presets": ["es2015"]
}
$ babel-node ./node_modules/.bin/isparta cover _mocha
Transformation error; return original code
[ReferenceError: [BABEL] src/lib.js: Unknown option: .babelrc.presets]

No coverage information was collected, exit without writing coverage information

If I remove the presets options from .babelrc, and use the command line option, everything works:

$ babel-node --presets es2015 ./node_modules/.bin/isparta cover _mocha
Transformation error; return original code
{ [Error: Line 1: Unexpected token ILLEGAL]
  lineNumber: 1,
  description: 'Unexpected token ILLEGAL',
  index: 0 }

=============================== Coverage summary ===============================
Statements   : 100% ( 138/138 ), 10 ignored
Branches     : 98.61% ( 71/72 ), 9 ignored
Functions    : 100% ( 12/12 )
Lines        : 100% ( 69/69 )
================================================================================

@nathancahill do you know why it says 10 ignored statements and 9 ignored branches? I've been having similar issues, but I don't have any ignore comments in my code. Do you?

I don't @jedmao. I double checked the coverage, and it seems to be working correctly. :shrugs:

@mikeallisonJS, I picked up where you left off with the export * bug in Babel. I hacked around it by enumerating the exports from Istanbul: d98dbba

Tests are running, it looks like some numbers in the ES6 classes are different than expected, but not too far off.

Cool, submitted #88. Besides the export * bug, even once that is fixed, it looks like the exports can not be overriden, like Instrumenter and VERSION. AFAIK, properties on the export object are set with configurable=false so they can't be deleted or changed. So we might have to export specific symbols anyway.

nkbt commented

For export stuff you need to use babel-plugin-transform-es2015-modules-commonjs. It is not included into presets. And it is not a bug

nkbt commented

Ah sorry, I see you are using stage-0, so it is included.

My workaround was not to use global babel config at all for the moment and let isparta use babel5, but rest uses babel6.

Scripts get a bit ugly though (since I heed to pass parameters manually)

"babel-node": "babel-node --presets es2015,react --plugins transform-es2015-modules-commonjs,transform-object-rest-spread",
"test:cov": "npm run babel-node -- node_modules/isparta/bin/isparta cover --report text --report html --dir reports/coverage --include \"**/!(*-test).js\" test",

20151107-214001

Can we expect an update soon? ๐Ÿ˜…

nkbt commented

@neoziro I'll try it asap, thanks

Aรฏe alright 3 PR for the same fix. Sorry guys for not being as available...
I will be merging every one tomorrow somehow :)

I would decently prefer a Babel fix. But I don't have the time to do it and this repo is already a hack anyway :D

So ya tomorrow guys for sure sorry again

nkbt commented

fixed by #91

nkbt commented

@douglasduteil publish on NPM? Or you first want to check something more? I guess it would be fairly safe to publish as new major release and push more patch versions in case of troubles

Great to see this! ๐Ÿ˜ƒ Is this fix published?

+1

nkbt commented

v4.0.0 is out \o/

@nkbt sry for the wait

nkbt commented

Thank you @douglasduteil

PS I've seen you added another breaking change, legit reason to delay major release ๐Ÿ‘Œ

Wait it's not working right for me...

Or is it ?

Thanks @douglasduteil, seems to work fine.

isparta is not working for me, as before =(

No coverage information was collected, exit without writing coverage information
โ€” https://travis-ci.org/iamstarkov/domain-links/jobs/91499048#L507
โ€” https://github.com/iamstarkov/domain-links/blob/master/package.json#L7

the same lines are working fine with babel v5 and isparta v3

nkbt commented

@iamstarkov are you sure that --require babel-core/register uses babel6 too and does not fail somewhere on the way?

I'm sure because mocha is working fine with that, take a look at npm test script and its output in travis

@nkbt how do you use isparta with babel v6 with mocha?

@iamstarkov I am also having the same issues. Worked fine with babel 5 and isparta v3.

Mocha is running the tests just fine on its own

  babel-node ./node_modules/.bin/isparta cover --verbose  --root './src' --include '**/*.es6' --include '**/*.jsx' --include '**/*.js' --report json-summary --report lcov _mocha -- --recursive --compilers es6:babel-core/register
Loading config: /Users/Dom/git/energy-scanner-web/.istanbul.yml
Using configuration
-------------------
verbose: true
instrumentation:
    root: ./src
    extensions:
        - .jsx
        - .js
        - .es6
    default-excludes: true
    excludes: []
    embed-source: false
    variable: __coverage__
    compact: true
    preserve-comments: false
    complete-copy: false
    save-baseline: false
    baseline-file: ./coverage/coverage-baseline.json
    include-all-sources: false
    include-pid: false
    preload-sources: false
reporting:
    print: summary
    reports:
        - json-summary
        - lcov
    dir: ./coverage
    watermarks:
        statements: [50, 80]
        lines: [50, 80]
        functions: [50, 80]
        branches: [50, 80]
    report-config:
        clover: {file: clover.xml}
        cobertura: {file: cobertura-coverage.xml}
        json: {file: coverage-final.json}
        json-summary: {file: coverage-summary.json}
        lcovonly: {file: lcov.info}
        teamcity: {file: null, blockName: Code Coverage Summary}
        text: {file: null, maxCols: 0}
        text-lcov: {file: lcov.info}
        text-summary: {file: null}
hooks:
    hook-run-in-context: false
    post-require-hook: null
    handle-sigint: false
check:
    global:
        statements: 0
        lines: 0
        branches: 0
        functions: 0
        excludes: []
    each:
        statements: 0
        lines: 0
        branches: 0
        functions: 0
        excludes: []

-------------------

Isparta options :
  { '0': 'cover',
  '--': [ '--recursive', '--compilers', 'es6:babel-core/register' ],
  verbose: true,
  root: './src',
  include: [ '**/*.es6', '**/*.jsx', '**/*.js' ],
  report: [ 'json-summary', 'lcov' ],
  cmd: '_mocha',
  _: [ 'cover', '_mocha' ],
  excludes: [] }
Running: node /usr/local/bin/_mocha --recursive --compilers es6:babel-core/register


  API
    GET /
::ffff:127.0.0.1 - GET /api/ HTTP/1.1 200 13 - 3.871 ms
      โœ“ should return 200 (39ms)

  app
    GET /
Warning: missing space before text for line 12 of jade file "/Users/Dom/git/energy-scanner-web/src/server/app/views/index.jade"
      โœ“ should return 200 (532ms)

  two
    โœ“ should work


  3 passing (694ms)

No coverage information was collected, exit without writing coverage information
nkbt commented

I use Tape and do not use Mocha. No overhead of testing framework, no problems ;)

le sigh

Cool ! ๐Ÿ‘

as this might be mocha specific shall I open a new issue @douglasduteil ?

@Dakuan yep please. Do you have the same problem ? Did you consult my demo here https://github.com/douglasduteil/study-node-path-es6 ?

@douglasduteil @iamstarkov

Had a look at the study project and have fixed my build :)

The trick was adding --include-all-sources. This wasn't required for isparta 3, but apparently is now.

Thanks for the pointer.

yep, its working now

"coverage": "isparta cover _mocha index.js --include-all-sources -- --require babel-core/register",

but one pretty big downside, that it includes all files even i explicitly say to cover only index.js

tell a lie, it's all gone to shit on my CI server. Clearing all my npm stuff has brought it all down:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'ci' ]
2 info using npm@2.14.7
3 info using node@v4.2.2
4 verbose run-script [ 'preci', 'ci', 'postci' ]
5 info preci energy-scanner-web@1.0.0
6 info ci energy-scanner-web@1.0.0
7 verbose unsafe-perm in lifecycle true
8 info energy-scanner-web@1.0.0 Failed to exec ci script
9 verbose stack Error: energy-scanner-web@1.0.0 ci: `npm run lint && npm test`
9 verbose stack Exit status 1
9 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:214:16)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at EventEmitter.emit (events.js:172:7)
9 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at ChildProcess.emit (events.js:172:7)
9 verbose stack     at maybeClose (internal/child_process.js:818:16)
9 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
10 verbose pkgid energy-scanner-web@1.0.0
11 verbose cwd /Users/Dom/git/energy-scanner-web
12 error Darwin 15.0.0
13 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "ci"
14 error node v4.2.2
15 error npm  v2.14.7
16 error code ELIFECYCLE
17 error energy-scanner-web@1.0.0 ci: `npm run lint && npm test`
17 error Exit status 1
18 error Failed at the energy-scanner-web@1.0.0 ci script 'npm run lint && npm test'.
18 error This is most likely a problem with the energy-scanner-web package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error     npm run lint && npm test
18 error You can get their info via:
18 error     npm owner ls energy-scanner-web
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]
> energy-scanner-web@1.0.0 test /Users/Dom/git/energy-scanner-web
> npm run clean && NODE_ENV=test babel-node ./node_modules/.bin/isparta cover -i './**/*.es6' -i './**/*.jsx' -i './**/*.js' --include-all-sources --report json-summary --report lcov _mocha -- --recursive --compilers es6:babel-core/register


> energy-scanner-web@1.0.0 clean /Users/Dom/git/energy-scanner-web
> rm -rf coverage

npm ERR! Test failed.  See above for more details.

npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "ci"
npm ERR! node v4.2.2
npm ERR! npm  v2.14.7
npm ERR! code ELIFECYCLE
npm ERR! energy-scanner-web@1.0.0 ci: `npm run lint && npm test`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the energy-scanner-web@1.0.0 ci script 'npm run lint && npm test'.
npm ERR! This is most likely a problem with the energy-scanner-web package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run lint && npm test
npm ERR! You can get their info via:
npm ERR!     npm owner ls energy-scanner-web
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/Dom/git/energy-scanner-web/npm-debug.log
nkbt commented

I'm not quite sure what sort of issues you have, logs are not very helpful.

My projects do not have issues with isparta4/babel6

https://circleci.com/gh/nkbt/react-component-template/148

See this block:

./node_modules/.bin/babel-node ./node_modules/.bin/isparta cover --report text --report lcov --verbose --dir ${CIRCLE_ARTIFACTS}/coverage --include '**/!(*-test).js' 

And coverage looks ok as usual.

https://coveralls.io/builds/4189818

@douglasduteil can you help us with mocha framework?

@iamstarkov, here's what I'm doing with mocha:

./node_modules/.bin/babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha

Here's the latest build with coverage output: https://travis-ci.org/nathancahill/eminent

My .istanbul.yml:

instrumentation:
  root: src

@nkbt I'm using tape 4.6.2 and "isparta": "^4.0.0" and I'm still getting
No coverage information was collected, exit without writing coverage information
Can you show me how you get it to work?