简体   繁体   English

在npm命令中将标志传递给脚本

[英]Passing flags to script in npm command

I am using create-react-app for my building my application and I am using cypress for automation. 我正在使用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"
}

In order to run the test, firstly I need to boot up my application using npm start and then I can run command npm run cy:run -- --record --key <record-key> . 为了运行测试,首先我需要使用npm start启动我的应用程序然后我可以运行命令npm run cy:run -- --record --key <record-key>

Instead what I am doing is run the command npm run cypress:all which will call npm start and once server is up and running it runs tests on it. 相反,我正在做的是运行命令npm run cypress:all将调用npm start并且一旦服务器启动并运行它就会运行测试。 But how do I pass the record flag for this command? 但是如何传递此命令的记录标志? npm run cypress:all -- --record <record-key> doesn't work here. npm run cypress:all -- --record <record-key>在这里不起作用。

The start-server-and-test docs says start-server-and-test文档

In addition to using NPM script names, you can pass entire commands (surround them with quotes so it is still a single string) that will be executed "as is". 除了使用NPM脚本名称之外,您还可以传递整个命令(用引号括起来,使它仍然是单个字符串),这些命令将“按原样”执行。 For example, to start globally installed http-server before running and recording Cypress.io tests you can use start-server-and-test 'http-server -c-1 --silent' 8000 './node_modules/.bin/cypress run --record' 例如,要在运行和记录Cypress.io测试之前启动全局安装的http-server,您可以使用start-server-and-test 'http-server -c-1 --silent' 8000 './node_modules/.bin/cypress run --record'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM