Skip to content

Commit fa13e13

Browse files
committed
test(core): add tests for browser agent funcionality
1 parent 33ee4f1 commit fa13e13

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

jest.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
extensionsToTreatAsEsm: ['.ts'],
5+
testMatch: ['**/tests/**/*.test.ts'],
6+
clearMocks: true,
7+
resetMocks: true,
8+
moduleNameMapper: {
9+
'^(\\.{1,2}/.*)\\.js$': '$1',
10+
},
11+
transformIgnorePatterns: ['/node_modules/(?!(@modelcontextprotocol)/)'],
12+
transform: {
13+
'^.+\\.tsx?$': [
14+
'ts-jest',
15+
{
16+
useESM: true,
17+
},
18+
],
19+
},
20+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcp-browser-agent",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"author":{
55
"name": "Iván Luna",
66
"email": "[email protected]",

tests/basic.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { test, expect, describe, jest } from '@jest/globals';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
const rootDir = path.resolve(__dirname, '..');
9+
10+
describe('MCP Browser Agent - Basic Tests', () => {
11+
test('Package should be properly configured', async () => {
12+
const packageJsonPath = path.join(rootDir, 'package.json');
13+
const packageJsonContent = await fs.promises.readFile(packageJsonPath, 'utf8');
14+
const packageJson = JSON.parse(packageJsonContent);
15+
16+
expect(packageJson.name).toBe('mcp-browser-agent');
17+
expect(packageJson.type).toBe('module');
18+
expect(typeof packageJson.scripts.test).toBe('string');
19+
});
20+
21+
test('Project should have required files', async () => {
22+
expect(fs.existsSync(path.join(rootDir, 'src/index.ts'))).toBeTruthy();
23+
expect(fs.existsSync(path.join(rootDir, 'src/executor.ts'))).toBeTruthy();
24+
expect(fs.existsSync(path.join(rootDir, 'src/tools.ts'))).toBeTruthy();
25+
expect(fs.existsSync(path.join(rootDir, 'src/handlers.ts'))).toBeTruthy();
26+
});
27+
28+
test('Tools module should exist', async () => {
29+
const toolsPath = path.join(rootDir, 'src/tools.ts');
30+
expect(fs.existsSync(toolsPath)).toBeTruthy();
31+
32+
const toolsContent = await fs.promises.readFile(toolsPath, 'utf8');
33+
expect(toolsContent).toContain('BROWSER_TOOLS');
34+
expect(toolsContent).toContain('browser_navigate');
35+
expect(toolsContent).toContain('browser_screenshot');
36+
expect(toolsContent).toContain('API_TOOLS');
37+
expect(toolsContent).toContain('api_get');
38+
expect(toolsContent).toContain('api_post');
39+
});
40+
});

tests/browser-error.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { test, expect, describe, jest, beforeAll } from '@jest/globals';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
const rootDir = path.resolve(__dirname, '..');
9+
const processEvents: Record<string, Array<() => void>> = {
10+
'SIGINT': [],
11+
'SIGTERM': []
12+
};
13+
14+
let cleanupFn: boolean | undefined;
15+
16+
beforeAll(() => {
17+
const executorPath = path.join(rootDir, 'src/executor.ts');
18+
const executorContent = fs.readFileSync(executorPath, 'utf8');
19+
if (executorContent.includes('process.on(\'SIGINT\'')) {
20+
processEvents['SIGINT'] = [() => {}];
21+
}
22+
23+
if (executorContent.includes('process.on(\'SIGTERM\'')) {
24+
processEvents['SIGTERM'] = [() => {}];
25+
}
26+
27+
if (executorContent.includes('cleanupBrowser')) {
28+
cleanupFn = true;
29+
}
30+
});
31+
32+
describe('Browser Error Handling Tests', () => {
33+
test('Executor should contain process cleanup handlers', async () => {
34+
const executorPath = path.join(rootDir, 'src/executor.ts');
35+
const executorContent = fs.readFileSync(executorPath, 'utf8');
36+
expect(executorContent.includes('process.on(\'SIGINT\'')).toBeTruthy();
37+
expect(executorContent.includes('process.on(\'SIGTERM\'')).toBeTruthy();
38+
expect(executorContent.includes('cleanupBrowser')).toBeTruthy();
39+
});
40+
41+
test('README should contain browser process cleanup documentation', () => {
42+
const readmePath = path.join(rootDir, 'README.md');
43+
const readmeContent = fs.readFileSync(readmePath, 'utf8');
44+
expect(readmeContent).toContain('Browser process not closing properly');
45+
expect(readmeContent).toContain('Windows');
46+
expect(readmeContent).toContain('macOS');
47+
expect(readmeContent).toContain('Linux');
48+
expect(readmeContent).toContain('Playwright');
49+
expect(readmeContent).toContain('issues');
50+
expect(readmeContent).toContain('github.com/microsoft/playwright/issues');
51+
});
52+
});

0 commit comments

Comments
 (0)