Files
Mahesh Singh e3d9e791b7 test: migrate lighthouse emulation restore test to unit test (#2725)
Ref: #2639
Prior PRs: #2641, #2665, #2683, #2698, #2704

### Rationale

Unlike tools whose core logic is delegated to \McpPage\ or \McpContext\,
Lighthouse's audit execution and report generation live directly inside
\src/tools/lighthouse.ts\. As noted by @OrKoN, tests verifying genuine
Lighthouse audit behavior must stay as real-browser e2e tests because
there is no lower-level class to isolate them against.

Incidental side-effects owned by another class—specifically \ estores
emulation\, which tests \McpPage.restoreEmulation()\—are converted to
mock-based unit tests to verify handler wiring, while real behavior
coverage is relocated to \ ests/McpPage.test.ts\.

### Test Classification in \	ests/tools/lighthouse.test.ts\

- **\ uns Lighthouse audit by default (navigation, desktop)\** — **Stays
Real**: Tests genuine Lighthouse navigation audit, score summary, report
generation (JSON & HTML), and filesystem writes.
- **\ estores emulation\** — **Converted to Mocks**: Verifies handler
calls \page.restoreEmulation()\ in its \ inally\ block; real behavior is
relocated to \ ests/McpPage.test.ts\.
- **\ estores emulation even when audit fails\** — **New Unit Test**:
Verifies handler reliably calls \page.restoreEmulation()\ even if the
audit operation rejects.
- **\ uns Lighthouse in snapshot mode with mobile device\** — **Stays
Real**: Tests genuine Lighthouse snapshot audit execution and mobile
device emulation settings.
- **\ uns Lighthouse with custom output dir\** — **Stays Real**: Tests
genuine report generation and file persistence with a custom output
directory.

### Key Changes

- **\src/third_party/index.ts\**: Exported \lighthouseRunner =
{snapshot, navigation}\ (and kept individual exports for backward
compatibility).
- **\src/tools/lighthouse.ts\**: Imported \lighthouseRunner\ from
\../third_party/index.js\ and updated handler to invoke
\lighthouseRunner.navigation(...)\ / \lighthouseRunner.snapshot(...)\.
- **\ ests/tools/lighthouse.test.ts\**: Converted \ estores emulation\
to use \createHandlerMocks()\, stubbing \sinon.stub(lighthouseRunner,
'snapshot')\; added \fterEach(() => sinon.restore())\.
- **\ ests/McpPage.test.ts\**: Added dedicated
\describe('restoreEmulation()', ...)\ suite testing that \
estoreEmulation()\ restores viewport, network conditions, and CPU
throttling settings on the underlying Puppeteer page.
- **\ ests/mocks.ts\**: Added \createMockRunnerResult()\ factory
returning a minimal, type-safe \RunnerResult\.
2026-09-11 08:03:42 +00:00
..