Skip to content

Commit bb0fd99

Browse files
authored
Merge pull request #180 from SentienceAPI/rebrand3
fix release pkg
2 parents a872047 + fb528ac commit bb0fd99

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/actions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,12 +1134,14 @@ export async function search(
11341134
const urlBefore = page.url();
11351135
const url = buildSearchUrl(query, engine);
11361136
await browser.goto(url);
1137-
// Some search engines keep long-lived background requests open in CI,
1138-
// so treat networkidle as a best-effort signal instead of a hard requirement.
1137+
// Use lightweight readiness checks instead of networkidle.
1138+
// On Windows CI and some search engines, networkidle can remain pending due to
1139+
// long-lived background requests and cause flaky timeouts.
11391140
try {
1140-
await page.waitForLoadState('networkidle', { timeout: 5000 });
1141+
await page.waitForLoadState('domcontentloaded', { timeout: 5000 });
1142+
await page.waitForLoadState('load', { timeout: 5000 });
11411143
} catch {
1142-
// no-op: page is already loaded enough for URL/result assertions
1144+
// best-effort only; URL/outcome assertions do not require full idle
11431145
}
11441146

11451147
const durationMs = Date.now() - startTime;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { search } from '../src/actions';
2+
3+
describe('search timeout hardening', () => {
4+
it('returns success when post-goto load-state wait times out', async () => {
5+
const page = {
6+
url: jest
7+
.fn()
8+
.mockReturnValueOnce('https://example.com')
9+
.mockReturnValue('https://duckduckgo.com/?q=sentience+sdk'),
10+
waitForLoadState: jest.fn().mockRejectedValue(new Error('Timeout 30000ms exceeded.')),
11+
};
12+
13+
const browser = {
14+
goto: jest.fn().mockResolvedValue(undefined),
15+
snapshot: jest.fn(),
16+
getPage: jest.fn().mockReturnValue(page),
17+
getContext: jest.fn().mockReturnValue(null),
18+
getApiKey: jest.fn().mockReturnValue(undefined),
19+
getApiUrl: jest.fn().mockReturnValue(undefined),
20+
} as any;
21+
22+
const result = await search(browser, 'sentience sdk', 'duckduckgo');
23+
24+
expect(result.success).toBe(true);
25+
expect(result.outcome).toBe('navigated');
26+
expect(browser.goto).toHaveBeenCalledWith('https://duckduckgo.com/?q=sentience+sdk');
27+
expect(page.waitForLoadState).toHaveBeenCalled();
28+
});
29+
});

0 commit comments

Comments
 (0)