mis*_*mas 4 javascript node.js webdriver-io package.json npm-scripts
我在 package.json 文件中有这个:
{
"name": "test demo",
"version": "1.0.0",
"description": "test demo scripts",
"scripts": {
"test:v1": "wdio src/resources/config/wdio.chrome.conf.js --spec test/Tests.spec.ts",
"test:v2": "wdio src/resources/config/wdio.firefox.conf.js --spec test/Tests.spec.ts",
"test": "npm run test:v1 && npm run test:v2"
},
...
}
Run Code Online (Sandbox Code Playgroud)
当运行此命令时:
npm run test
Run Code Online (Sandbox Code Playgroud)
如果test:v1失败,则test:v2根本不执行脚本。
有没有一种方法可以配置它,以便所有脚本都运行,无论其中一些脚本是否失败?
编辑:当我在 package.json 中尝试此操作时:
"test": "npm run test:v1 ; npm run test:v2"
Run Code Online (Sandbox Code Playgroud)
然后我仍然没有执行这两个脚本,只是test:v1执行时出错。
这是我在控制台中得到的:
C:\2020\demo>npm run test
> demo@1.0.0 test C:\2020\demo
> npm run test:v1 ; npm run test:v2
> demo@1.0.0 test:v1 C:\2020\demo
> wdio src/resources/config/wdio.chrome.conf.js --spec test/Tests.spec.ts ";"
"npm" "run" "test:v2"
Execution of 1 spec files started at 2020-06-12T15:16:42.936Z
[0-0] RUNNING in chrome - C:\2020\demo\Tests.spec.ts
... other log with failing tests ...
Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:27
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! demo@1.0.0 test:v1: `wdio src/resources/config/wdio.chrome.conf.js --spec test/Tests.spec.ts ";" "npm" "run" "test:v2"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the demo@1.0.0 test:v1 script.
npm ERR! This is probably not a problem with npm. There is likely additional
logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<User>\AppData\Roaming\npm-cache\_logs\2020-06-
12T15_17_10_512Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! demo@1.0.0 test: `npm run test:v1 ; npm run test:v2`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the demo@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional
logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<User>\AppData\Roaming\npm-cache\_logs\2020-06-
12T15_17_10_548Z-debug.log
Run Code Online (Sandbox Code Playgroud)
如果我在 package.json 中尝试这样:
"test": "npm run test:v1; npm run test:v2"
Run Code Online (Sandbox Code Playgroud)
然后我在控制台中得到这个:
npm ERR! missing script: test:v1;
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! test:v1
npm ERR! test:v2
Run Code Online (Sandbox Code Playgroud)
谢谢!
解决方案因您使用的操作系统而异,因为 NPM 使用不同的 shell 来运行 npm 脚本。
sh.cmd.exe。使用npm config命令,您需要检查设置的值script-shell。为此,您可以运行以下命令:
npm config get script-shell
Run Code Online (Sandbox Code Playgroud)
它通常会返回/打印路径名cmd.exe或sh- 取决于您使用的操作系统。
如果您运行的是 Windows 并且默认 shell 是cmd.exe
然后将package.jsontest中的脚本更改为以下内容:
"test": "npm run test:v1 & npm run test:v2"
Run Code Online (Sandbox Code Playgroud)
请注意,双与号 ( &&) 已替换为单与号 ( &)。
或者...
如果您正在运行*nix并且默认 shell 是sh
然后将package.jsontest中的脚本更改为以下内容:
"test": "npm run test:v1; npm run test:v2"
Run Code Online (Sandbox Code Playgroud)
请注意,双与号 ( &&) 已替换为单个分号 ( ;)。
| 归档时间: |
|
| 查看次数: |
3398 次 |
| 最近记录: |