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

Issue when running tests with --watchAll=false --coverage #8689

Closed
kentcdodds opened this issue Mar 21, 2020 · 25 comments · Fixed by #8362
Closed

Issue when running tests with --watchAll=false --coverage #8689

kentcdodds opened this issue Mar 21, 2020 · 25 comments · Fixed by #8362

Comments

@kentcdodds
Copy link
Contributor

Describe the bug

When I attempt to run my tests with coverage in CI (or locally for that matter) I get an error: App(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

Did you try recovering your dependencies?

N/A (happens on a fresh bootstrap of a new app

Which terms did you search for in User Guide?

N/A, though I did search for the error in the issues and found nothing

Environment

Environment Info:

  current version of create-react-app: 3.4.1
  running from /Users/kentcdodds/.npm/_npx/59115/lib/node_modules/create-react-app

  System:
    OS: macOS 10.15.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 12.13.1 - ~/n/bin/node
    Yarn: 1.21.1 - ~/.yarn/bin/yarn
    npm: 6.14.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 80.0.3987.149
    Firefox: 71.0
    Safari: 13.0.5
  npmPackages:
    react: ^16.13.1 => 16.13.1 
    react-dom: ^16.13.1 => 16.13.1 
    react-scripts: 3.4.1 => 3.4.1 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

Reproduction steps:

npm create react-app coverage-issues
cd coverage-issues
npx react-scripts test --watchAll=false --coverage

Expected behavior

I expect the test to pass and coverage to be reported

Actual behavior

Here's the relevant output:

 FAIL  src/App.test.js
  ✕ renders learn react link (22ms)

  ● renders learn react link

    App(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

      4 | 
      5 | test('renders learn react link', () => {
    > 6 |   const { getByText } = render(<App />);
        |                         ^
      7 |   const linkElement = getByText(/learn react/i);
      8 |   expect(linkElement).toBeInTheDocument();
      9 | });

      at reconcileChildFibers (node_modules/react-dom/cjs/react-dom.development.js:14348:23)
      at reconcileChildren (node_modules/react-dom/cjs/react-dom.development.js:16762:28)
      at mountIndeterminateComponent (node_modules/react-dom/cjs/react-dom.development.js:17542:5)
      at beginWork (node_modules/react-dom/cjs/react-dom.development.js:18596:16)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:188:14)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:237:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:292:31)
      at beginWork$1 (node_modules/react-dom/cjs/react-dom.development.js:23203:7)
      at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:22157:12)
      at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:22130:22)
      at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:21756:9)
      at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:21188:7)
      at updateContainer (node_modules/react-dom/cjs/react-dom.development.js:24373:3)
      at node_modules/react-dom/cjs/react-dom.development.js:24758:7
      at unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:21903:12)
      at legacyRenderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:24757:5)
      at Object.render (node_modules/react-dom/cjs/react-dom.development.js:24840:10)
      at node_modules/@testing-library/react/dist/pure.js:86:25
      at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:21856:12)
      at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:929:14)
      at render (node_modules/@testing-library/react/dist/pure.js:82:26)
      at Object.<anonymous> (src/App.test.js:6:25)

Reproducible demo

The reproduction steps should be enough. You don't need to change anything about the generated project.

I am also experiencing this in all of my react-scripts apps. I think this only started happening in the last week or so.

@kentcdodds
Copy link
Contributor Author

One thing I noticed is that if you remove --watchAll=false or --coverage then this is not an issue. It's only a problem if you have both of those together.

@komarovalexander
Copy link

I'm getting the same error without --watchAll
"Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null."
Travis build https://travis-ci.com/github/komarovalexander/ka-table/builds/154410305

@neviaumi
Copy link

Same issue here with --coverage and CI=true combination

Message

FAIL src/hooks/__tests__/useAccessToken.test.tsx
  ● Test useAccessToken setAccessToken hooks › Should success set the token

    _default(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

      28 | describe('Test useAccessToken setAccessToken hooks', () => {
      29 |   it('Should success set the token', () => {
    > 30 |     const { getByTestId } = render(
         |                             ^
      31 |       <MemoryRouter initialEntries={['/']}>
      32 |         <AuthContextProvider>
      33 |           <DummyComponentWillSetToken />

      at reconcileChildFibers (node_modules/react-dom/cjs/react-dom.development.js:14348:23)

Github action
https://github.com/davidNHK/spotify-music-player/pull/155/checks?check_run_id=524800323

@ambroseus
Copy link

ambroseus commented Mar 22, 2020

@kentcdodds possible root cause: combination of babel 7.9 and jest 24.9 in react-scripts 3.4.1

in case forcing jest to v 25.1 test coverage works as expected

{
  "resolutions": {
    "jest": "25.1.0"
  },
  "scripts": {
    "test:coverage": "SKIP_PREFLIGHT_CHECK=true CI=true react-scripts test --coverage"
  }
}

(#8362)

@taijuten
Copy link

Babel 7.9.3 was just release too, with some issues that may well be related to this

@adamelliotfields
Copy link

adamelliotfields commented Mar 22, 2020

I think this may have fixed itself.

rm -rf node_modules
rm package-lock.json
npm install
CI=true npm test -- --coverage

Edit 1: I experienced this all day yesterday (3/21). It is not longer occurring for me (3/22) on either existing react-scripts projects (after refreshing dependencies) or new create-react-app scaffolded projects.

Edit 2: Using yarn install instead of npm install will reproduce the issue.

@wescopeland
Copy link

One thing I noticed is that if you remove --watchAll=false or --coverage then this is not an issue. It's only a problem if you have both of those together.

We are experiencing this with the --coverage flag, even if --watchAll=false is removed.

@kentcdodds
Copy link
Contributor Author

This is likely a problem with the Babel plugin jest uses for coverage reporting. One potential solution is to use v8's built-in coverage reporting via the "coverageProvider" option

@lizzykerrigan
Copy link

Same issue here too. Running tests with --coverage flag return an error, whereas running tests without the --coverage flag run successfully. This has only started happening in the last few days 🤔

@asllani94
Copy link

@ambroseus none of the above worked for me

@wescopeland
Copy link

I just did a fresh npm install, coverage seems to be working again 🤷‍♂️

@alessioalex
Copy link

Getting the same error when running jest --coverage on a sample project. Running without --coverage works fine.

I think I'm using the latest modules (npm ls --depth=0):

├── @babel/core@7.9.0
├── @babel/plugin-proposal-class-properties@7.8.3
├── @babel/preset-env@7.9.0
├── @babel/preset-react@7.9.4
├── @frontendmasters/pet@1.0.3
├── @reach/router@1.3.3
├── @testing-library/react@10.0.1
├── babel-eslint@10.1.0
├── cross-env@7.0.2
├── eslint@6.8.0
├── eslint-config-prettier@6.10.1
├── eslint-plugin-import@2.20.1
├── eslint-plugin-jsx-a11y@6.2.3
├── eslint-plugin-react@7.19.0
├── eslint-plugin-react-hooks@2.5.1
├── jest@25.2.3
├── parcel-bundler@1.12.4
├── prettier@2.0.2
├── react@16.13.1
├── react-dom@16.13.1
└── rimraf@3.0.2

@komarovalexander
Copy link

komarovalexander commented Mar 28, 2020

a week ago this error appeared, but today I've cleared the cache and the build passed

@sarahatwork
Copy link

Ran into this issue today. Downgraded to react-scripts 3.4.0 in my package.json as a workaround.

@yannbf
Copy link

yannbf commented Mar 31, 2020

Downgrading to react-scripts 3.4.0 worked well. Thanks @sarahatwork !

csmarchbanks added a commit to csmarchbanks/prometheus that referenced this issue Apr 1, 2020
facebook/create-react-app#8689 is causing our
tests to fail in the CI pipeline. As the comments suggest, downgrading
to react-scripts 3.4.0 fixes the problem.

In addition, fix a test warning due to a missing id field.

Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
juliusv pushed a commit to prometheus/prometheus that referenced this issue Apr 1, 2020
facebook/create-react-app#8689 is causing our
tests to fail in the CI pipeline. As the comments suggest, downgrading
to react-scripts 3.4.0 fixes the problem.

In addition, fix a test warning due to a missing id field.

Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
@technikhil314
Copy link

technikhil314 commented Apr 3, 2020

@babel/core@7.9.0
@testing-library/jest-dom@4.2.4
@testing-library/react@9.5.0
@testing-library/user-event@7.2.1
babel-eslint@10.1.0
babel-jest@24.9.0
babel-loader@8.1.0
babel-plugin-named-asset-import@0.3.6
babel-preset-react-app@9.1.2
jest@25.2.7
jest-css-modules@2.1.0
jest-environment-jsdom-fourteen@1.0.1
jest-resolve@24.9.0
jest-watch-typeahead@0.4.2
prettier@2.0.2
react-app-polyfill@1.0.6
react-dev-utils@10.2.1
react-dom@16.13.1
react-router-dom@5.1.2

Same here above it list of all direct dependancies. Upgrading jest does not help either. Any help would be appreciated.

One thing I noticed is that if I write and return jsx in this fashion it works.

export default function Demo() {
  var demo = (
    <h1 className={styles.demo}>
      Demo
    </h1>
  )
  return demo;
}```

but this does not work

```import styles from "./demo.module.scss";
export default function Demo() {
  return (
    <h1 className={styles.demo}>
      Demo
    </h1>
  );
}```

@alicompiler
Copy link

same issue here
running test only with --coverage flag.

downgrading to react-scripts 3.4.0 didn't work for me

@alexiusp
Copy link

alexiusp commented Apr 7, 2020

same issue here.
downgrading to react-scripts 3.4.0 worked for me, but i remember there was some other issue with that version in my pipeline, so fixing this problem would be really appreciated

@drewjs
Copy link

drewjs commented Apr 10, 2020

I was encountering this issue as well when using jest with the --coverage flag. I was able to resolve it by switching to v8 as the coverage provider along with jest-environment-jsdom-sixteen.

@tribakzero
Copy link

Same issue.

@JacekKosciesza
Copy link

I've the same problem

svdo added a commit to Zwaai-app/infections-server that referenced this issue Apr 15, 2020
@PaulACoroneos
Copy link

Can confirm going to react-scripts 3.4.0 also resolved this issue for me.

penx added a commit to penx/storybook-code-coverage that referenced this issue Apr 16, 2020
@Jhonatangiraldo
Copy link

Thanks, @ambroseus, your solution worked so I can avoid downgrading react-scripts.

As of today 22/april 2020, is it work on this? Are there any plans to fix this bug?

If there is a lack of devs, I offer myself to work on this bug. However not sure if this needs so many fixed dependencies or something similar

@pzi
Copy link

pzi commented Apr 24, 2020

Interestingly enough, the coverage report still gets produced accurately, despite all the errors in the console.

ncronquist added a commit to listerlyify/listerlyify-client that referenced this issue Apr 26, 2020
- There appears to be a bug in react-scripts that causes running the
  tests with coverage to fail when in CI mode or if --watchAll=false
- Downgrading react-scripts from 3.4.1 to 3.4.0 seems to fix the problem
  as a workaround for now
- See facebook/create-react-app#8689 for more
  information
ncronquist added a commit to listerlyify/listerlyify-client that referenced this issue Apr 26, 2020
- There appears to be a bug in react-scripts that causes running the
  tests with coverage to fail when in CI mode or if --watchAll=false
- Downgrading react-scripts from 3.4.1 to 3.4.0 seems to fix the problem
  as a workaround for now
- See facebook/create-react-app#8689 for more
  information
poteirard pushed a commit to ZopaPublic/react-components that referenced this issue May 6, 2020
@transmissions11
Copy link

I was pulling my hair out over this issue but as able to fix it. Problem was that on CI, Create-React-App was defaulting to yarn, which messed up an install somehow, which did not happen on my local machine as I do not have yarn installed.

If you are having this issue (and you don't want to downgrade to 3.4.0, try using --use-npm

@lock lock bot locked and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.