How can I exclude files from Jest watch?

前端 未结 7 1609
眼角桃花
眼角桃花 2021-02-01 12:17

I\'m doing some slightly bizarre stuff using Jest for testing where I\'m writing some stuff to disk. If I use the watch flag in Jest however then I\'m finding (quit

7条回答
  •  清酒与你
    2021-02-01 13:04

    To exclude a directory from Jest testing, use testPathIgnorePatterns

    testPathIgnorePatterns

    "testPathIgnorePatterns": ["directory to ignore"]
    

    Below in file package.json, I have configured to ignore the "src" directory

    {
          "name": "learn-test",
          "jest": {
            "testPathIgnorePatterns": ["src"]
          },
          "version": "0.1.0",
          "private": true,
          "dependencies": {
            "react": "^16.4.1",
            "react-dom": "^16.4.1",
            "react-scripts": "1.1.4"
          },
          "scripts": {
            "start": "react-scripts start",
            "build": "react-scripts build",
            "test": "jest --watch",
            "eject": "react-scripts eject",
    
          },
    
          "devDependencies": {}
        }
    

提交回复
热议问题