Skip to content

Commit 221e627

Browse files
update action
1 parent e52f709 commit 221e627

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

.github/workflows/playwright.yml

+9
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,12 @@ jobs:
7272
name: playwright-report
7373
path: playwright-report/
7474
retention-days: 7
75+
76+
- name: Process test result
77+
if: always()
78+
run: |
79+
if [[ "${{ steps.run-tests.outputs.tests-passed }}" == "true" ]]; then
80+
echo "All tests passed!"
81+
else
82+
echo "Some tests failed"
83+
fi

tests/run-tests.ts

+31-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type ChildProcess, execSync, spawn } from 'node:child_process';
2+
import fs from 'node:fs';
23
import { config } from 'dotenv';
34
import waitOn from 'wait-on';
45

@@ -70,6 +71,7 @@ async function deleteBranch(branchId: string) {
7071
async 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

Comments
 (0)