11import { type ChildProcess , execSync , spawn } from 'node:child_process' ;
2+ import fs from 'node:fs' ;
23import { config } from 'dotenv' ;
34import waitOn from 'wait-on' ;
45
@@ -70,6 +71,7 @@ async function deleteBranch(branchId: string) {
7071async function main ( ) : Promise < void > {
7172 let createdBranchId : string | null = null ;
7273 let serverProcess : ChildProcess | null = null ;
74+ let testFailed = false ;
7375
7476 try {
7577 console . log ( `Creating database branch...` ) ;
@@ -99,13 +101,31 @@ async function main(): Promise<void> {
99101 await waitOn ( { resources : [ 'http://localhost:3000' ] } ) ;
100102
101103 console . log ( 'Running Playwright tests...' ) ;
102- execSync ( 'pnpm playwright test --reporter=line' , {
103- stdio : 'inherit' ,
104- env : { ...process . env , POSTGRES_URL : branchConnectionUri } ,
105- } ) ;
104+ try {
105+ if ( ! fs . existsSync ( 'playwright-report' ) ) {
106+ fs . mkdirSync ( 'playwright-report' , { recursive : true } ) ;
107+ }
108+
109+ execSync ( 'pnpm playwright test --reporter=line,html,junit' , {
110+ stdio : 'inherit' ,
111+ env : { ...process . env , POSTGRES_URL : branchConnectionUri } ,
112+ } ) ;
113+
114+ console . log ( '✅ All tests passed!' ) ;
115+ } catch ( testError ) {
116+ testFailed = true ;
117+ const exitCode = ( testError as any ) . status || 1 ;
118+ console . error ( `❌ Tests failed with exit code: ${ exitCode } ` ) ;
119+
120+ if ( process . env . GITHUB_ACTIONS === 'true' ) {
121+ console . log (
122+ '::error::Playwright tests failed. See report for details.' ,
123+ ) ;
124+ }
125+ }
106126 } catch ( error ) {
107127 console . error ( 'Error during test setup or execution:' , error ) ;
108- process . exit ( 1 ) ;
128+ testFailed = true ;
109129 } finally {
110130 if ( serverProcess ) {
111131 console . log ( 'Shutting down server...' ) ;
@@ -118,12 +138,17 @@ async function main(): Promise<void> {
118138 } else {
119139 console . log ( `Cleaning up: deleting branch ${ createdBranchId } ` ) ;
120140 await deleteBranch ( createdBranchId ) ;
121-
122141 console . log ( 'Branch deleted successfully' ) ;
123142 }
124143 } catch ( cleanupError ) {
125144 console . error ( 'Error during cleanup:' , cleanupError ) ;
126145 }
146+
147+ if ( testFailed ) {
148+ process . exit ( 1 ) ;
149+ } else {
150+ process . exit ( 0 ) ;
151+ }
127152 }
128153}
129154
0 commit comments