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

Doesn't work with babel-register #121

Closed
dangreen opened this issue Jan 15, 2016 · 7 comments
Closed

Doesn't work with babel-register #121

dangreen opened this issue Jan 15, 2016 · 7 comments

Comments

@dangreen
Copy link

require("babel-register")();

require("./test.js");

test.js:

require("source-map-support").install();
throw new Error('test');

error:

throw new Error('test');
^

Error: test
    at Object.<anonymous> (/Users/dangreen/github/jam-editor/jam-server/test.js:4:7)
    at Module._compile (module.js:425:26)
    at loader (/Users/dangreen/github/jam-editor/jam-server/node_modules/babel-register/lib/node.js:131:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/dangreen/github/jam-editor/jam-server/node_modules/babel-register/lib/node.js:141:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/dangreen/github/jam-editor/jam-server/smtest.reg.js:3:1)
    at Module._compile (module.js:425:26)

Compiled code:

"use strict";

require("source-map-support").install();
throw new Error('test');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtdGVzdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDLE9BQU8sRUFBRSxDQUFDO0FBQ3hDLE1BQU0sSUFBSSxLQUFLLENBQUMsTUFBTSxDQUFDLENBQUMiLCJmaWxlIjoic210ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsicmVxdWlyZShcInNvdXJjZS1tYXAtc3VwcG9ydFwiKS5pbnN0YWxsKCk7XG50aHJvdyBuZXcgRXJyb3IoJ3Rlc3QnKTsiXX0=
@wmertens
Copy link

You need to register the source map support before babel register…

@dangreen
Copy link
Author

@wmertens mmmm how ? example ?

@dangreen
Copy link
Author

require("source-map-support").install();
require("babel-register")();

require("./test.js");

and all works. I think developers should write some about it in documentation.

@tamlyn
Copy link

tamlyn commented Jan 21, 2016

Oh wow, I spent all of yesterday trying to work this out! Any chance of adding it to the readme?

@dangreen
Copy link
Author

@tamlyn I'm sorry I made a mistake. See working with babel here.

@graingert
Copy link
Contributor

@tamlyn how is it done without sails?

@graingert
Copy link
Contributor

fyi, babel-register includes support for source-map-support directly. https://github.com/babel/babel/blob/dc1f40540de11045bb4714350350e012fee4f93e/packages/babel-register/src/node.js#L11-L24

wKovacs64 added a commit to wKovacs64/hibp that referenced this issue Aug 12, 2016
Referenced to get nyc/istanbul reporting properly with tests transpiled inline:
https://github.com/react-bootstrap/react-prop-types (as of v0.4.0)

Note on source maps:
Source map support comes with `mocha --compilers js:babel-register`, which
seems to enable source maps to work in tests but not in the compiled output.
Adding `import 'source-map-support/register'` to the src enables source maps
to work in compiled code but break in tests. Including source-map-support in
src and requiring source-map-support before babel-register when running mocha
(instead of passing the compilers option) appears to get both.

Referenced to get source maps working in test and compiled output:
evanw/node-source-map-support#121

Notes on coverage:
nyc's "--all" option to include reports for files that are not required is
currently not working with babel-plugin-istanbul, but they're aware of the
matter. Also, including reporter settings in the nyc stanza of package.json
appear to trample command line options, so those were moved to the npm test
script instead.

Related issues:
istanbuljs/nyc#333
istanbuljs/babel-plugin-istanbul#4
wKovacs64 added a commit to wKovacs64/pwned that referenced this issue Aug 12, 2016
Referenced to get nyc/istanbul reporting properly with tests transpiled inline:
https://github.com/react-bootstrap/react-prop-types (as of v0.4.0)

Note on source maps:
Source map support comes with `mocha --compilers js:babel-register`, which
seems to enable source maps to work in tests but not in the compiled output.
Adding `import 'source-map-support/register'` to the src enables source maps
to work in compiled code but break in tests. Including source-map-support in
src and requiring source-map-support before babel-register when running mocha
(instead of passing the compilers option) appears to get both.

Referenced to get source maps working in test and compiled output:
evanw/node-source-map-support#121

Notes on coverage:
nyc's "--all" option to include reports for files that are not required is
currently not working with babel-plugin-istanbul, but they're aware of the
matter. Also, including reporter settings in the nyc stanza of package.json
appear to trample command line options, so those were moved to the npm test
script instead.

Related issues:
istanbuljs/nyc#333
istanbuljs/babel-plugin-istanbul#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants