Issue
I have created the following batch that is supposed to run multiple jest tests:
#!/bin/bash
echo 'The test will run 10 times per loop. The number of loops are 20.'
echo 'Total number of instances that will be run: 200 instances'
echo 'Starting in 5 seconds...'
sleep 5
for i in {1..20}; do ${1} & ${1} & ${1} & ${1} & ${1} & ${1} & ${1} & ${1} & ${1} & ${1} || (echo 'Failed after $i attempts' && break); done
The ideia is that once I pass the test as a param, it will run like this: npm run test SomeTest.test.ts & npm run test SomeTest.test.ts & npm run test SomeTest.test.ts.
With this I will be running the same test at the same time, without having to wait for it to be completed.
And I have added it to my package.json like this:
"scripts": {
"stress-test": "./scripts/bash.sh"
}
The idea is to run like this because I want to run only one test from my .test file that has multiple tests npm run test MyJestTest.test.ts -- -t 'some specific test'
. And this command works like a charm when used on the terminal without the bash. But if I try to use it with the bash, it won't work.
npm run stress-test -- "npm run test NelnetService.test.ts -- -t 'loan transactions gets loan transactions data'"
For some reason it won't accept the -t
parameters that I'm adding.
The main idea is to execute a specific test multiple times concurrently through a loop.
Can anyone help me?
Solution
npm run test SomeTest.test.ts && npm run test SomeTest.test.ts && npm run test SomeTest.test.ts . With this I will be running the same test at the same time, without having to wait for it to be completed.
You have misunderstood the meaning of "&&".
Those components will not run simultaneously.
Only after successful completion of the first segment, the shell will be instructed to execute the second segment, and only after successful completion of that second segment, the shell will be instructed to execute the third segment. The "triplet" sequence will stop at the first failed condition.
To ensure simultaneous run of all instances, regardless of return-code value, you need to run something like
npm run test SomeTest.test.ts &
npm run test SomeTest.test.ts &
npm run test SomeTest.test.ts &
wait
The wait will ensure that you only proceed with the next step after all those background processes have completed.
Answered By - Eric Marceau Answer Checked By - Marilyn (WPSolving Volunteer)