Skip to content

Commit 3ef2f64

Browse files
committed
test: add retries and unit test
1 parent 74b8536 commit 3ef2f64

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

browser-tests/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default defineConfig({
1616
fullyParallel: false,
1717
workers: 1,
1818
timeout: 120_000,
19-
retries: 0,
19+
retries: process.env.CI ? 1 : 0,
2020
outputDir: './test-results',
2121
reporter: [['html', { open: 'never', outputFolder: './playwright-report' }]],
2222

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { resolveUIDistDir } from '../web-server.js';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
4+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5+
6+
vi.mock('node:fs');
7+
8+
const existsSync = vi.mocked(fs.existsSync);
9+
10+
describe('resolveUIDistDir', () => {
11+
const originalEnv = process.env;
12+
13+
beforeEach(() => {
14+
process.env = { ...originalEnv };
15+
delete process.env.AGENT_INSPECTOR_PATH;
16+
existsSync.mockReturnValue(false);
17+
});
18+
19+
afterEach(() => {
20+
process.env = originalEnv;
21+
vi.restoreAllMocks();
22+
});
23+
24+
it('returns null when no candidate has index.html', () => {
25+
expect(resolveUIDistDir()).toBeNull();
26+
});
27+
28+
it('returns AGENT_INSPECTOR_PATH when env var is set and dir has index.html', () => {
29+
const customPath = '/custom/inspector/dist';
30+
process.env.AGENT_INSPECTOR_PATH = customPath;
31+
32+
existsSync.mockImplementation(p => p === path.join(customPath, 'index.html'));
33+
34+
expect(resolveUIDistDir()).toBe(customPath);
35+
});
36+
37+
it('skips AGENT_INSPECTOR_PATH when env var is set but dir lacks index.html', () => {
38+
process.env.AGENT_INSPECTOR_PATH = '/missing/inspector';
39+
existsSync.mockReturnValue(false);
40+
41+
expect(resolveUIDistDir()).toBeNull();
42+
});
43+
44+
it('returns the first candidate that has index.html', () => {
45+
existsSync.mockImplementation(p => {
46+
return String(p).endsWith(path.join('agent-inspector', 'index.html'));
47+
});
48+
49+
const result = resolveUIDistDir();
50+
expect(result).not.toBeNull();
51+
expect(result!).toMatch(/agent-inspector$/);
52+
});
53+
54+
it('prefers AGENT_INSPECTOR_PATH over bundled candidates', () => {
55+
const customPath = '/custom/path';
56+
process.env.AGENT_INSPECTOR_PATH = customPath;
57+
58+
existsSync.mockReturnValue(true);
59+
60+
expect(resolveUIDistDir()).toBe(customPath);
61+
});
62+
});

0 commit comments

Comments
 (0)