Skip to content

Make the puppeteer test suite run headless with no local server - #3

Merged
blogcastAI merged 1 commit into
developfrom
fix/headless-puppeteer-tests
Aug 3, 2026
Merged

Make the puppeteer test suite run headless with no local server#3
blogcastAI merged 1 commit into
developfrom
fix/headless-puppeteer-tests

Conversation

@blogcastAI

@blogcastAI blogcastAI commented Aug 3, 2026

Copy link
Copy Markdown
Owner

What

npm test currently fails 26 of 81 tests out of the box: validate.test.cjs navigates to http://localhost:8000 (no server in the repo starts one) and jest-puppeteer.config.cjs sets headless: false, so the suite needs a manually started server AND a display.

Changes

  • jest-puppeteer.config.cjs — headless by default; HEADFUL=1 restores the visible browser for debugging; --no-sandbox flags added under CI for container runners.
  • validate.test.cjs — replaces the localhost:8000 dependency with puppeteer request interception: the page navigates to http://ableplayer.test/ and the request is fulfilled from memory with an empty document. A real http(s) origin is still required — isProtocolSafe() resolves relative URLs against window.location.origin, which is opaque on about:blank (the 4 URL tests fail there) — but no server process is needed.
  • ci.yml — new test-browser job runs the puppeteer project after npm run build (the suite loads build/test/validate.umd.js).

Verification

  • npm test: 81/81 pass locally with zero setup (was 55/81)
  • CI runs the full matrix: lint + jsdom + puppeteer + build

Note

Internal fork PR to validate before offering upstream — this one directly serves upstream contributing.md's "expanding the test suite is a high priority" by making the existing suite actually runnable.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added automated browser testing to the continuous integration process.
    • Browser tests now run headlessly by default, with optional headed mode for local troubleshooting.
    • Improved test setup to use request interception and more reliable page navigation.
  • Chores
    • Updated CI documentation to reflect the full test suite and browser testing workflow.

validate.test.cjs previously required a manually started server on
localhost:8000 and a headed browser (headless: false), so npm test
always failed 26 tests out of the box and the suite could not run in CI.

- jest-puppeteer.config.cjs: headless by default; HEADFUL=1 restores a
  visible browser for debugging; pass --no-sandbox in CI containers.
- validate.test.cjs: navigate to an intercepted http://ableplayer.test/
  origin fulfilled from memory instead of localhost:8000. A real http(s)
  origin is still required because isProtocolSafe() resolves relative
  URLs against window.location.origin (opaque on about:blank), but no
  server process is needed.
- ci.yml: new test-browser job runs the puppeteer project (after
  npm run build, which produces build/test/validate.umd.js).

npm test now passes 81/81 locally with zero setup. Build artifacts
intentionally omitted per contributing.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The CI workflow now builds the project and runs the Puppeteer Jest project. Puppeteer defaults to headless mode, supports HEADFUL, and uses request interception for http://ableplayer.test/.

Changes

Puppeteer CI testing

Layer / File(s) Summary
Browser launch and request handling
jest-puppeteer.config.cjs, scripts/__tests__/validate.test.cjs
Puppeteer uses headless execution by default and supports headed mode through HEADFUL. CI disables the Chromium sandbox. The test intercepts navigation to http://ableplayer.test/ and continues other requests.
CI Puppeteer test job
.github/workflows/ci.yml
The workflow documents both Jest projects and adds a job that installs dependencies, builds the project, and runs the Puppeteer Jest project.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant npm
  participant Jest
  participant Puppeteer
  participant Chromium
  GitHubActions->>npm: Install dependencies
  GitHubActions->>npm: Build project
  GitHubActions->>Jest: Run Puppeteer project
  Jest->>Puppeteer: Launch configured browser
  Puppeteer->>Chromium: Start headless browser
  Jest->>Chromium: Navigate to ableplayer.test
  Chromium-->>Jest: Receive intercepted empty HTML response
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: headless Puppeteer tests and removal of the local server dependency.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/headless-puppeteer-tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 47-51: Update the workflow steps using actions/checkout and
actions/setup-node to reference approved full commit SHAs instead of version
tags, and add persist-credentials: false to the checkout step’s with
configuration. Preserve the existing Node.js version and npm cache settings.

In `@jest-puppeteer.config.cjs`:
- Line 6: Update the headless option in the Puppeteer configuration to disable
headless mode only when process.env.HEADFUL equals "1"; treat unset, "0", and
"false" values as headless execution.

In `@scripts/__tests__/validate.test.cjs`:
- Around line 17-22: Update the request interception condition in the test setup
to match only the exact navigation URL used by page.goto, rather than every URL
prefixed with http://ableplayer.test/. Preserve the existing synthetic HTML
response for the root navigation while allowing same-origin scripts,
stylesheets, images, and fetches to proceed or use resource-specific fixtures.
- Around line 15-27: Extend the browser fixture around page.goto to capture the
navigation response and assert its status is 200, then add a test asserting
window.location.origin equals http://ableplayer.test. Keep the existing request
interception behavior unchanged and place the regression assertions in
scripts/__tests__ coverage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7d6d00ef-d0da-4b21-8b2f-6e6395d35b41

📥 Commits

Reviewing files that changed from the base of the PR and between e7be755 and 1ae8bc4.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml
  • jest-puppeteer.config.cjs
  • scripts/__tests__/validate.test.cjs

Comment thread .github/workflows/ci.yml
Comment on lines +47 to +51
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Pin the actions and disable checkout credential persistence.

Lines [47-51] use unpinned action references. actions/checkout also retains credentials in the local repository configuration. Pin both actions to approved full commit SHAs and set persist-credentials: false.

Proposed hardening
-      - uses: actions/checkout@v4
+      - uses: actions/checkout@<approved-full-commit-sha>
+        with:
+          persist-credentials: false
-      - uses: actions/setup-node@v4
+      - uses: actions/setup-node@<approved-full-commit-sha>
🧰 Tools
🪛 zizmor (1.28.0)

[warning] 47-47: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)


[error] 47-47: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)


[error] 48-48: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 47 - 51, Update the workflow steps
using actions/checkout and actions/setup-node to reference approved full commit
SHAs instead of version tags, and add persist-credentials: false to the checkout
step’s with configuration. Preserve the existing Node.js version and npm cache
settings.

Source: Linters/SAST tools

Comment thread jest-puppeteer.config.cjs
module.exports = {
launch: {
headless: false, // Set to true to run tests in headless mode
headless: process.env.HEADFUL ? false : true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Treat only HEADFUL=1 as headed mode.

Line [6] checks whether HEADFUL is present. Therefore, HEADFUL=0 and HEADFUL=false also disable headless mode. Compare the value with "1" to preserve unattended execution.

Proposed fix
-    headless: process.env.HEADFUL ? false : true,
+    headless: process.env.HEADFUL !== "1",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
headless: process.env.HEADFUL ? false : true,
headless: process.env.HEADFUL !== "1",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@jest-puppeteer.config.cjs` at line 6, Update the headless option in the
Puppeteer configuration to disable headless mode only when process.env.HEADFUL
equals "1"; treat unset, "0", and "false" values as headless execution.

Comment on lines +15 to +27
await page.setRequestInterception(true);
page.on("request", (request) => {
if (request.url().startsWith("http://ableplayer.test/")) {
request.respond({
status: 200,
contentType: "text/html",
body: "<!doctype html><html><head></head><body></body></html>",
});
} else {
request.continue();
}
});
await page.goto("http://ableplayer.test/");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for the intercepted origin.

Lines [15-27] introduce a new browser fixture but do not assert its contract. Capture the navigation response and assert status 200. Add a test that checks window.location.origin is exactly http://ableplayer.test.

As per path instructions, scripts/__tests__/** test expansion is the maintainer's stated top priority; add coverage for this new browser setup.

Proposed test coverage
-    await page.goto("http://ableplayer.test/");
+    const response = await page.goto("http://ableplayer.test/");
+    expect(response?.status()).toBe(200);

+test("uses the intercepted HTTP origin", async () => {
+  expect(await page.evaluate(() => window.location.origin)).toBe(
+    "http://ableplayer.test",
+  );
+});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/__tests__/validate.test.cjs` around lines 15 - 27, Extend the browser
fixture around page.goto to capture the navigation response and assert its
status is 200, then add a test asserting window.location.origin equals
http://ableplayer.test. Keep the existing request interception behavior
unchanged and place the regression assertions in scripts/__tests__ coverage.

Source: Path instructions

Comment on lines +17 to +22
if (request.url().startsWith("http://ableplayer.test/")) {
request.respond({
status: 200,
contentType: "text/html",
body: "<!doctype html><html><head></head><body></body></html>",
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Restrict the synthetic response to the navigation URL.

Lines [17-22] match every path below http://ableplayer.test/, not only the navigation at /. A same-origin script, stylesheet, image, or fetch then receives an HTML document with status 200. Match the exact URL used by page.goto, or provide resource-specific fixtures.

Proposed fix
-      if (request.url().startsWith("http://ableplayer.test/")) {
+      if (request.url() === "http://ableplayer.test/") {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (request.url().startsWith("http://ableplayer.test/")) {
request.respond({
status: 200,
contentType: "text/html",
body: "<!doctype html><html><head></head><body></body></html>",
});
if (request.url() === "http://ableplayer.test/") {
request.respond({
status: 200,
contentType: "text/html",
body: "<!doctype html><html><head></head><body></body></html>",
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/__tests__/validate.test.cjs` around lines 17 - 22, Update the request
interception condition in the test setup to match only the exact navigation URL
used by page.goto, rather than every URL prefixed with http://ableplayer.test/.
Preserve the existing synthetic HTML response for the root navigation while
allowing same-origin scripts, stylesheets, images, and fetches to proceed or use
resource-specific fixtures.

@blogcastAI
blogcastAI merged commit 64c9c40 into develop Aug 3, 2026
6 checks passed
blogcastAI added a commit that referenced this pull request Aug 3, 2026
…trict status checks require an up-to-date branch)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant