Abort Upload Midflight
Abort an upload request after it starts and assert that the UI exits the uploading state.
await injectChaos(page, { seed: 42, network: { aborts: [{ urlPattern: '/api/uploads', timeout: 500, probability: 1 }] },});await page.goto('/upload');await page.setInputFiles('input[type="file"]', 'fixtures/photo.png');await page.click('[data-testid="upload"]');await expect(page.locator('[data-testid="upload-error"]')).toBeVisible();expect((await getChaosLog(page)).some((event) => event.type === 'network:abort' && event.applied)).toBe(true);cy.injectChaos({ seed: 42, network: { aborts: [{ urlPattern: '/api/uploads', timeout: 500, probability: 1 }] },});cy.visit('/upload');cy.get('input[type="file"]').selectFile('cypress/fixtures/photo.png');cy.get('[data-testid="upload"]').click();cy.get('[data-testid="upload-error"]').should('be.visible');cy.getChaosLog().should((log) => { expect(log.some((event) => event.type === 'network:abort' && event.applied)).to.equal(true);});await browser.url('/upload');await injectChaos(browser, { seed: 42, network: { aborts: [{ urlPattern: '/api/uploads', timeout: 500, probability: 1 }] },});await $('input[type="file"]').setValue('/absolute/path/to/photo.png');await $('[data-testid="upload"]').click();await expect($('[data-testid="upload-error"]')).toBeDisplayed();expect((await getChaosLog(browser)).some((event) => event.type === 'network:abort' && event.applied)).toBe(true);await injectChaos(page, { seed: 42, network: { aborts: [{ urlPattern: '/api/uploads', timeout: 500, probability: 1 }] },});await page.goto('http://localhost:3000/upload');const input = await page.$('input[type="file"]');await input!.uploadFile('/absolute/path/to/photo.png');await page.click('[data-testid="upload"]');await page.waitForSelector('[data-testid="upload-error"]');const log = await getChaosLog(page);if (!log.some((event) => event.type === 'network:abort' && event.applied)) { throw new Error('Expected upload abort');}