Nth Request Fails
Fail only the third matching request to exercise retry and partial-data behavior without making every request fail.
await injectChaos(page, { seed: 42, network: { failures: [{ urlPattern: '/api/search', statusCode: 503, probability: 1, onNth: 3 }] },});await page.goto('/search');for (const term of ['a', 'ab', 'abc']) await page.fill('[name="q"]', term);await expect(page.locator('[data-testid="retry-inline"]')).toBeVisible();expect((await getChaosLog(page)).filter((event) => event.type === 'network:failure' && event.applied)).toHaveLength(1);cy.injectChaos({ seed: 42, network: { failures: [{ urlPattern: '/api/search', statusCode: 503, probability: 1, onNth: 3 }] },});cy.visit('/search');['a', 'ab', 'abc'].forEach((term) => cy.get('[name="q"]').clear().type(term));cy.get('[data-testid="retry-inline"]').should('be.visible');cy.getChaosLog().should((log) => { expect(log.filter((event) => event.type === 'network:failure' && event.applied)).to.have.length(1);});await browser.url('/search');await injectChaos(browser, { seed: 42, network: { failures: [{ urlPattern: '/api/search', statusCode: 503, probability: 1, onNth: 3 }] },});for (const term of ['a', 'ab', 'abc']) await $('[name="q"]').setValue(term);await expect($('[data-testid="retry-inline"]')).toBeDisplayed();expect((await getChaosLog(browser)).filter((event) => event.type === 'network:failure' && event.applied)).toHaveLength(1);await injectChaos(page, { seed: 42, network: { failures: [{ urlPattern: '/api/search', statusCode: 503, probability: 1, onNth: 3 }] },});await page.goto('http://localhost:3000/search');for (const term of ['a', 'ab', 'abc']) { await page.click('[name="q"]', { clickCount: 3 }); await page.type('[name="q"]', term);}await page.waitForSelector('[data-testid="retry-inline"]');const failures = (await getChaosLog(page)).filter((event) => event.type === 'network:failure' && event.applied);if (failures.length !== 1) throw new Error('Expected one nth failure');