Skip to content

Strange SyntaxError when running tests, probably transpiler bug #3055

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

Closed
MOZGIII opened this issue Sep 3, 2017 · 7 comments
Closed

Strange SyntaxError when running tests, probably transpiler bug #3055

MOZGIII opened this issue Sep 3, 2017 · 7 comments
Milestone

Comments

@MOZGIII
Copy link

MOZGIII commented Sep 3, 2017

Is this a bug report?

Yes.

Can you also reproduce the problem with npm 4.x?

I'm using yarn. Tried npm 4 though. Same.

Which terms did you search for in User Guide?

Did a quick look-through. I searched google for SyntaxError: Unexpected identifier, did not found the solution.

Environment

  1. node -v: v8.4.0
  2. npm -v: 4.6.1 (was 5.x before)
  3. yarn --version: 0.27.5
  4. npm ls react-scripts: [email protected] (also checked at [email protected] with yarn)

Switching yarn/npm seems to have no effect.

Then, specify:

  1. Operating system: Ubuntu xenial
  2. Browser and version (if relevant): -

Steps to Reproduce

The issue is really strange.

  1. Create a new project, cd into it.

  2. yarn add flow-bin ([email protected]), then yarn flow init.

  3. Create two files:

src/dummy.js

// @flow
export const dummmmmmmmmmmmmmmmmmy = async (
  response: Response
): Promise<Response> => {
  if (!response.ok) {
    const text = await response.text();
    throw Error(text);
  }
  return response;
};

src/dummy.test.js

// @flow
import { dummmmmmmmmmmmmmmmmmy } from "./dummy";

it("should run", async () => {
  await dummmmmmmmmmmmmmmmmmy(fetch("https://google.com"));
  expect(true);
});
  1. yarn test

Expected Behavior

Tests run successfully or at least fail with some sane error.

Actual Behavior

 PASS  src/App.test.js
 FAIL  src/dummy.test.js
  ● Test suite failed to run

    .../issue/src/dummy.js:6
        const text = await response.text();
                           ^^^^^^^^
    
    SyntaxError: Unexpected identifier
      
      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (src/dummy.test.js:2:14)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.517s, estimated 1s
Ran all test suites related to changed files.

Watch Usage
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.
Done in 7.55s.

image

Seems to be related to the way code is formatted. 😮

Reproducible Demo

https://github.com/MOZGIII/js-bug-demo-1

Just cone it and yarn install.
Run CI=true yarn test. Pretend you're CI to run all tests.

@MOZGIII
Copy link
Author

MOZGIII commented Sep 19, 2017

Ping

@MOZGIII
Copy link
Author

MOZGIII commented Nov 30, 2017

Still have this error.

@gaearon
Copy link
Contributor

gaearon commented Jan 8, 2018

Sorry, we were busy with releasing React 16 and this project did not receive much attention at the time.

@gaearon
Copy link
Contributor

gaearon commented Jan 8, 2018

I can reproduce this. But I don't know if it's a bug with Babel or something else.

The minimal example is:

const x = async (
  x: A
) => {
  const text = await x;
};

Interestingly, removing newlines around the argument list fixes it.

@gaearon gaearon added this to the 1.0.x milestone Jan 8, 2018
@gaearon
Copy link
Contributor

gaearon commented Jan 8, 2018

I think the next step here is to create a minimal reproducing example with Babel and without CRA.

@gaearon gaearon modified the milestones: 1.0.x, 1.0.18 Jan 14, 2018
@gaearon gaearon modified the milestones: 1.0.18, 2.0.0 Jan 14, 2018
@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

This appears fixed in Babel 7 and doesn't happen in our next branch. We'll publish first 2.0 alphas soon.

@gaearon gaearon closed this as completed Jan 14, 2018
@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

I'm adding a regression test in #3791 so this doesn't break again.

gaearon added a commit to gaearon/create-react-app that referenced this issue Jan 14, 2018
gaearon added a commit that referenced this issue Jan 14, 2018
gaearon added a commit that referenced this issue Jan 14, 2018
Timer pushed a commit to Timer/create-react-app that referenced this issue Jan 15, 2018
akstuhl pushed a commit to akstuhl/create-react-app that referenced this issue Mar 15, 2018
zmitry pushed a commit to zmitry/create-react-app that referenced this issue Sep 30, 2018
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants