0

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?

Alon
  • 35
  • 1
  • 5
  • Does ["Pass command line -- argument to child script in Yarn"](https://stackoverflow.com/questions/50835221/pass-command-line-argument-to-child-script-in-yarn) answer your question? I'd especially recommend rebinnaf's answer (or equivalently Etheryte's answer, but using `"$@"` instead of `"$*"`). – Gordon Davisson Jun 07 '23 at 21:49

1 Answers1

0

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 TAB 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.

bigcbull
  • 41
  • 3
  • Thanks. But I want 'myTestName' to be a parameter. I want to run it sometimes with yarn test:debug -g "test1" and at other times yarn test:debug -g "test2" and so on. Is it possible? – Alon Jun 08 '23 at 05:28
  • @Alon Yes. There is a workaround, check my edit. – bigcbull Jun 08 '23 at 10:16
  • Thanks a lot! I found something simpilier: yarn build && playwright test --project=chromium-debug -c build \"$@\" && ts-node ./src/logs/generateLog.ts – Alon Jun 11 '23 at 06:11