@@ -11,7 +11,6 @@ import {afterEach, describe, it} from 'node:test';
1111import sinon from 'sinon' ;
1212
1313import type { ParsedArguments } from '../../src/cli.js' ;
14- import type { McpResponse } from '../../src/McpResponse.js' ;
1514import {
1615 installExtension ,
1716 uninstallExtension ,
@@ -20,7 +19,7 @@ import {
2019 triggerExtensionAction ,
2120} from '../../src/tools/extensions.js' ;
2221import { listPages } from '../../src/tools/pages.js' ;
23- import { withMcpContext } from '../utils.js' ;
22+ import { extractId , withMcpContext } from '../utils.js' ;
2423
2524const EXTENSION_WITH_SW_PATH = path . join (
2625 import . meta. dirname ,
@@ -31,15 +30,6 @@ const EXTENSION_PATH = path.join(
3130 '../../../tests/tools/fixtures/extension' ,
3231) ;
3332
34- export function extractId ( response : McpResponse ) {
35- const responseLine = response . responseLines [ 0 ] ;
36- assert . ok ( responseLine , 'Response should not be empty' ) ;
37- const match = responseLine . match ( / E x t e n s i o n i n s t a l l e d \. I d : ( .+ ) / ) ;
38- const extensionId = match ? match [ 1 ] : null ;
39- assert . ok ( extensionId , 'Response should contain a valid key' ) ;
40- return extensionId ;
41- }
42-
4333describe ( 'extension' , ( ) => {
4434 afterEach ( ( ) => {
4535 sinon . restore ( ) ;
@@ -135,17 +125,13 @@ describe('extension', () => {
135125 assert . ok ( reinstalled , 'Extension should be present after reload' ) ;
136126 } ) ;
137127 } ) ;
138- it ( 'triggers an extension action' , async ( ) => {
128+ it ( 'triggers an extension action' , async t => {
139129 await withMcpContext (
140130 async ( response , context ) => {
141- await installExtension . handler (
142- { params : { path : EXTENSION_WITH_SW_PATH } } ,
143- response ,
144- context ,
131+ const extensionId = await context . installExtension (
132+ EXTENSION_WITH_SW_PATH ,
145133 ) ;
146134
147- const extensionId = extractId ( response ) ;
148-
149135 response . resetResponseLineForTesting ( ) ;
150136 const listPageDef = listPages ( {
151137 categoryExtensions : true ,
@@ -160,9 +146,8 @@ describe('extension', () => {
160146 type : 'text' ;
161147 text : string ;
162148 } ;
163- assert . ok (
164- ! textContent . text . includes ( extensionId ) ,
165- 'Response should not contain extension service worker id' ,
149+ t . assert . snapshot ?.(
150+ textContent . text . replaceAll ( extensionId , '<extension-id>' ) ,
166151 ) ;
167152
168153 await triggerExtensionAction . handler (
@@ -187,9 +172,11 @@ describe('extension', () => {
187172 type : 'text' ;
188173 text : string ;
189174 } ;
190- assert . ok (
191- textContent . text . includes ( swUrl ) ,
192- 'Response should contain extension service worker url' ,
175+ t . assert . snapshot ?.(
176+ textContent . text
177+ . replaceAll ( extensionId , '<extension-id>' )
178+ . replaceAll ( swUrl , '<sw-url>' )
179+ . replaceAll ( / l o c a l h o s t : \d + / g, 'localhost:<port>' ) ,
193180 ) ;
194181 } ,
195182 {
0 commit comments