-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathtools.test.ts
More file actions
74 lines (68 loc) · 2.02 KB
/
tools.test.ts
File metadata and controls
74 lines (68 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import {describe, it} from 'node:test';
import {evaluate, navigate, screenshot} from '../../../src/tools/slim/tools.js';
import {screenshots} from '../../snapshot.js';
import {withMcpContext} from '../../utils.js';
describe('slim', () => {
it('evaluates', async t => {
await withMcpContext(async (response, context) => {
await evaluate.handler(
{
params: {
script: `2 * 5`,
},
},
response,
context,
);
t.assert.snapshot?.(response.responseLines.join('\n'));
});
});
it('handles errors', async t => {
await withMcpContext(async (response, context) => {
await evaluate.handler(
{
params: {
script: `throw new Error('test error')`,
},
},
response,
context,
);
t.assert.snapshot?.(response.responseLines.join('\n'));
});
});
it('navigates to correct page', async t => {
await withMcpContext(async (response, context) => {
await navigate.handler(
{params: {url: 'data:text/html,<div>Hello MCP</div>'}},
response,
context,
);
const page = context.getSelectedPage();
assert.equal(
await page.evaluate(() => document.querySelector('div')?.textContent),
'Hello MCP',
);
assert(!response.includePages);
t.assert.snapshot?.(response.responseLines.join('\n'));
});
});
it('with default options', async () => {
await withMcpContext(async (response, context) => {
const fixture = screenshots.basic;
const page = context.getSelectedPage();
await page.setContent(fixture.html);
await screenshot.handler({params: {format: 'png'}}, response, context);
assert(path.isAbsolute(response.responseLines.at(0)!));
assert(fs.existsSync(response.responseLines.at(0)!));
});
});
});