I have been trying to run multiple npm commands to run some of my cypress tests in a sequence. after some research what I found was to use && in between npm commands.
package.json file, inside scripts I defined a test as,
"scripts":{
"test":"npm run cypresscommand_1 && npm run cypresscommand_2"
}
When I execute this using npm run test for some reason, npm run cypresscommand_1 got executed but npm run cypresscommand_2 didn't get executed. With further research and going through some tutorials, later I tried two modifications
modification 1: insted of && I used &
"scripts":{
"test":"npm run cypresscommand_1 & npm run cypresscommand_2"
}
modification 2: insted of && I used ||
"scripts":{
"test":"npm run cypresscommand_1 || npm run cypresscommand_2"
}
surprisingly both gave me the expected results which mean both executed npm run cypresscommand_1 and then npm run cypresscommand_2
What I want to know is,
Although the code is working perfectly, I want to make sure if I'm using the correct syntax or not. Can someone help?
Thank you.
It has nothing to do with npm, these are interpreted as bash commands on Linux based systems,
& - means it will run as background job,
&& - exit code from each command and uses it as an operand in a chained && operation.
| - is a pipe operator where the output of one command is passed on to the following command,
|| - the OR logical operator, and make Bash continue processing chained commands if only one of a pair completes.
For your case you can try using semicolon ';' which runs the commands one after other even if it fails.
"scripts":{ "test":"npm run cypresscommand_1 ; npm run cypresscommand_2" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With