diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index eed5478..a9e0cdc 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -107,7 +107,10 @@ jobs: PORT: 3000 DEMO_MODE: 'true' UPLOADS_DIR: /tmp/redefined-uploads - NODE_ENV: production + # NODE_ENV is deliberately unset: `npm install` omits devDependencies when + # NODE_ENV=production, which strips tsc/vite/@playwright/test and breaks the + # build. It would also flip the session cookie to Secure, which the e2e run + # serves over plain http. steps: - name: Checkout uses: actions/checkout@v4 @@ -125,12 +128,24 @@ jobs: run: node migrate.js up working-directory: backend - - name: Build and start backend + - name: Build backend + run: npm run build + working-directory: backend + + - name: Start backend run: | mkdir -p /tmp/redefined-uploads - npm run build - node dist/server.js & - sleep 3 + node dist/server.js > /tmp/backend.log 2>&1 & + for i in $(seq 1 30); do + if node -e "require('http').get('http://localhost:3000/api/config', r => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"; then + echo "Backend ready after ${i}s" + exit 0 + fi + sleep 1 + done + echo "Backend did not become ready within 30s:" + cat /tmp/backend.log + exit 1 working-directory: backend - name: Install frontend deps @@ -149,6 +164,10 @@ jobs: run: npx playwright test --reporter=json working-directory: frontend + - name: Backend log + if: steps.e2e.outcome == 'failure' + run: cat /tmp/backend.log + - name: Summarize if: always() run: node scripts/summarize-playwright.js frontend/playwright-results.json diff --git a/scripts/summarize-jest.js b/scripts/summarize-jest.js index eac7e38..2797862 100644 --- a/scripts/summarize-jest.js +++ b/scripts/summarize-jest.js @@ -2,6 +2,15 @@ const fs = require('fs'); const [, , resultsPath, label] = process.argv; + +// This runs with `if: always()`, so it also fires when an earlier step failed and +// no results file was ever written. Report that plainly and exit 0 — the job still +// fails on the real step, and a stack trace here would only bury it. +if (!fs.existsSync(resultsPath)) { + report([`## ${label || 'Test'} Results`, '', `No results file at \`${resultsPath}\` — the test step failed before writing one.`, '']); + process.exit(0); +} + const raw = fs.readFileSync(resultsPath, 'utf-8'); const data = JSON.parse(raw); @@ -33,11 +42,15 @@ if (data.numFailedTests > 0) { lines.push(''); } -const summaryPath = process.env.GITEA_STEP_SUMMARY || process.env.GITHUB_STEP_SUMMARY; -if (summaryPath) { - fs.appendFileSync(summaryPath, lines.join('\n') + '\n'); -} else { - console.log(lines.join('\n')); -} +report(lines); -process.exit(data.numFailedTests > 0 ? 1 : 0); \ No newline at end of file +process.exit(data.numFailedTests > 0 ? 1 : 0); + +function report(out) { + const summaryPath = process.env.GITEA_STEP_SUMMARY || process.env.GITHUB_STEP_SUMMARY; + if (summaryPath) { + fs.appendFileSync(summaryPath, out.join('\n') + '\n'); + } else { + console.log(out.join('\n')); + } +} \ No newline at end of file diff --git a/scripts/summarize-playwright.js b/scripts/summarize-playwright.js index 2a191a8..c9f0bd5 100644 --- a/scripts/summarize-playwright.js +++ b/scripts/summarize-playwright.js @@ -2,6 +2,15 @@ const fs = require('fs'); const [, , resultsPath] = process.argv; + +// This runs with `if: always()`, so it also fires when an earlier step failed and +// no results file was ever written. Report that plainly and exit 0 — the job still +// fails on the real step, and a stack trace here would only bury it. +if (!fs.existsSync(resultsPath)) { + report([`## Playwright E2E Results`, '', `No results file at \`${resultsPath}\` — the test step failed before writing one.`, '']); + process.exit(0); +} + const raw = fs.readFileSync(resultsPath, 'utf-8'); const data = JSON.parse(raw); const stats = data.stats || {}; @@ -44,11 +53,15 @@ if (failures.length) { lines.push(''); } -const summaryPath = process.env.GITEA_STEP_SUMMARY || process.env.GITHUB_STEP_SUMMARY; -if (summaryPath) { - fs.appendFileSync(summaryPath, lines.join('\n') + '\n'); -} else { - console.log(lines.join('\n')); -} +report(lines); -process.exit((stats.unexpected || 0) > 0 ? 1 : 0); \ No newline at end of file +process.exit((stats.unexpected || 0) > 0 ? 1 : 0); + +function report(out) { + const summaryPath = process.env.GITEA_STEP_SUMMARY || process.env.GITHUB_STEP_SUMMARY; + if (summaryPath) { + fs.appendFileSync(summaryPath, out.join('\n') + '\n'); + } else { + console.log(out.join('\n')); + } +} \ No newline at end of file