Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude node_modules from create-react-app testing?

I want to make tests of my create-react-app using jest.

One of node_modules have test-error,

enter image description here

but I don't want jest to work with node_modules folder.

In the documentation I found configuration property "collectCoverageFrom" and tried to use itin my package.json:

  ....
  "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom ",
        "eject": "react-scripts eject"
  },
  "jest": {
        "collectCoverageFrom": [
            "!/node_modules/*"
         ]
  }

But there is nothing changed.

like image 272
Alexander Knyazev Avatar asked Nov 26 '22 01:11

Alexander Knyazev


1 Answers

There is nothing with coverage.

One of your components is using react-mic package provides access to audio through window.AudioContext.

You have different ways to solve it.

  1. You may mock window.AudioContext. It would be really hard to achieve. I don't really suggest you doing that.

  2. You can mock react-mic module. That's much more achievable than #1 but still quite hard.

  3. You can rely on shallow() in your tests. So your will never need to mock anything related to Audio at all. I'd like to suggest you doing that way.

like image 65
skyboyer Avatar answered Dec 04 '22 12:12

skyboyer