dredd
dredd copied to clipboard
fix(cli): output debug npm version
The spawnSync returns an object with stdout property which is to be logged instead of the whole object.
apiary-ui-ssr-service standa$ DEBUG=* npx dredd
npx: installed 217 in 29.895s
2020-04-29T11:02:00.532Z - debug: Dredd version: 13.1.0
2020-04-29T11:02:00.533Z - debug: Node.js version: v12.16.1
2020-04-29T11:02:00.533Z - debug: Node.js environment: node=12.16.1, v8=7.8.279.23-node.31, uv=1.34.0, zlib=1.2.11, brotli=1.0.7, ares=1.15.0, modules=72, nghttp2=1.40.0, napi=5, llhttp=2.0.4, http_parser=2.9.3, openssl=1.1.1d, cldr=35.1, icu=64.2, tz=2019c, unicode=12.1
2020-04-29T11:02:00.533Z - debug: System version: Darwin 18.7.0 x64
2020-04-29T11:02:00.538Z - debug: npm version: [object Object]
2020-04-29T11:02:00.538Z - debug: Configuration: {"color":true,"dry-run":null,"hookfiles":["test/dredd/hooks.js"],"language":"nodejs","require":null,"server":"http://localhost:8200","server-wait":20,"init":false,"custom":{"cwd":"/Users/standa/Dev/documentation-service/packages/apiary-ui-ssr-service","argv":[]},"names":false,"only":[],"reporter":[],"output":[],"header":[],"sorted":false,"user":null,"inline-errors":false,"details":false,"method":[],"loglevel":"debug","path":["apiaryui.apib","apiaryui.apib"],"hooks-worker-timeout":5000,"hooks-worker-connect-timeout":1500,"hooks-worker-connect-retry":500,"hooks-worker-after-connect-wait":100,"hooks-worker-term-timeout":5000,"hooks-worker-term-retry":500,"hooks-worker-handler-host":"127.0.0.1","hooks-worker-handler-port":61321,"config":"./dredd.yml","_":["apiaryui.apib"],"p":["apiaryui.apib","apiaryui.apib"]}
2020-04-29T11:02:00.541Z - debug: Backend server process specified, starting backend server and then testing
2020-04-29T11:02:00.542Z - debug: Using 'node' as a server command, ["./index.js"] as arguments
2020-04-29T11:02:00.545Z - debug: Starting backend server process with command: node ./index.js
stdout is a socket, seems we would need to wait (async) for data.
> spawn('npm', ['--version']).stdout
<ref *1> Socket {
...
}
> spawn('npm', ['--version']).stdout.toString()
'[object Object]'
> spawn('npm', ['--version']).stdout.on('data', buffer => console.log(buffer.toString()))
> 6.14.4
For spawnSync the stdout is a Buffer. When tested individually I get:
> require('child_process').spawnSync('npm', ['--version']).stdout.toString().trim()
'6.14.6'
So the code looks ok. It's just that the code using spawnSync did not yet get released.
Ah... it is the cross-spawn which we should rather let use spawnSync to fix the output.
import { spawnSync } from 'cross-spawn'
@opichals you may need to rebase this, or re-create it to fix the CI badges (we moved to GitHub Actions).