From c9d10d36a0c58b689f0569246a6405a2a35e8e06 Mon Sep 17 00:00:00 2001 From: codemenschendev Date: Sat, 26 Sep 2026 16:54:56 +0700 Subject: [PATCH] fix(api): skip the page audit tests when playwright-core is missing PageAudit::available() only checked for node and the script file. On a machine with node but without tools/node_modules (every fresh worktree) the tests ran, qa-page.cjs died on require('playwright-core') and eleven PageAuditTest cases failed with an empty report instead of skipping. available() now also requires playwright-core beside the script, which is where the API image and CI install it. The test docblock no longer claims CI skips these tests (CI installs the driver and runs them) and the skip message names the npm command that fixes it. Project: Appwerk --- .github/workflows/ci.yml | 2 +- apps/api/app/Domain/Qa/PageAudit.php | 7 ++++++- apps/api/tests/Feature/PageAuditTest.php | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fefc25..3b59ff0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: - run: cp .env.example .env && php artisan key:generate working-directory: apps/api # PageAuditTest drives a real browser through tools/qa-page.cjs. Without playwright-core - # and a headless shell the auditor answers "skipped" and eleven tests fail on it. + # the tests skip, and without a headless shell eleven of them fail. - uses: actions/setup-node@v4 with: node-version: 22 diff --git a/apps/api/app/Domain/Qa/PageAudit.php b/apps/api/app/Domain/Qa/PageAudit.php index b369680..15144ae 100644 --- a/apps/api/app/Domain/Qa/PageAudit.php +++ b/apps/api/app/Domain/Qa/PageAudit.php @@ -22,9 +22,14 @@ class PageAudit public function __construct(private readonly string $script, private readonly ?string $node = null) {} + /** + * Node, the script and the browser driver it requires. Without playwright-core beside the + * script (`npm --prefix tools ci`, as the image and CI do) the script dies on its first line. + */ public function available(): bool { - return is_file($this->script) && $this->binary() !== null; + return is_file($this->script) && $this->binary() !== null + && is_file(dirname($this->script).'/node_modules/playwright-core/package.json'); } /** diff --git a/apps/api/tests/Feature/PageAuditTest.php b/apps/api/tests/Feature/PageAuditTest.php index d49e9f2..e6d2cd5 100644 --- a/apps/api/tests/Feature/PageAuditTest.php +++ b/apps/api/tests/Feature/PageAuditTest.php @@ -8,9 +8,9 @@ /** * The auditor itself, driving a real browser over a real page. * - * Skipped where node or chromium is not installed, which is every developer machine that has not - * asked for them and no CI box we run. That is deliberate: the checks are only meaningful against - * a browser, and a mocked browser would test the mock. + * Skipped where node or playwright-core is missing: run `npm --prefix tools ci --omit=dev` once to + * get them. CI installs both and runs these for real. That is deliberate: the checks are only + * meaningful against a browser, and a mocked browser would test the mock. */ class PageAuditTest extends TestCase { @@ -18,7 +18,7 @@ private function audit(): PageAudit { $a = app(PageAudit::class); if (! $a->available()) { - $this->markTestSkipped('no node or no qa-page.cjs on this machine'); + $this->markTestSkipped('no node, qa-page.cjs or playwright-core on this machine (npm --prefix tools ci)'); } return $a;