Parallel test execution runs multiple tests or test groups concurrently, reducing the time developers wait for feedback. It can happen inside a test runner, across test layers, or across pipeline stages. section 2.6 section 10.4.2
Speed comes with a trustworthiness risk: shared, stateful setup can be overwritten by another test running at the same time. Forgotten resets and shared variables can therefore create flaky failures that are difficult to diagnose. section 2.6
A shared verifier can become unsafe
A Jest suite may create one higher-level verifier in an outer beforeEach() and add a fake rule in an inner beforeEach(). This shortens the tests, but parallel execution makes shared state risky. Create isolated state for each test and reset mutable data such as the errors array. section 2.6
Use parallel execution deliberately:
- Run independent test layers in parallel to shorten pipeline feedback. section 10.4.2
- Split a large end-to-end test collection into parallel suites. section 10.4.2
- Use dynamically created environments when parallel tests need separate execution space. section 10.4.2
- Run the delivery pipeline after each commit instead of waiting for a nightly build. section 10.4.2
Listing 2.13 Using beforeEach() on two levels
describe('PasswordVerifier', () => {
let verifier;
beforeEach(() => verifier = new PasswordVerifier1()); #1
describe('with a failing rule', () => {
let fakeRule, errors;
beforeEach(() => { #2
fakeRule = input => ({passed: false, reason: 'fake reason'});
verifier.addRule(fakeRule);
});
it('has an error message based on the rule.reason', () => {
const errors = verifier.verify('any value');
expect(errors[0]).toContain('fake reason');
});
it('has exactly one error', () => {
const errors = verifier.verify('any value');
expect(errors.length).toBe(1);
});
});
});
#1 Setting up a new verifier that will be used in each test
#2 Setting up a fake rule that will be used within this describe() method
Inspect the nested beforeEach() example showing shared verifier setup and scenario-specific fake rules. section 2.6
Inspect the figure showing pipelines and pipeline stages running in parallel to accelerate delivery feedback. section 10.4.2

