【问题标题】:Passing flags to script in npm command在 npm 命令中将标志传递给脚本
【发布时间】:2019-04-23 12:23:29
【问题描述】:

我正在使用 create-react-app 来构建我的应用程序,并且我正在使用 cypress 来实现自动化。

    "scripts": {
    "build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",
    "watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
    "start-js": "react-scripts start",
    "start": "npm-run-all -p watch-css start-js",
    "cy:run": "cypress run ,
    "cypress:all": "start-server-and-test start http-get://localhost:3000 cy:run"
}

为了运行测试,首先我需要使用npm start 启动我的应用程序,然后我可以运行命令npm run cy:run -- --record --key <record-key>

我正在做的是运行命令npm run cypress:all,它将调用npm start,一旦服务器启动并运行,它就会在其上运行测试。 但是我如何传递这个命令的记录标志呢? npm run cypress:all -- --record <record-key> 在这里不起作用。

【问题讨论】:

    标签: node.js npm cypress npm-scripts create-react-native-app


    【解决方案1】:

    start-server-and-test docs

    除了使用 NPM 脚本名称之外,您还可以传递将“按原样”执行的整个命令(用引号将它们括起来,因此它仍然是单个字符串)。例如,要在运行和记录 Cypress.io 测试之前启动全局安装的 http-server,您可以使用 start-server-and-test 'http-server -c-1 --silent' 8000 './node_modules/.bin/cypress run --record'

    【讨论】:

    • './node_modules/.bin/cypress 运行。我觉得不整齐。这就是为什么我想要一个 npm 脚本
    猜你喜欢
    • 1970-01-01
    • 2018-10-15
    • 2018-01-11
    • 2020-05-09
    • 2017-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多