Skip to content

feat: add tests for routes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update action
  • Loading branch information
jeremyphilemon committed Apr 12, 2025
commit 221e62703f50c5ee09a4ca0d1a25298071e5f78d
9 changes: 9 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@ jobs:
name: playwright-report
path: playwright-report/
retention-days: 7

- name: Process test result
if: always()
run: |
if [[ "${{ steps.run-tests.outputs.tests-passed }}" == "true" ]]; then
echo "All tests passed!"
else
echo "Some tests failed"
fi
37 changes: 31 additions & 6 deletions tests/run-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type ChildProcess, execSync, spawn } from 'node:child_process';
import fs from 'node:fs';
import { config } from 'dotenv';
import waitOn from 'wait-on';

Expand Down Expand Up @@ -70,6 +71,7 @@ async function deleteBranch(branchId: string) {
async function main(): Promise<void> {
let createdBranchId: string | null = null;
let serverProcess: ChildProcess | null = null;
let testFailed = false;

try {
console.log(`Creating database branch...`);
Expand Down Expand Up @@ -99,13 +101,31 @@ async function main(): Promise<void> {
await waitOn({ resources: ['http://localhost:3000'] });

console.log('Running Playwright tests...');
execSync('pnpm playwright test --reporter=line', {
stdio: 'inherit',
env: { ...process.env, POSTGRES_URL: branchConnectionUri },
});
try {
if (!fs.existsSync('playwright-report')) {
fs.mkdirSync('playwright-report', { recursive: true });
}

execSync('pnpm playwright test --reporter=line,html,junit', {
stdio: 'inherit',
env: { ...process.env, POSTGRES_URL: branchConnectionUri },
});

console.log('✅ All tests passed!');
} catch (testError) {
testFailed = true;
const exitCode = (testError as any).status || 1;
console.error(`❌ Tests failed with exit code: ${exitCode}`);

if (process.env.GITHUB_ACTIONS === 'true') {
console.log(
'::error::Playwright tests failed. See report for details.',
);
}
}
} catch (error) {
console.error('Error during test setup or execution:', error);
process.exit(1);
testFailed = true;
} finally {
if (serverProcess) {
console.log('Shutting down server...');
Expand All @@ -118,12 +138,17 @@ async function main(): Promise<void> {
} else {
console.log(`Cleaning up: deleting branch ${createdBranchId}`);
await deleteBranch(createdBranchId);

console.log('Branch deleted successfully');
}
} catch (cleanupError) {
console.error('Error during cleanup:', cleanupError);
}

if (testFailed) {
process.exit(1);
} else {
process.exit(0);
}
}
}

Expand Down