11/**
22 * Requires: npm run build prior to running Jest.
3+ * - If typings are needed, use public types from dist to avoid type identity mismatches between src and dist
4+ * - We're unable to mock fetch for stdio since it runs in a separate process, so we run a server and use that path for mocking external URLs.
35 */
46import { resolve } from 'node:path' ;
57import { pathToFileURL } from 'node:url' ;
@@ -13,7 +15,6 @@ import { setupFetchMock } from './utils/fetchMock';
1315describe ( 'PatternFly MCP, STDIO' , ( ) => {
1416 let FETCH_MOCK : Awaited < ReturnType < typeof setupFetchMock > > | undefined ;
1517 let CLIENT : StdioTransportClient ;
16- // We're unable to mock fetch for stdio since it runs in a separate process, so we run a server and use that path for mocking external URLs.
1718 let URL_MOCK : string ;
1819
1920 beforeAll ( async ( ) => {
@@ -22,7 +23,6 @@ describe('PatternFly MCP, STDIO', () => {
2223 routes : [
2324 {
2425 url : / \/ R E A D M E \. m d $ / ,
25- // url: '/notARealPath/README.md',
2626 status : 200 ,
2727 headers : { 'Content-Type' : 'text/markdown; charset=utf-8' } ,
2828 body : `# PatternFly Development Rules
@@ -39,7 +39,6 @@ describe('PatternFly MCP, STDIO', () => {
3939 } ,
4040 {
4141 url : / .* \. m d $ / ,
42- // url: '/notARealPath/AboutModal.md',
4342 status : 200 ,
4443 headers : { 'Content-Type' : 'text/markdown; charset=utf-8' } ,
4544 body : '# Test Document\n\nThis is a test document for mocking remote HTTP requests.'
@@ -53,7 +52,6 @@ describe('PatternFly MCP, STDIO', () => {
5352
5453 afterAll ( async ( ) => {
5554 if ( CLIENT ) {
56- // You may still receive jest warnings about a running process, but clean up case we forget at the test level.
5755 await CLIENT . close ( ) ;
5856 }
5957
@@ -116,7 +114,7 @@ describe('PatternFly MCP, STDIO', () => {
116114 const response = await CLIENT . send ( req , { timeoutMs : 10000 } ) ;
117115 const text = response ?. result ?. content ?. [ 0 ] ?. text || '' ;
118116
119- // expect(text.startsWith('# Documentation from')).toBe(true);
117+ expect ( text . startsWith ( '# Documentation from' ) ) . toBe ( true ) ;
120118 expect ( text ) . toMatchSnapshot ( ) ;
121119 } ) ;
122120} ) ;
@@ -179,15 +177,25 @@ describe('Tools', () => {
179177 let CLIENT : StdioTransportClient ;
180178
181179 beforeEach ( async ( ) => {
182- const abs = resolve ( process . cwd ( ) , 'tests/__fixtures__/tool.echo.js' ) ;
183- const url = pathToFileURL ( abs ) . href ;
184-
185- CLIENT = await startServer ( { args : [ '--log-stderr' , '--plugin-isolation' , 'strict' , '--tool' , url ] } ) ;
180+ const echoBasicFileUrl = pathToFileURL ( resolve ( process . cwd ( ) , 'tests/__fixtures__/tool.echoBasic.js' ) ) . href ;
181+ const echoToolHelperFileUrl = pathToFileURL ( resolve ( process . cwd ( ) , 'tests/__fixtures__/tool.echoToolHelper.js' ) ) . href ;
182+
183+ CLIENT = await startServer ( {
184+ args : [
185+ '--log-stderr' ,
186+ '--plugin-isolation' ,
187+ 'strict' ,
188+ '--tool' ,
189+ echoBasicFileUrl ,
190+ '--tool' ,
191+ echoToolHelperFileUrl
192+ ]
193+ } ) ;
186194 } ) ;
187195
188196 afterEach ( async ( ) => CLIENT . stop ( ) ) ;
189197
190- itSkip ( envNodeVersion >= 22 ) ( 'should access a new tool ' , async ( ) => {
198+ itSkip ( envNodeVersion >= 22 ) ( 'should access new tools ' , async ( ) => {
191199 const req = {
192200 method : 'tools/list' ,
193201 params : { }
@@ -196,8 +204,11 @@ describe('Tools', () => {
196204 const resp = await CLIENT . send ( req ) ;
197205 const names = ( resp ?. result ?. tools ?? [ ] ) . map ( ( tool : any ) => tool . name ) ;
198206
199- expect ( CLIENT . logs ( ) . join ( ',' ) ) . toContain ( 'Registered tool: echo_plugin_tool' ) ;
200- expect ( names ) . toContain ( 'echo_plugin_tool' ) ;
207+ expect ( CLIENT . logs ( ) . join ( ',' ) ) . toContain ( 'Registered tool: echo_basic_tool' ) ;
208+ expect ( names ) . toContain ( 'echo_basic_tool' ) ;
209+
210+ expect ( CLIENT . logs ( ) . join ( ',' ) ) . toContain ( 'Registered tool: echo_createMcp_tool' ) ;
211+ expect ( names ) . toContain ( 'echo_createMcp_tool' ) ;
201212 } ) ;
202213
203214 itSkip ( envNodeVersion <= 20 ) ( 'should fail to access a new tool' , async ( ) => {
@@ -211,16 +222,23 @@ describe('Tools', () => {
211222 expect ( CLIENT . logs ( ) . join ( ',' ) ) . toContain ( 'External tool plugins require Node >= 22; skipping file-based tools.' ) ;
212223 } ) ;
213224
214- itSkip ( envNodeVersion >= 22 ) ( 'should interact with the new tool' , async ( ) => {
225+ itSkip ( envNodeVersion >= 22 ) . each ( [
226+ {
227+ description : 'echo basic tool' ,
228+ name : 'echo_basic_tool' ,
229+ args : { type : 'echo' , lorem : 'ipsum' , dolor : 'sit amet' }
230+ } ,
231+ {
232+ description : 'echo create MCP tool' ,
233+ name : 'echo_createMcp_tool' ,
234+ args : { type : 'echo' , lorem : 'ipsum' , dolor : 'sit amet' }
235+ }
236+ ] ) ( 'should interact with a tool, $description' , async ( { name, args } ) => {
215237 const req = {
216238 method : 'tools/call' ,
217239 params : {
218- name : 'echo_plugin_tool' ,
219- arguments : {
220- type : 'echo' ,
221- lorem : 'ipsum' ,
222- dolor : 'sit amet'
223- }
240+ name,
241+ arguments : args
224242 }
225243 } ;
226244
@@ -230,16 +248,23 @@ describe('Tools', () => {
230248 expect ( resp . result . isError ) . toBeUndefined ( ) ;
231249 } ) ;
232250
233- itSkip ( envNodeVersion <= 20 ) ( 'should fail to interact with the new tool' , async ( ) => {
251+ itSkip ( envNodeVersion <= 20 ) . each ( [
252+ {
253+ description : 'echo basic tool' ,
254+ name : 'echo_basic_tool' ,
255+ args : { type : 'echo' , lorem : 'ipsum' , dolor : 'sit amet' }
256+ } ,
257+ {
258+ description : 'echo create MCP tool' ,
259+ name : 'echo_createMcp_tool' ,
260+ args : { type : 'echo' , lorem : 'ipsum' , dolor : 'sit amet' }
261+ }
262+ ] ) ( 'should fail to interact with a tool, $description' , async ( { name, args } ) => {
234263 const req = {
235264 method : 'tools/call' ,
236265 params : {
237- name : 'echo_plugin_tool' ,
238- arguments : {
239- type : 'echo' ,
240- lorem : 'ipsum' ,
241- dolor : 'sit amet'
242- }
266+ name,
267+ arguments : args
243268 }
244269 } ;
245270
0 commit comments