Search code examples
node.jsreactjsunit-testingcontinuous-integrationfrontend

npm test -- --coverage never exits


I am using create-react-app to create a react application. When I executes npm test -- --coverage the test never exists. npm test actually runs react-scripts test. Any Idea?

enter image description here


Solution

  • -- --coverage part won't work, and should use one of the commands below to set CI to true.

    By default npm test runs the watcher with interactive CLI. However, you can force it to run tests once and finish the process by setting an environment variable called CI.

    source: React docs

    Windows (cmd.exe)

    • set CI=true && npm test

    • set CI=true && npm run build

    Windows (Powershell)

    • ($env:CI = "true") -and (npm test)

    • ($env:CI = "true") -and (npm run build)

    Linux, macOS (Bash)

    • CI=true npm test

    • CI=true npm run build


    NOT included in the docs

    For Docker (node and react):

    docker run -e CI=true [myImage] npm run test