Skip to content

Commit d0ffee9

Browse files
committed
add integration test for old reddit page
1 parent 3e54bc0 commit d0ffee9

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

integration/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) error {
100100
{Bin: "node", Args: []string{"integration/duckduckgo.js"}},
101101
{Bin: "node", Args: []string{"integration/algolia.js"}},
102102
{Bin: "node", Args: []string{"integration/github.js"}},
103+
{Bin: "node", Args: []string{"integration/old-reddit.js"}},
103104
} {
104105
if *verbose {
105106
t.Stderr = stderr

integration/old-reddit.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2023-2025 Lightpanda (Selecy SAS)
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use scrict'
15+
16+
import puppeteer from 'puppeteer-core';
17+
18+
const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222';
19+
20+
// use browserWSEndpoint to pass the Lightpanda's CDP server address.
21+
const browser = await puppeteer.connect({
22+
browserWSEndpoint: browserAddress,
23+
});
24+
25+
// The rest of your script remains the same.
26+
const context = await browser.createBrowserContext();
27+
const page = await context.newPage();
28+
29+
await page.goto('https://old.reddit.com/r/Zig/comments/1ke7bau/zig_has_great_potential_for_async', {waitUtil: 'networkidle0'});
30+
31+
let foundPost = false;
32+
const postBodyText = await page.$eval('.thing.link .usertext-body', el => el.textContent);
33+
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.")) {
34+
foundPost = true;
35+
}
36+
37+
if (!foundPost) {
38+
console.error("Failed to find main post body");
39+
throw new Error("invalid results");
40+
}
41+
42+
43+
let foundComment = false;
44+
const commentBodyText = await page.$eval('.commentarea .usertext-body', el => el.textContent);
45+
if (commentBodyText.includes("Async was already present in earlier versions of Zig")) {
46+
foundComment = true;
47+
}
48+
49+
if (!foundComment) {
50+
console.error("Failed to find comment of post");
51+
throw new Error("invalid results");
52+
}

0 commit comments

Comments
 (0)