@@ -866,6 +866,55 @@ test('should run nothing with --last-failed when previous run had no failures',
866866 expect ( result2 . didNotRun ) . toBe ( 0 ) ;
867867} ) ;
868868
869+ test ( 'should run last failed tests that did not run because a beforeAll hook failed' , async ( { runInlineTest } ) => {
870+ const workspace = {
871+ 'a.spec.js' : `
872+ import fs from 'fs';
873+ import { test, expect } from '@playwright/test';
874+ test.beforeAll(() => {
875+ if (!fs.existsSync('marker.txt')) {
876+ fs.writeFileSync('marker.txt', '');
877+ throw new Error('from beforeAll');
878+ }
879+ });
880+ test('one', () => {});
881+ test('two', () => {});
882+ `
883+ } ;
884+ const result1 = await runInlineTest ( workspace ) ;
885+ expect ( result1 . exitCode ) . toBe ( 1 ) ;
886+ expect ( result1 . failed ) . toBe ( 1 ) ;
887+ expect ( result1 . didNotRun ) . toBe ( 1 ) ;
888+
889+ const result2 = await runInlineTest ( workspace , { } , { } , { additionalArgs : [ '--last-failed' ] } ) ;
890+ expect ( result2 . exitCode ) . toBe ( 0 ) ;
891+ expect ( result2 . passed ) . toBe ( 2 ) ;
892+ expect ( result2 . didNotRun ) . toBe ( 0 ) ;
893+ } ) ;
894+
895+ test ( 'should not run intentionally skipped tests with --last-failed' , async ( { runInlineTest } ) => {
896+ const workspace = {
897+ 'a.spec.js' : `
898+ import { test, expect } from '@playwright/test';
899+ test('fail', () => {
900+ expect(1).toBe(2);
901+ });
902+ test('skipped', () => {
903+ test.skip();
904+ });
905+ `
906+ } ;
907+ const result1 = await runInlineTest ( workspace ) ;
908+ expect ( result1 . exitCode ) . toBe ( 1 ) ;
909+ expect ( result1 . failed ) . toBe ( 1 ) ;
910+ expect ( result1 . skipped ) . toBe ( 1 ) ;
911+
912+ const result2 = await runInlineTest ( workspace , { } , { } , { additionalArgs : [ '--last-failed' ] } ) ;
913+ expect ( result2 . exitCode ) . toBe ( 1 ) ;
914+ expect ( result2 . failed ) . toBe ( 1 ) ;
915+ expect ( result2 . skipped ) . toBe ( 0 ) ;
916+ } ) ;
917+
869918test ( 'should run last failed tests in a shard' , async ( { runInlineTest } ) => {
870919 const workspace = {
871920 'a.spec.js' : `
0 commit comments