目标:是否有一种方法或黑客可以让我在不调用单独的脚本的情况下将环境变量的r值添加为NPM脚本的CLI参数。
示例
"test:run": cypress run --spec 'tests/*' --env host=
npm run test:run localhost
cypress run --spec 'tests/*' --env host=localhost
我目前使用的是:
"test:run": cypress run --spec 'tests/*' --env
npm run test:run host=localhost
cypress run --spec 'tests/*' --env host=localhost
这是可行的,但是我想知道是否有一种方法可以省略在我的命令中添加host=,这样我就可以编写r值,localhost来表示简洁。
发布于 2022-04-06 17:29:50
我不认为你想要达到的目标目前是你想要实现它的可能性,因为npm是如何释放命令行参数的。传入的任何内容都作为单独的“选项”附加,而不只是添加到现有的字符串中,这是您当前正在看到的行为(npm run test:run localhost => cypress run --spec 'tests/*' --env host= localhost)。
有一些替代方案,这似乎是您不想做的,但是您可以为该行为创建一个单独的脚本。
"test:run": "cypress run --spec 'tests/*' --env"
"test:run:local": "npm run test:run host=localhost"或者,可以在test命令之前声明Cypress环境变量。
CYPRESS_HOST=localhost npm run test:runhttps://stackoverflow.com/questions/71769122
复制相似问题