From d0ffee9ce5726e514eada38527c8c419f23a7d26 Mon Sep 17 00:00:00 2001 From: Muki Kiboigo Date: Tue, 5 Aug 2025 14:03:31 -0700 Subject: [PATCH] add integration test for old reddit page --- integration/main.go | 1 + integration/old-reddit.js | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 integration/old-reddit.js diff --git a/integration/main.go b/integration/main.go index f627554..339f9e8 100644 --- a/integration/main.go +++ b/integration/main.go @@ -100,6 +100,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) error { {Bin: "node", Args: []string{"integration/duckduckgo.js"}}, {Bin: "node", Args: []string{"integration/algolia.js"}}, {Bin: "node", Args: []string{"integration/github.js"}}, + {Bin: "node", Args: []string{"integration/old-reddit.js"}}, } { if *verbose { t.Stderr = stderr diff --git a/integration/old-reddit.js b/integration/old-reddit.js new file mode 100644 index 0000000..2a05014 --- /dev/null +++ b/integration/old-reddit.js @@ -0,0 +1,52 @@ +// Copyright 2023-2025 Lightpanda (Selecy SAS) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +'use scrict' + +import puppeteer from 'puppeteer-core'; + +const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222'; + +// use browserWSEndpoint to pass the Lightpanda's CDP server address. +const browser = await puppeteer.connect({ + browserWSEndpoint: browserAddress, +}); + +// The rest of your script remains the same. +const context = await browser.createBrowserContext(); +const page = await context.newPage(); + +await page.goto('https://old.reddit.com/r/Zig/comments/1ke7bau/zig_has_great_potential_for_async', {waitUtil: 'networkidle0'}); + +let foundPost = false; +const postBodyText = await page.$eval('.thing.link .usertext-body', el => el.textContent); +if (postBodyText.includes("The ideal async model, I believe, is runtime agnostic, and without function coloring. I think Zig might have what it takes to do this.")) { + foundPost = true; +} + +if (!foundPost) { + console.error("Failed to find main post body"); + throw new Error("invalid results"); +} + + +let foundComment = false; +const commentBodyText = await page.$eval('.commentarea .usertext-body', el => el.textContent); +if (commentBodyText.includes("Async was already present in earlier versions of Zig")) { + foundComment = true; +} + +if (!foundComment) { + console.error("Failed to find comment of post"); + throw new Error("invalid results"); +}