-1

I have used the following command :

npx create-react-app fresh-cra && cd fresh-cra

to create a fresh copy of a Create React App (CRA).

But when I run npm test as suggested in the instructions that follow, it gives me an error :

● Test suite failed to run

Frustratingly, there is no additional information about the error.

'npm test' gives an error: Test suite failed to run.

^ click to enlarge

How can I work around this error?

After searching the internet for days, I finally found the question Jest from create-react-app not running on Windows which seems to report the exact same error, but for Windows 8.1. 1

Just as the asker of that question, I'm baffled. Not only by the error, but also by the time that has passed since then. Is it really true that after more than three years, the same error still prevails – without anyone in the Create React App team having fixed this bug? 2

Don't get me wrong. I'm a big fan of the create-react-app npm package.

But if this is a Windows-only bug, I honestly cannot help feeling a bit bullied for being on Windows.

Does anyone on Linux or macOS get this same error when running npm test
on a fresh Create React App?


Support for the experimental syntax 'jsx' isn't currently enabled

Since npm test didn't work, I felt inclined to run Jest directly, so I tried the npx jest command. 3

But this answer says that a Create React App is not configured out-of-the-box to run the jest command. So that appears to be a dead-end alley that I don't want to try.

References


1 When I first wrote this question, I was on Windows 10, version 21H2.

2 Or is it the Jest team that doesn't reach up to standards?

3 As did the asker of Jest from create-react-app not running on Windows.

Henke
  • 4,445
  • 3
  • 31
  • 44

1 Answers1

-2

How can I work around this error?

There is no need to do that anymore, as the bug appears to have been fixed. 1

When you now run npm test, expect to see :

There is no error anymore.

Compare this screenshot (January 2023) with the screenshot in the question (May 2022).

You'll notice that where it used to say :

Determining test suites to run...

  ● Test suite failed to run

it now says :

No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.

Pressing a on the keyboard starts the test, and the test passes, as shown in the above screenshot.
No error!


I could stop here, but I noticed the suggestion :
or run Jest with `--watchAll`.

It doesn't say :
or run `npx jest --watchAll`
so it's a bit unclear what command exactly is suggested.

Despite the lack of clarity, I decided to try npx jest --watchAll.

The screenshot below shows the result.

The added '--watchAll' flag makes the error go away.

^ click to enlarge

The error says :

SyntaxError:
…\src\App.test.js:
 Support for the experimental syntax 'jsx' isn't currently enabled

As suggested already in the question, running npx jest doesn't seem to be a great idea. 2

Reference


1 When I first wrote this answer, my solution was – in package.json – to add the watchAll flag by replacing "react-scripts test" with "react-scripts test --watchAll".
Since the error is now gone, there is no longer any reason to do that.

2 An interesting anecdote.
I just discovered that I still have all the files from May 2022 on my hard drive – including the whole 219 MiB node_modules subdirectory. I couldn't resist the temptation to see if I could reproduce the error ● Test suite failed to run that I saw in May 2022 – of course, without first running npm install. Once again, I was baffled – no error!
The only difference I know for certain between May 2022 and January 2023, is that I have now upgraded Node.js from version 16.13.2 to version 18.12.1.
Well, I've also updated Windows 10 from version 21H2 to 22H2, but that change seems even less likely to explain the difference than the version upgrade of Node.js.
Is this bug/error now gone for good.? Or will it again turn up its ugly face?

Henke
  • 4,445
  • 3
  • 31
  • 44