create-react-app: Tests are failing after upgrade to 0.8.1

If you are reporting a bug, please fill in below. Otherwise feel free to remove this template entirely.

Can you reproduce the problem with latest npm?

I have Yarn installed, so CRA used latest yarn@0.18.0 to setup.

Description

My test command fails with the following error

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

    TypeError: /home/bserdiuk/coding/test/src/App.test.js: Cannot read property 'length' of null
      
      at Buffer._append (node_modules/babel-generator/lib/buffer.js:83:25)
      at Buffer.append (node_modules/babel-generator/lib/buffer.js:55:10)
      at Generator._append (node_modules/babel-generator/lib/printer.js:206:52)
      at Generator.word (node_modules/babel-generator/lib/printer.js:131:10)
      at Generator.Identifier (node_modules/babel-generator/lib/generators/types.js:38:8)
      at node_modules/babel-generator/lib/printer.js:298:23
      at Buffer.withSource (node_modules/babel-generator/lib/buffer.js:142:28)
      at Generator.withSource (node_modules/babel-generator/lib/printer.js:189:15)
      at Generator.print (node_modules/babel-generator/lib/printer.js:297:10)
      at Generator.VariableDeclarator (node_modules/babel-generator/lib/generators/statements.js:309:8)

It worked fine with version 0.7.0, today I tried to upgrade to latest 0.8.1 and got the error above. I have generated new test application with latest create-react-app and react-scripts and could find a minimal example to reproduce.

Add the following test in your test files, then run npm test.

it('async test', async () => {
    const {result} = doSometing();
});

Basically, destructuring assignment doesn’t work in async function with Jest. Babel Repl transpiles this code fine. Also it works fine if I will put this code into source. Problem appears only in testing code.

Expected behavior

I expect that it works as it was before in 0.7.0

Actual behavior

Tests are not run, error appears before any test starts.

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts (if you haven’t ejected):
npm ls react-scripts
test@0.1.0 /home/bserdiuk/coding/test
└── react-scripts@0.8.1 
  1. node -v:
v6.9.1
  1. npm -v:
4.0.3

Then, specify:

  1. Operating system: Ubuntu 16.04.1 LTS
  2. Browser and version: not applicable

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 44 (31 by maintainers)

Most upvoted comments

I can confirm

var addIndex = function addIndex({ index, ...routes } = {}, base) {
};

is not working.

    /Users/gaearon/p/create-react-app/packages/react-scripts/template/src/App.test.js:27
    var addIndex = function addIndex({ index, ...routes } = {}, base) {
                                              ^^^
    SyntaxError: Unexpected token ...
      
      at transformAndBuildScript (../node_modules/jest-runtime/build/transform.js:316:10)
      at process._tickCallback (../../../internal/process/next_tick.js:103:7)

I can confirm that commenting out regenerator fixes

it('async test', async () => {
    const {result} = await doSometing(); // Note: MUST have await to reproduce
});

for me.

Before commenting it I was seeing

  /Users/gaearon/p/create-react-app/packages/react-scripts/template/src/App.test.js: Expected type "Expression" with option {}

but not anymore.

One thing to keep in mind is there’s some Jest caching going on so you need to change something in test file every time you try after changing preset.

Oh right that specifically https://github.com/babel/babel/issues/4851! Haven’t had time to fix but can work on that

(edge cases in the object-rest-spread transforms)