Skip to content

Commit 1da76d0

Browse files
stabilize the snapshot content
1 parent ba6117c commit 1da76d0

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

tests/McpResponse.test.js.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ uid=1_0 RootWebArea "My test page" url="about:blank"
3131
exports[`McpResponse > saves snapshot to file 1`] = `
3232
# test response
3333
## Page content
34-
Saved snapshot to /tmp/test-screenshot.png.
34+
Saved snapshot to <file>
3535
`;
3636

3737
exports[`McpResponse > saves snapshot to file 2`] = `

tests/McpResponse.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import {tmpdir} from 'node:os';
99
import {join} from 'node:path';
1010
import {describe, it} from 'node:test';
1111

12-
import {getMockRequest, getMockResponse, html, withBrowser} from './utils.js';
12+
import {
13+
getMockRequest,
14+
getMockResponse,
15+
html,
16+
stabilizeResponseOutput,
17+
withBrowser,
18+
} from './utils.js';
1319

1420
describe('McpResponse', () => {
1521
it('list pages', async () => {
@@ -100,7 +106,7 @@ Testing 2`,
100106
});
101107
});
102108

103-
it('saves snapshot to file', async t => {
109+
it.only('saves snapshot to file', async t => {
104110
const filePath = join(tmpdir(), 'test-screenshot.png');
105111
try {
106112
await withBrowser(async (response, context) => {
@@ -112,10 +118,11 @@ Testing 2`,
112118
});
113119
const result = await response.handle('test', context);
114120
assert.equal(result[0].type, 'text');
115-
t.assert.snapshot?.(result[0].text);
121+
console.log(result[0].text);
122+
t.assert.snapshot?.(stabilizeResponseOutput(result[0].text));
116123
});
117124
const content = await readFile(filePath, 'utf-8');
118-
t.assert.snapshot?.(content);
125+
t.assert.snapshot?.(stabilizeResponseOutput(content));
119126
} finally {
120127
await rm(filePath, {force: true});
121128
}

tests/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,8 @@ export function stabilizeResponseOutput(text: unknown) {
164164
// sec-ch-ua-platform:"Linux"
165165
const chUaPlatformRegEx = /sec-ch-ua-platform:"[a-zA-Z]*"/g;
166166
output = output.replaceAll(chUaPlatformRegEx, 'sec-ch-ua-platform:"<os>"');
167+
168+
const savedSnapshot = /Saved snapshot to (.*)/g;
169+
output = output.replaceAll(savedSnapshot, 'Saved snapshot to <file>');
167170
return output;
168171
}

0 commit comments

Comments
 (0)