1
1
import { type ChildProcess , execSync , spawn } from 'node:child_process' ;
2
+ import fs from 'node:fs' ;
2
3
import { config } from 'dotenv' ;
3
4
import waitOn from 'wait-on' ;
4
5
@@ -70,6 +71,7 @@ async function deleteBranch(branchId: string) {
70
71
async function main ( ) : Promise < void > {
71
72
let createdBranchId : string | null = null ;
72
73
let serverProcess : ChildProcess | null = null ;
74
+ let testFailed = false ;
73
75
74
76
try {
75
77
console . log ( `Creating database branch...` ) ;
@@ -99,13 +101,31 @@ async function main(): Promise<void> {
99
101
await waitOn ( { resources : [ 'http://localhost:3000' ] } ) ;
100
102
101
103
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
+ }
106
126
} catch ( error ) {
107
127
console . error ( 'Error during test setup or execution:' , error ) ;
108
- process . exit ( 1 ) ;
128
+ testFailed = true ;
109
129
} finally {
110
130
if ( serverProcess ) {
111
131
console . log ( 'Shutting down server...' ) ;
@@ -118,12 +138,17 @@ async function main(): Promise<void> {
118
138
} else {
119
139
console . log ( `Cleaning up: deleting branch ${ createdBranchId } ` ) ;
120
140
await deleteBranch ( createdBranchId ) ;
121
-
122
141
console . log ( 'Branch deleted successfully' ) ;
123
142
}
124
143
} catch ( cleanupError ) {
125
144
console . error ( 'Error during cleanup:' , cleanupError ) ;
126
145
}
146
+
147
+ if ( testFailed ) {
148
+ process . exit ( 1 ) ;
149
+ } else {
150
+ process . exit ( 0 ) ;
151
+ }
127
152
}
128
153
}
129
154
0 commit comments