-
Notifications
You must be signed in to change notification settings - Fork 0
Make the puppeteer test suite run headless with no local server #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,10 @@ | ||||||
| // jest-puppeteer.config.js | ||||||
| // Headless by default so `npm test` runs unattended (locally and in CI). | ||||||
| // Set HEADFUL=1 to watch the browser while debugging. | ||||||
| module.exports = { | ||||||
| launch: { | ||||||
| headless: false, // Set to true to run tests in headless mode | ||||||
| headless: process.env.HEADFUL ? false : true, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Treat only Line [6] checks whether Proposed fix- headless: process.env.HEADFUL ? false : true,
+ headless: process.env.HEADFUL !== "1",📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| // Chromium's sandbox is unavailable in most CI containers. | ||||||
| args: process.env.CI ? ["--no-sandbox", "--disable-setuid-sandbox"] : [], | ||||||
| }, | ||||||
| }; | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,23 @@ const path = require("path"); | |||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| describe("validate.js tests", () => { | ||||||||||||||||||||||||||
| beforeAll(async () => { | ||||||||||||||||||||||||||
| await page.goto("http://localhost:8000"); // Replace with your test URL | ||||||||||||||||||||||||||
| // The suite needs a real http(s) origin (isProtocolSafe resolves | ||||||||||||||||||||||||||
| // relative URLs against window.location.origin, which is opaque on | ||||||||||||||||||||||||||
| // about:blank), but no actual server: intercept the navigation and | ||||||||||||||||||||||||||
| // fulfill it with an empty page. | ||||||||||||||||||||||||||
| 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>", | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
Comment on lines
+17
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Proposed fix- if (request.url().startsWith("http://ableplayer.test/")) {
+ if (request.url() === "http://ableplayer.test/") {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| request.continue(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| await page.goto("http://ableplayer.test/"); | ||||||||||||||||||||||||||
|
Comment on lines
+15
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 As per path instructions, 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 AgentsSource: Path instructions |
||||||||||||||||||||||||||
| const validatePath = path.resolve(__dirname, "../../build/test/validate.umd.js"); | ||||||||||||||||||||||||||
| // Add DOMPurify script | ||||||||||||||||||||||||||
| const domPurifyPath = path.resolve( | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
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/checkoutalso retains credentials in the local repository configuration. Pin both actions to approved full commit SHAs and setpersist-credentials: false.Proposed hardening
🧰 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
Source: Linters/SAST tools