diff --git a/src/test/dispatcher.ts b/src/test/dispatcher.ts index 7aafc82985..5cbaf0ed96 100644 --- a/src/test/dispatcher.ts +++ b/src/test/dispatcher.ts @@ -186,7 +186,7 @@ export class Dispatcher { // Only retry expected failures, not passes and only if the test failed. for (const testId of failedTestIds) { const pair = this._testById.get(testId)!; - if (pair.test.expectedStatus === 'passed' && pair.test.results.length < pair.test.retries + 1) { + if (!this._isStopped && pair.test.expectedStatus === 'passed' && pair.test.results.length < pair.test.retries + 1) { pair.result = pair.test._appendTestResult(); remaining.unshift({ retry: pair.result.retry, diff --git a/tests/playwright-test/max-failures.spec.ts b/tests/playwright-test/max-failures.spec.ts index 2724b919ee..69e88def6d 100644 --- a/tests/playwright-test/max-failures.spec.ts +++ b/tests/playwright-test/max-failures.spec.ts @@ -63,3 +63,19 @@ test('-x should work', async ({ runInlineTest }) => { expect(result.failed).toBe(1); expect(result.output.split('\n').filter(l => l.includes('expect(')).length).toBe(2); }); + +test('max-failures should work with retries', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.spec.js': ` + const { test } = pwt; + for (let i = 0; i < 10; ++i) { + test('fail_' + i, () => { + expect(true).toBe(false); + }); + } + `, + }, { 'max-failures': 2, 'retries': 4 }); + expect(result.exitCode).toBe(1); + expect(result.failed).toBe(1); + expect(result.output.split('\n').filter(l => l.includes('Received:')).length).toBe(2); +});