Skip to content

Commit 5b54892

Browse files
committed
chore: try snapshot
1 parent 76c7d57 commit 5b54892

File tree

8 files changed

+36
-26
lines changed

8 files changed

+36
-26
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Build
4545
run: npm run bundle
4646
env:
47-
NODE_OPTIONS: '--max_old_space_size=4096'
47+
NODE_OPTIONS: '--max_old_space_size=8192'
4848

4949
- name: Set up Node.js
5050
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
347347
- **Emulation** (2 tools)
348348
- [`emulate`](docs/tool-reference.md#emulate)
349349
- [`resize_page`](docs/tool-reference.md#resize_page)
350-
- **Performance** (3 tools)
350+
- **Performance** (4 tools)
351+
- [`lighthouse_audit`](docs/tool-reference.md#lighthouse_audit)
351352
- [`performance_analyze_insight`](docs/tool-reference.md#performance_analyze_insight)
352353
- [`performance_start_trace`](docs/tool-reference.md#performance_start_trace)
353354
- [`performance_stop_trace`](docs/tool-reference.md#performance_stop_trace)

docs/tool-reference.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
- **[Emulation](#emulation)** (2 tools)
2222
- [`emulate`](#emulate)
2323
- [`resize_page`](#resize_page)
24-
- **[Performance](#performance)** (3 tools)
24+
- **[Performance](#performance)** (4 tools)
25+
- [`lighthouse_audit`](#lighthouse_audit)
2526
- [`performance_analyze_insight`](#performance_analyze_insight)
2627
- [`performance_start_trace`](#performance_start_trace)
2728
- [`performance_stop_trace`](#performance_stop_trace)
@@ -225,6 +226,14 @@
225226

226227
## Performance
227228

229+
### `lighthouse_audit`
230+
231+
**Description:** Runs a Lighthouse accessibility audit on the currently selected page. This tool analyzes the page for accessibility issues and provides a detailed report with scores and recommendations.
232+
233+
**Parameters:** None
234+
235+
---
236+
228237
### `performance_analyze_insight`
229238

230239
**Description:** Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording.

scripts/prepare.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ function removeConflictingGlobalDeclaration(): void {
2727
projectRoot,
2828
'node_modules/@paulirish/trace_engine/models/trace/ModelImpl.d.ts',
2929
);
30-
console.log('Removing conflicting global declaration from @paulirish/trace_engine...');
30+
console.log(
31+
'Removing conflicting global declaration from @paulirish/trace_engine...',
32+
);
3133
const content = readFileSync(filePath, 'utf-8');
3234
// Remove the declare global block using regex
3335
// Matches: declare global { ... interface HTMLElementEventMap { ... } ... }

src/third_party/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ export {
3838
type ChromeReleaseChannel as BrowsersChromeReleaseChannel,
3939
} from '@puppeteer/browsers';
4040

41-
export * as Lighthouse from 'lighthouse';
41+
export {snapshot} from './lighthouse-devtools-mcp-bundle.js';
42+
4243
export * as DevTools from '../../node_modules/chrome-devtools-frontend/mcp/mcp.js';

src/tools/lighthouse.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {Lighthouse, zod} from '../third_party/index.js';
7+
import {snapshot} from '../third_party/index.js';
88

99
import {ToolCategory} from './categories.js';
1010
import {defineTool} from './ToolDefinition.js';
@@ -19,20 +19,21 @@ export const lighthouseAudit = defineTool({
1919
schema: {},
2020
handler: async (request, response, context) => {
2121
const page = context.getSelectedPage();
22-
const url = page.url();
23-
2422
const flags = {
2523
onlyCategories: ['accessibility'],
2624
};
27-
28-
const result = await Lighthouse.default(url, flags, undefined, page);
25+
const result = await snapshot(page, {
26+
flags,
27+
});
2928
const lhr = result!.lhr;
3029
const accessibilityCategory = lhr.categories.accessibility;
3130

3231
const failedAudits = Object.values(lhr.audits).filter(
32+
// @ts-ignore
3333
audit => audit.score !== null && audit.score < 1,
3434
);
3535
const passedAudits = Object.values(lhr.audits).filter(
36+
// @ts-ignore
3637
audit => audit.score === 1,
3738
);
3839

tests/tools/lighthouse.test.js.snapshot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ exports[`lighthouse > lighthouse_audit > runs Lighthouse accessibility audit 1`]
3333
"top": 0,
3434
"bottom": 34,
3535
"left": 0,
36-
"right": 412,
37-
"width": 412,
36+
"right": 1200,
37+
"width": 1200,
3838
"height": 34
3939
},
4040
"snippet": "<html lang=\\"en\\">",

tests/tools/lighthouse.test.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import assert from 'node:assert';
87
import {describe, it} from 'node:test';
98

109
import {lighthouseAudit} from '../../src/tools/lighthouse.js';
@@ -14,21 +13,18 @@ import {html, withMcpContext} from '../utils.js';
1413
describe('lighthouse', () => {
1514
const server = serverHooks();
1615
describe('lighthouse_audit', () => {
17-
it(
18-
'runs Lighthouse accessibility audit',
19-
async (t) => {
20-
server.addHtmlRoute('/test', html`<div>Test</div>`);
16+
it('runs Lighthouse accessibility audit', async t => {
17+
server.addHtmlRoute('/test', html`<div>Test</div>`);
2118

22-
await withMcpContext(async (response, context) => {
23-
const page = context.getSelectedPage();
24-
await page.goto(server.getRoute('/test'));
19+
await withMcpContext(async (response, context) => {
20+
const page = context.getSelectedPage();
21+
await page.goto(server.getRoute('/test'));
2522

26-
await lighthouseAudit.handler({params: {}}, response, context);
23+
await lighthouseAudit.handler({params: {}}, response, context);
2724

28-
const responseText = response.responseLines.join('\n');
29-
t.assert.snapshot?.(responseText);
30-
});
31-
},
32-
);
25+
const responseText = response.responseLines.join('\n');
26+
t.assert.snapshot?.(responseText);
27+
});
28+
});
3329
});
3430
});

0 commit comments

Comments
 (0)