question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Newly created react app with typescript template crashing when running tests with coverage flag enabled

See original GitHub issue

Describe the bug

Running on a greenfield project created with create-react-app and typescript template the tests with the coverage flag doesn’t work. Running the test without coverage flag works fine.

Environment

Environment Info:

  current version of create-react-app: 3.4.1
  running from /Users/pperezdiez/.config/yarn/global/node_modules/create-react-app

  System:
    OS: macOS 10.15.5
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
  Binaries:
    Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
  Browsers:
    Chrome: 85.0.4183.83
    Firefox: 79.0
    Safari: 13.1.1
  npmPackages:
    react: ^16.13.1 => 16.13.1 
    react-dom: ^16.13.1 => 16.13.1 
    react-scripts: 3.4.3 => 3.4.3 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

  1. yarn create react-app my-first-app --template typescript
  2. Add to package.json a script to run tests with coverage: "test:coverage": "react-scripts test -- --coverage --runInBand --watchAll=false",
  3. Run the coverage: yarn test:coverage

Same can be done without yarn. I am adding yarn as it is how I created it so it is consistent with the info above.

Expected behavior

The tests are run properly when the coverage flag is enabled

Actual behavior

It crashes like if it wasn’t aware that it has to transpile typescript to run the tests.

Screenshot 2020-09-04 at 13 04 37 Screenshot 2020-09-04 at 13 04 52

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

1reaction
PabloFNKcommented, Oct 12, 2020

This is stale as there is no official answer but this is still happening.

0reactions
PabloFNKcommented, Mar 8, 2021

I have detected that with react-scripts 4 this issue is solved, so if someone is still facing this I suggest to update. At least creating a project from scratch no longer fails when running tests with coverage flag.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running Tests | Create React App
Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser. This...
Read more >
Why Code Coverage in react app is empty? Tried using npm ...
I have just created a new app using the latest create-react-app. I am trying to find the code coverage using npm run test...
Read more >
Continuous integration for React applications using Jest and ...
Getting started. This project builds on the Redux Async Example app. Using this application will show how you would add tests to a...
Read more >
Testing - React Native
In this guide, we will cover different, automated ways to ensure your app works as expected, ranging from static analysis to end-to-end tests....
Read more >
Code Coverage for End-to-end Tests - Gleb Bahmutov
How to instrument application code and collect code coverage during Cypress E2E tests. Instrumenting the code as a pre-processor step; During ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found