test(lint): reduce warning debt in selected test suites
This commit is contained in:
@@ -34,6 +34,14 @@ const mockManager = {
|
||||
describe('Browser tools', () => {
|
||||
let tools: ReturnType<typeof createBrowserTools>;
|
||||
|
||||
function getTool(name: string) {
|
||||
const tool = tools.find(t => t.name === name);
|
||||
if (!tool) {
|
||||
throw new Error(`Tool not found: ${name}`);
|
||||
}
|
||||
return tool;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
tools = createBrowserTools(mockManager);
|
||||
@@ -51,7 +59,7 @@ describe('Browser tools', () => {
|
||||
});
|
||||
|
||||
it('browser.navigate navigates to URL', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.navigate')!;
|
||||
const tool = getTool('browser.navigate');
|
||||
const result = await tool.execute({ url: 'https://example.com' });
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.output).toContain('example.com');
|
||||
@@ -59,13 +67,13 @@ describe('Browser tools', () => {
|
||||
});
|
||||
|
||||
it('browser.navigate respects custom waitUntil', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.navigate')!;
|
||||
const tool = getTool('browser.navigate');
|
||||
await tool.execute({ url: 'https://example.com', waitUntil: 'networkidle0' });
|
||||
expect(mockGoto).toHaveBeenCalledWith('https://example.com', { waitUntil: 'networkidle0' });
|
||||
});
|
||||
|
||||
it('browser.screenshot takes page screenshot', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.screenshot')!;
|
||||
const tool = getTool('browser.screenshot');
|
||||
const result = await tool.execute({});
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.output).toContain('Screenshot captured');
|
||||
@@ -73,7 +81,7 @@ describe('Browser tools', () => {
|
||||
});
|
||||
|
||||
it('browser.screenshot takes element screenshot', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.screenshot')!;
|
||||
const tool = getTool('browser.screenshot');
|
||||
const result = await tool.execute({ selector: '#header' });
|
||||
expect(result.success).toBe(true);
|
||||
expect(mock$).toHaveBeenCalledWith('#header');
|
||||
@@ -81,28 +89,28 @@ describe('Browser tools', () => {
|
||||
|
||||
it('browser.screenshot fails for missing element', async () => {
|
||||
mock$.mockResolvedValueOnce(null);
|
||||
const tool = tools.find(t => t.name === 'browser.screenshot')!;
|
||||
const tool = getTool('browser.screenshot');
|
||||
const result = await tool.execute({ selector: '#nonexistent' });
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error).toContain('Element not found');
|
||||
});
|
||||
|
||||
it('browser.click clicks element', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.click')!;
|
||||
const tool = getTool('browser.click');
|
||||
const result = await tool.execute({ selector: '#submit' });
|
||||
expect(result.success).toBe(true);
|
||||
expect(mockClick).toHaveBeenCalledWith('#submit');
|
||||
});
|
||||
|
||||
it('browser.type types into element', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.type')!;
|
||||
const tool = getTool('browser.type');
|
||||
const result = await tool.execute({ selector: '#search', text: 'hello' });
|
||||
expect(result.success).toBe(true);
|
||||
expect(mockType).toHaveBeenCalledWith('#search', 'hello');
|
||||
});
|
||||
|
||||
it('browser.type clears field before typing when clear=true', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.type')!;
|
||||
const tool = getTool('browser.type');
|
||||
await tool.execute({ selector: '#search', text: 'hello', clear: true });
|
||||
expect(mockClick).toHaveBeenCalledWith('#search', { count: 3 });
|
||||
expect(mockKeyboard.press).toHaveBeenCalledWith('Backspace');
|
||||
@@ -110,7 +118,7 @@ describe('Browser tools', () => {
|
||||
});
|
||||
|
||||
it('browser.content returns page text', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.content')!;
|
||||
const tool = getTool('browser.content');
|
||||
const result = await tool.execute({});
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.output).toContain('Page content here');
|
||||
@@ -119,13 +127,13 @@ describe('Browser tools', () => {
|
||||
});
|
||||
|
||||
it('browser.content uses custom selector', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.content')!;
|
||||
const tool = getTool('browser.content');
|
||||
await tool.execute({ selector: '#main' });
|
||||
expect(mock$eval).toHaveBeenCalledWith('#main', expect.any(Function));
|
||||
});
|
||||
|
||||
it('browser.eval evaluates JS', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.eval')!;
|
||||
const tool = getTool('browser.eval');
|
||||
const result = await tool.execute({ expression: '1 + 1' });
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.output).toContain('42');
|
||||
@@ -133,7 +141,7 @@ describe('Browser tools', () => {
|
||||
|
||||
it('browser.eval returns string results directly', async () => {
|
||||
mockEvaluate.mockResolvedValueOnce('hello world');
|
||||
const tool = tools.find(t => t.name === 'browser.eval')!;
|
||||
const tool = getTool('browser.eval');
|
||||
const result = await tool.execute({ expression: '"hello world"' });
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.output).toBe('hello world');
|
||||
@@ -141,7 +149,7 @@ describe('Browser tools', () => {
|
||||
|
||||
it('handles navigation errors gracefully', async () => {
|
||||
mockGoto.mockRejectedValueOnce(new Error('Navigation failed'));
|
||||
const tool = tools.find(t => t.name === 'browser.navigate')!;
|
||||
const tool = getTool('browser.navigate');
|
||||
const result = await tool.execute({ url: 'https://broken.example.com' });
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error).toContain('Navigation failed');
|
||||
@@ -149,14 +157,14 @@ describe('Browser tools', () => {
|
||||
|
||||
it('handles click errors gracefully', async () => {
|
||||
mockClick.mockRejectedValueOnce(new Error('Element not found'));
|
||||
const tool = tools.find(t => t.name === 'browser.click')!;
|
||||
const tool = getTool('browser.click');
|
||||
const result = await tool.execute({ selector: '#missing' });
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error).toContain('Element not found');
|
||||
});
|
||||
|
||||
it('returns aborted error when signal is already aborted', async () => {
|
||||
const tool = tools.find(t => t.name === 'browser.navigate')!;
|
||||
const tool = getTool('browser.navigate');
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user