Update relay-core.test.ts
This commit is contained in:
@@ -172,74 +172,81 @@ describe('Relay Core Tests', () => {
|
|||||||
})
|
})
|
||||||
}, 30000)
|
}, 30000)
|
||||||
|
|
||||||
it('should get accessibility snapshot of hacker news', async () => {
|
const accessibilitySnapshotTestCases = [
|
||||||
await client.callTool({
|
{
|
||||||
name: 'execute',
|
name: 'hacker-news',
|
||||||
arguments: {
|
url: 'https://news.ycombinator.com/item?id=1',
|
||||||
code: js`
|
expectedContent: ['role=link', 'Hacker News'],
|
||||||
const newPage = await context.newPage();
|
},
|
||||||
state.page = newPage;
|
{
|
||||||
if (!state.pages) state.pages = [];
|
name: 'shadcn-ui',
|
||||||
state.pages.push(newPage);
|
url: 'https://ui.shadcn.com/',
|
||||||
`,
|
expectedContent: ['shadcn'],
|
||||||
},
|
},
|
||||||
})
|
]
|
||||||
|
|
||||||
const result = await client.callTool({
|
for (const testCase of accessibilitySnapshotTestCases) {
|
||||||
name: 'execute',
|
it(`should get accessibility snapshot of ${testCase.name}`, async () => {
|
||||||
arguments: {
|
await client.callTool({
|
||||||
code: js`
|
name: 'execute',
|
||||||
await state.page.goto('https://news.ycombinator.com/item?id=1', { waitUntil: 'domcontentloaded' });
|
arguments: {
|
||||||
const snapshot = await accessibilitySnapshot({ page: state.page, showDiffSinceLastCall: false });
|
code: js`
|
||||||
return snapshot;
|
const newPage = await context.newPage();
|
||||||
`,
|
state.page = newPage;
|
||||||
},
|
if (!state.pages) state.pages = [];
|
||||||
})
|
state.pages.push(newPage);
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const initialData =
|
// Capture interactiveOnly=true snapshot (default)
|
||||||
typeof result === 'object' && result.content?.[0]?.text
|
const interactiveResult = await client.callTool({
|
||||||
? tryJsonParse(result.content[0].text)
|
name: 'execute',
|
||||||
: result
|
arguments: {
|
||||||
await expect(initialData).toMatchFileSnapshot(
|
code: js`
|
||||||
'snapshots/hacker-news-initial-accessibility.md',
|
await state.page.goto('${testCase.url}', { waitUntil: 'domcontentloaded' });
|
||||||
)
|
const snapshot = await accessibilitySnapshot({ page: state.page, showDiffSinceLastCall: false, interactiveOnly: true });
|
||||||
expect(result.content).toBeDefined()
|
return snapshot;
|
||||||
expect(initialData).toContain('role=link')
|
`,
|
||||||
expect(initialData).toContain('Hacker News')
|
},
|
||||||
}, 30000)
|
})
|
||||||
|
|
||||||
it('should get accessibility snapshot of shadcn UI', async () => {
|
const interactiveData =
|
||||||
await client.callTool({
|
typeof interactiveResult === 'object' && interactiveResult.content?.[0]?.text
|
||||||
name: 'execute',
|
? tryJsonParse(interactiveResult.content[0].text)
|
||||||
arguments: {
|
: interactiveResult
|
||||||
code: js`
|
await expect(interactiveData).toMatchFileSnapshot(
|
||||||
const newPage = await context.newPage();
|
`snapshots/${testCase.name}-accessibility-interactive.md`,
|
||||||
state.page = newPage;
|
)
|
||||||
if (!state.pages) state.pages = [];
|
expect(interactiveResult.content).toBeDefined()
|
||||||
state.pages.push(newPage);
|
for (const expected of testCase.expectedContent) {
|
||||||
`,
|
expect(interactiveData).toContain(expected)
|
||||||
},
|
}
|
||||||
})
|
|
||||||
|
|
||||||
const snapshot = await client.callTool({
|
// Capture interactiveOnly=false snapshot (full tree)
|
||||||
name: 'execute',
|
const fullResult = await client.callTool({
|
||||||
arguments: {
|
name: 'execute',
|
||||||
code: js`
|
arguments: {
|
||||||
await state.page.goto('https://ui.shadcn.com/', { waitUntil: 'domcontentloaded' });
|
code: js`
|
||||||
const snapshot = await accessibilitySnapshot({ page: state.page });
|
const snapshot = await accessibilitySnapshot({ page: state.page, showDiffSinceLastCall: false, interactiveOnly: false });
|
||||||
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({
|
||||||
|
|||||||
Reference in New Issue
Block a user