現(xiàn)在我們可以在終端中執(zhí)行 npm run test 執(zhí)行對應(yīng)的 script 腳本, 如下:
? xxx npm run test
> xx@1.0.0 test /Users/beidan/Desktop/xxx > echo "Error: no test specified" && exit 1
Error: no test specified npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! xx@1.0.0 test: `echo "Error: no test specified" && exit 1` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the xx@1.0.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log ofthis run can be found in: npm ERR! /Users/beidan/.npm/_logs/2021-02-19T06_40_42_472Z-debug.log
如果直接在終端中執(zhí)行 npm test, 也是可以得到一樣的結(jié)果
? xxx npm test
> xx@1.0.0 test /Users/beidan/Desktop/xxx > echo "Error: no test specified" && exit 1
Error: no test specified npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! xx@1.0.0 test: `echo "Error: no test specified" && exit 1` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the xx@1.0.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log ofthis run can be found in: npm ERR! /Users/beidan/.npm/_logs/2021-02-19T06_40_42_472Z-debug.log
{ "scripts": { "lint": "eslint .", "test": "echo \"Error: no test specified\" && exit 1", "ci": "npm run lint && npm test"// 此時 npm run ci 即會依次執(zhí)行 npm run lint , npm run test } }
> xx@1.0.0 test /Users/beidan/Desktop/xxx > echo "Error: no test specified" && exit 1
Error: no test specified npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! xx@1.0.0 test: `echo "Error: no test specified" && exit 1` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the xx@1.0.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log ofthis run can be found in: npm ERR! /Users/beidan/.npm/_logs/2021-02-19T06_48_18_141Z-debug.log
靜默消息
如果想減少錯誤日志并非防止腳本拋出錯誤, 可以使用下面的命令來“靜默”處理, (比如在 ci 中,即使測試命令失敗,也希望整個管道繼續(xù)運行,就可以使用這個命令)
npm run <script> --silent // 或者 npm run <script> -s
如果腳本名不存在時不想報錯,可以使用 --if-present ,比如:npm run <script> --if-present