Update relay-core.test.ts

This commit is contained in:
Tommy D. Rossi
2026-02-03 12:36:57 +01:00
parent 1b6be13d11
commit d0489b3d48
+45 -38
View File
@@ -172,7 +172,21 @@ describe('Relay Core Tests', () => {
}) })
}, 30000) }, 30000)
it('should get accessibility snapshot of hacker news', async () => { const accessibilitySnapshotTestCases = [
{
name: 'hacker-news',
url: 'https://news.ycombinator.com/item?id=1',
expectedContent: ['role=link', 'Hacker News'],
},
{
name: 'shadcn-ui',
url: 'https://ui.shadcn.com/',
expectedContent: ['shadcn'],
},
]
for (const testCase of accessibilitySnapshotTestCases) {
it(`should get accessibility snapshot of ${testCase.name}`, async () => {
await client.callTool({ await client.callTool({
name: 'execute', name: 'execute',
arguments: { arguments: {
@@ -185,61 +199,54 @@ describe('Relay Core Tests', () => {
}, },
}) })
const result = await client.callTool({ // Capture interactiveOnly=true snapshot (default)
const interactiveResult = await client.callTool({
name: 'execute', name: 'execute',
arguments: { arguments: {
code: js` code: js`
await state.page.goto('https://news.ycombinator.com/item?id=1', { waitUntil: 'domcontentloaded' }); await state.page.goto('${testCase.url}', { waitUntil: 'domcontentloaded' });
const snapshot = await accessibilitySnapshot({ page: state.page, showDiffSinceLastCall: false }); const snapshot = await accessibilitySnapshot({ page: state.page, showDiffSinceLastCall: false, interactiveOnly: true });
return snapshot; return snapshot;
`, `,
}, },
}) })
const initialData = const interactiveData =
typeof result === 'object' && result.content?.[0]?.text typeof interactiveResult === 'object' && interactiveResult.content?.[0]?.text
? tryJsonParse(result.content[0].text) ? tryJsonParse(interactiveResult.content[0].text)
: result : interactiveResult
await expect(initialData).toMatchFileSnapshot( await expect(interactiveData).toMatchFileSnapshot(
'snapshots/hacker-news-initial-accessibility.md', `snapshots/${testCase.name}-accessibility-interactive.md`,
) )
expect(result.content).toBeDefined() expect(interactiveResult.content).toBeDefined()
expect(initialData).toContain('role=link') for (const expected of testCase.expectedContent) {
expect(initialData).toContain('Hacker News') expect(interactiveData).toContain(expected)
}, 30000) }
it('should get accessibility snapshot of shadcn UI', async () => { // Capture interactiveOnly=false snapshot (full tree)
await client.callTool({ const fullResult = await client.callTool({
name: 'execute', name: 'execute',
arguments: { arguments: {
code: js` code: js`
const newPage = await context.newPage(); const snapshot = await accessibilitySnapshot({ page: state.page, showDiffSinceLastCall: false, interactiveOnly: false });
state.page = newPage;
if (!state.pages) state.pages = [];
state.pages.push(newPage);
`,
},
})
const snapshot = await client.callTool({
name: 'execute',
arguments: {
code: js`
await state.page.goto('https://ui.shadcn.com/', { waitUntil: 'domcontentloaded' });
const snapshot = await accessibilitySnapshot({ page: state.page });
return snapshot; return snapshot;
`, `,
}, },
}) })
const data = const fullData =
typeof snapshot === 'object' && snapshot.content?.[0]?.text typeof fullResult === 'object' && fullResult.content?.[0]?.text
? tryJsonParse(snapshot.content[0].text) ? tryJsonParse(fullResult.content[0].text)
: snapshot : fullResult
await expect(data).toMatchFileSnapshot('snapshots/shadcn-ui-accessibility.md') await expect(fullData).toMatchFileSnapshot(
expect(snapshot.content).toBeDefined() `snapshots/${testCase.name}-accessibility-full.md`,
expect(data).toContain('shadcn') )
}, 30000) expect(fullResult.content).toBeDefined()
for (const expected of testCase.expectedContent) {
expect(fullData).toContain(expected)
}
}, 60000)
}
it('should close all created pages', async () => { it('should close all created pages', async () => {
const result = await client.callTool({ const result = await client.callTool({