Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping user input using NPM test

Tags:

When running the command "NPM run test" NPM runs all of my unit tests but it shows a "watch usage" dialog requiring user input.

I want to be able to run "NPM run test" as a part of my build process so I want to have a way to skip this "watch usage" dialog. I have already tried using --forceExit which doesn't change anything.

Are there any command line parameters I can use to launch "NPM run test" without this dialog? Or alternatively, can I add something to the scripts section of my package.json that will cause this dialog not to be shown?

The scripts section of my package.json:

"scripts": {
    "start": "node node_modules/react-scripts/bin/react-scripts.js start",
    "build": "node node_modules/react-scripts/bin/react-scripts.js build",
    "test": "node node_modules/react-scripts/bin/react-scripts.js test --env=jsdom",
    "test-coverage": "npm test -- --coverage",
    "test-json": "npm test -- --coverage --json",
    "eject": "node node_modules/react-scripts/bin/react-scripts.js eject",
    "flow": "node node_modules/flow-bin/vendor/flow",
    "flow-coverage": "node node_modules/flow-coverage-report/bin/flow-coverage-report.js",
    "flow-coverage-report": "if process.platform === 'win32'; then start ./flow-coverage/index.html; else open ./flow-coverage/index.html; fi",
    "flow-json": "node node_modules/flow-bin/vendor/flow --json",
    "flow-stop": "node node_modules/flow-bin/vendor/flow stop"
   }

The aforementioned dialog:

Watch usage
 > Press u to update failing snapshots.
 > Press p to filter by a filename regex pattern.
 > Press t to filter by a test name regex pattern.
 > Press q to quit watch mode.
 > Press Enter to trigger a test run.
like image 968
bootv2 Avatar asked Jun 21 '17 11:06

bootv2


2 Answers

"test": "CI=true react-scripts test --watch=all",

this worked for me

like image 53
Sandeep P Avatar answered Sep 25 '22 05:09

Sandeep P


Aswear form Sandeep P works for me on Linux (Docker) and fails on Windows machine.

Looks like issue is that cmd was used on Windows.

Using this commands on Windows let me achieve desired result:

set CI=true
npm test --watch=all

Also this modification of package.json did the job:

  "scripts": {
    "test": "react-scripts test",
    "test-once": "CI=true react-scripts test --watch=all",
    "test-once-win": "set CI=true && react-scripts test --watch=all",
  },
like image 20
Marek R Avatar answered Sep 21 '22 05:09

Marek R