9

I've got a bash script that starts up a server and then runs some functional tests. It's got to happen in one script, so I'm running the server in the background. This all happens via 2 npm commands: start:nolog and test:functional.

All good. But there's a lot of cruft in the output that I don't care about:

✗ ./functional-tests/runInPipeline.sh

(... "good" output here)

> @co/foo@2.2.10 pretest:functional /Users/jcol53/Documents/work/foo
> curl 'http://localhost:3000/foo' -s -f -o /dev/null || (echo 'Website must be running locally for functional tests.' && exit 1)


> @co/foo@2.2.10 test:functional /Users/jcol53/Documents/work/foo
> npm run --prefix functional-tests test:dev:chromeff


> @co/foo-functional-tests@1.0.0 test:dev:chromeff /Users/jcol53/Documents/work/foo/functional-tests
> testcafe chrome:headless,firefox:headless ./tests/**.test.js  -r junit:reports/functional-test.junit.xml -r html:reports/functional-test.html --skip-js-errors

That's a lot of lines that I don't need there. Can I suppress the @co/foo-functional-tests etc lines? They aren't telling me anything worthwhile...

npm run -s kills all output from the command, which is not what I'm looking for.

This is probably not possible but that's OK, I'm curious, maybe I missed something...

RobC
  • 20,007
  • 20
  • 62
  • 73
jcollum
  • 40,207
  • 47
  • 175
  • 294
  • https://stackoverflow.com/questions/2292847/how-to-silence-output-in-a-bash-script – Nick May 31 '19 at 23:47
  • 1
    I need the output of the npm commands though, I'm just curious if I can remove all those lines prefixed with `> ` above – jcollum Jun 01 '19 at 00:38
  • Is there a pattern to the kind of lines you want to suppress? Or a pattern to the lines you actually want. – suv Jun 01 '19 at 12:44
  • 1
    You're not missing anything as far as I can tell. If the `--silent | -s` option doesn't achieve the desired result you'll just have to accept that [npm run-scripts are noisy](https://github.com/npm/npm/issues/8821). – RobC Jun 01 '19 at 12:45
  • 1
    wow, that's an old debate; guess this ship has sailed in the opposite direction of what I want :/ – jcollum Jun 02 '19 at 18:10
  • You might want to try adding one more npm script in _package.js_ that invokes both `start:nolog` and `test:functional` using `npm run` command - and include the `-s` option with both them. For instance: `"scripts": { "both": "npm run start:nolog -s && npm run test:functional -s" }, ...` - Then execute `npm run both` via your ClI. This should reduce _some_ of npm's verbosity, i.e. less `> @co/foo@2.2.10....`) and keep output of the npm commands - inc. errors. – RobC Jun 03 '19 at 07:16
  • Just as surprised with you how this hasn't been addressed properly yet. Any idea if `yarn` also does this or does it produce a cleaner output without echoing the command back to us. – Joshua Pinter Oct 17 '19 at 14:50
  • Yarn's install output is much cleaner. – jcollum Oct 17 '19 at 23:42
  • For me, `npm --silent run ` works. Also, `yarn --silent run ` works. – Nawaz May 29 '21 at 17:31

0 Answers0