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

Improve syntax error reporting; revert babel-runtime change. #787

Closed
wants to merge 1 commit into from

Conversation

cpojer
Copy link
Member

@cpojer cpojer commented Mar 11, 2016

This diff makes a number of changes:

  • It adds a useful message when a syntax error happens due to a configuration issue. This is something that a lot of people, including me, run into. There are a couple of scenarios that the new message should address:
    • babel-jest is installed but .babelrc is not properly set up. The code may use imports but it doesn't transform them into requires
    • no preprocessor is set up at all but people expect code to just work
    • the preprocessor was updated but the cache key doesn't consider everything and people don't know to use --no-cache.
    • it also prints the code that it tried to run. This is especially valuable for debugging – something I've run into dozens of times myself and I always had to hack Jest to print the source.
    • Screenshots: screenshot1 and screenshot2
    • Funny enough, the stack trace filter used to filter every line that contains node_modules. Since the message is part of the stack trace, it would filter out Preprocessor: node_modules/babel-jest. That took a while to figure out… I changed the stacktrace filter to look for \s+at in the beginning of the message.
    • Note: this error is not triggered when Babel finds a legit syntax error in the source code. When that happens, babel throws an error that is not based on SyntaxError, so it bypasses this check. This is actually nice – it means we can show this message only while people have trouble setting up their preprocessor.
  • We were swallowing runtime errors in --verbose mode, probably because @gaearon and I were working on the same code on the same time and after the merge of Haste2 #599 this got lost again. Unfortunately the reporter code is a bit unwieldy and hard to test – there is an internal task that tracks the rewrite of that component.
  • This diff also removes babel-runtime again. It was added in Update babel-jest for better code coverage #785 but I had a chat with some of the babel core developers and it seems like the best course of action is to keep babel-polyfill. babel-runtime can be added by people who use babel-jest through .babelrc. Because Jest sets the NODE_ENV variable to test, it can be enabled just for the test environment as well. The auxiliaryCommentBefore option should be enough to fix code coverage reporting.

@cpojer
Copy link
Member Author

cpojer commented Mar 11, 2016

@facebook-github-bot import

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in ebac6d4 Mar 11, 2016
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants