英文:
Send parameter to package.json script
问题
I have this script on package.json file:
"test:debug": "yarn build && playwright test --project=chromium-debug -c build && ts-node ./src/logs/generateLog.ts"
When I run this command: yarn test:debug -g 'myTestName'
I see in the terminal that it runs this command:
yarn build && playwright test --project=chromium-debug -c build && ts-node ./src/logs/generateLog.ts -g 'myTestName'
but I want it to run this command:
yarn build && playwright test --project=chromium-debug -c build -g 'myTestName' && ts-node ./src/logs/generateLog.ts
What should I change in my script in order to achieve that?
英文:
I have this script on package.json file:
"test:debug": "yarn build && playwright test --project=chromium-debug -c build && ts-node ./src/logs/generateLog.ts"
When I run this command: yarn test:debug -g 'myTestName'
I see in the terminal that it runs this command:
yarn build && playwright test --project=chromium-debug -c build && ts-node ./src/logs/generateLog.ts -g 'myTestName'
but I want it to run this command:
yarn build && playwright test --project=chromium-debug -c build -g 'myTestName' && ts-node ./src/logs/generateLog.ts
What should I change in my script in order to achieve that?
答案1
得分: 0
"test:debug" 在 package.json
中可以这样定义:
"test:debug": "yarn build && playwright test --project=chromium-debug -c build -g 'myTestName' && ts-node ./src/logs/generateLog.ts"
然后只需运行 yarn test:debug
。
编辑
一个解决方法是使用 Makefile 来实现你期望的结果,但首先确保你的设备上安装了 make
。
在项目的根目录中,创建一个新的 Makefile,然后将以下简单命令添加到其中(不要忘记保存 Makefile):
test:
yarn build && playwright test --project=chromium-debug -c build -g '$(g)' && ts-node ./src/logs/generateLog.ts
(注意第二行的缩进,在你的IDE中,你应该将第二行的缩进替换为使用 <kbd>TAB</kbd>
而不是4个空格,否则 make
会报错)
现在在终端中调用该命令的方式如下:
make test g="myTestName"
这样你可以在调用命令时调整 "g" 变量,并实现所期望的结果。
英文:
You can define the command in package.json
like that:
"test:debug": "yarn build && playwright test --project=chromium-debug -c build -g 'myTestName' && ts-node ./src/logs/generateLog.ts"
And then simply just run yarn test:debug
EDIT
A workaround would be to use a Makefile to achieve your desired result instead, but first make sure that make
is installed on your device.
In your project root folder. Create a new Makefile and put this simple command in it (don’t forget to save the Makefile):
test:
yarn build && playwright test --project=chromium-debug -c build -g '$(g)' && ts-node ./src/logs/generateLog.ts
(Notice the indentation in the second line, in your IDE you should replace the indentation of the second line to use a <kbd>TAB</kbd> instead of 4 spaces like I did here otherwise make
will fire an error)
Now calling the command in a terminal would be like that:
make test g="myTestName"
This will let you to tweak the ”g” variable when calling the command and it will achieve the desired result.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论