Skip to content

Commit 7037c8c

Browse files
authored
Merge pull request #53 from lightpanda-io/algolia
add algolia integration test
2 parents d82972f + 9baeb41 commit 7037c8c

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

integration/algolia.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
const baseURL = process.env.URL ? process.env.URL : 'http://127.0.0.1:1234'
20+
21+
// use browserWSEndpoint to pass the Lightpanda's CDP server address.
22+
const browser = await puppeteer.connect({
23+
browserWSEndpoint: browserAddress,
24+
});
25+
26+
// The rest of your script remains the same.
27+
const context = await browser.createBrowserContext();
28+
const page = await context.newPage();
29+
30+
await page.goto('https://hn.algolia.com/?q=lightpanda', {waitUtil: 'networkidle0'});
31+
32+
await page.waitForFunction(() => {
33+
return document.querySelector('.Story_title') != null;
34+
}, {timeout: 1000});
35+
36+
const titles = await page.evaluate(() => {
37+
return Array.from(document.querySelectorAll('.Story_title span')).map(row => {
38+
return row.textContent;
39+
});
40+
});
41+
42+
await page.close();
43+
await context.close();
44+
await browser.disconnect();
45+
46+
let found = {
47+
homepage: false,
48+
github: false,
49+
}
50+
for (const title of titles) {
51+
if (title === 'Show HN: Lightpanda, an open-source headless browser in Zig') found.homepage = true;
52+
else if (title === 'Lightpanda: Headless browser designed for AI and automation') found.github = true;
53+
}
54+
55+
if (!found.homepage || !found.github) {
56+
console.log("Failed to find expected links", found);
57+
throw new Error("invalid results");
58+
}
59+

integration/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) error {
9898
fails := 0
9999
for _, t := range []Test{
100100
{Bin: "node", Args: []string{"integration/duckduckgo.js"}},
101+
{Bin: "node", Args: []string{"integration/algolia.js"}},
101102
} {
102103
if *verbose {
103104
t.Stderr = stderr

0 commit comments

Comments
 (0)