@frontmcp/testing 1.10.15 → 1.11.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -3
- package/client/mcp-test-client.d.ts +5 -4
- package/client/mcp-test-client.d.ts.map +1 -1
- package/errors/index.d.ts +8 -0
- package/errors/index.d.ts.map +1 -1
- package/esm/fixtures/index.mjs +2 -2
- package/esm/index.mjs +8 -8
- package/esm/matchers/index.mjs +1 -1
- package/esm/package.json +12 -6
- package/esm/perf/index.mjs +1 -1
- package/esm/setup.mjs +1 -1
- package/fixtures/index.js +2 -2
- package/index.d.ts +4 -1
- package/index.d.ts.map +1 -1
- package/index.js +9 -9
- package/jest-preset-unit.js +11 -0
- package/jest-preset.base.js +35 -0
- package/jest-preset.js +4 -34
- package/matchers/index.js +1 -1
- package/matchers/matcher-types.d.ts +40 -5
- package/matchers/matcher-types.d.ts.map +1 -1
- package/matchers/mcp-matchers.d.ts +5 -0
- package/matchers/mcp-matchers.d.ts.map +1 -1
- package/package.json +12 -6
- package/perf/index.js +4 -4
- package/platform/platform-client-info.d.ts.map +1 -1
- package/platform/platform-types.d.ts +1 -1
- package/platform/platform-types.d.ts.map +1 -1
- package/replay/replay-diff.d.ts +54 -0
- package/replay/replay-diff.d.ts.map +1 -0
- package/replay/replay-session.d.ts +29 -0
- package/replay/replay-session.d.ts.map +1 -0
- package/server/port-registry.d.ts +4 -0
- package/server/port-registry.d.ts.map +1 -1
- package/setup.js +1 -1
- package/transport/sse.transport.d.ts.map +1 -1
- package/transport/streamable-http.transport.d.ts.map +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Jest preset for unit tests, CommonJS projects included; the @frontmcp/testing README shows how to use it. */
|
|
2
|
+
|
|
3
|
+
const base = require('./jest-preset.base.js');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
...base,
|
|
7
|
+
|
|
8
|
+
testMatch: ['<rootDir>/**/*.spec.ts', '<rootDir>/**/*.spec.tsx'],
|
|
9
|
+
|
|
10
|
+
testPathIgnorePatterns: [...base.testPathIgnorePatterns, '\\.(e2e|perf|pw)\\.spec\\.tsx?$'],
|
|
11
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** What both @frontmcp/testing Jest presets share, so they cannot drift. */
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
|
|
6
|
+
// Covers `.js` too: ESM-only deps ship `.js`, and un-ignoring them in `transformIgnorePatterns` needs a matching transform.
|
|
7
|
+
transform: {
|
|
8
|
+
'^.+\\.[tj]sx?$': [
|
|
9
|
+
// The transform `frontmcp test` injects, resolved from here because @frontmcp/testing installs it
|
|
10
|
+
require.resolve('@swc/jest'),
|
|
11
|
+
{
|
|
12
|
+
jsc: {
|
|
13
|
+
target: 'es2022',
|
|
14
|
+
parser: { syntax: 'typescript', tsx: true, decorators: true, dynamicImport: true },
|
|
15
|
+
transform: { decoratorMetadata: true, legacyDecorator: true, react: { runtime: 'automatic' } },
|
|
16
|
+
keepClassNames: true,
|
|
17
|
+
externalHelpers: false,
|
|
18
|
+
loose: true,
|
|
19
|
+
},
|
|
20
|
+
module: { type: 'es6' },
|
|
21
|
+
sourceMaps: true,
|
|
22
|
+
swcrc: false,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
28
|
+
|
|
29
|
+
// The SDK's ESM-only runtime deps: `jose` (auth) and `@noble/*` (`@frontmcp/utils` crypto). The `.pnpm` skip keeps this correct under pnpm (issue #519).
|
|
30
|
+
transformIgnorePatterns: [
|
|
31
|
+
'node_modules[/\\\\](?!\\.pnpm[/\\\\])(?!(jose|@noble[/\\\\]hashes|@noble[/\\\\]ciphers)[/\\\\])',
|
|
32
|
+
],
|
|
33
|
+
|
|
34
|
+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
|
|
35
|
+
};
|
package/jest-preset.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @description Jest preset for @frontmcp/testing
|
|
4
4
|
*
|
|
5
5
|
* Mirrors the config `frontmcp test` injects (libs/cli/src/commands/dev/test.ts); a CLI test fails when they differ.
|
|
6
|
+
* For unit tests in a CommonJS project, use `@frontmcp/testing/jest-preset-unit`.
|
|
6
7
|
*
|
|
7
8
|
* Usage in jest.config.ts:
|
|
8
9
|
* ```typescript
|
|
@@ -13,33 +14,10 @@
|
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
// Use Node.js environment for E2E tests
|
|
18
|
-
testEnvironment: 'node',
|
|
19
|
-
|
|
20
|
-
// Covers `.js` too: ESM-only deps ship `.js`, and un-ignoring them in `transformIgnorePatterns` needs a matching transform.
|
|
21
|
-
transform: {
|
|
22
|
-
'^.+\\.[tj]sx?$': [
|
|
23
|
-
// The transform `frontmcp test` injects, resolved from here because @frontmcp/testing installs it
|
|
24
|
-
require.resolve('@swc/jest'),
|
|
25
|
-
{
|
|
26
|
-
jsc: {
|
|
27
|
-
target: 'es2022',
|
|
28
|
-
parser: { syntax: 'typescript', tsx: true, decorators: true, dynamicImport: true },
|
|
29
|
-
transform: { decoratorMetadata: true, legacyDecorator: true, react: { runtime: 'automatic' } },
|
|
30
|
-
keepClassNames: true,
|
|
31
|
-
externalHelpers: false,
|
|
32
|
-
loose: true,
|
|
33
|
-
},
|
|
34
|
-
module: { type: 'es6' },
|
|
35
|
-
sourceMaps: true,
|
|
36
|
-
swcrc: false,
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
},
|
|
17
|
+
const base = require('./jest-preset.base.js');
|
|
40
18
|
|
|
41
|
-
|
|
42
|
-
|
|
19
|
+
module.exports = {
|
|
20
|
+
...base,
|
|
43
21
|
|
|
44
22
|
testTimeout: 60000,
|
|
45
23
|
|
|
@@ -56,14 +34,6 @@ module.exports = {
|
|
|
56
34
|
'<rootDir>/e2e/**/*.e2e.spec.tsx',
|
|
57
35
|
],
|
|
58
36
|
|
|
59
|
-
// Transpile ESM-only deps (`@noble/*` for CodeCall); the `.pnpm` skip keeps this correct under pnpm (issue #519).
|
|
60
|
-
transformIgnorePatterns: [
|
|
61
|
-
'node_modules[/\\\\](?!\\.pnpm[/\\\\])(?!(jose|@noble[/\\\\]hashes|@noble[/\\\\]ciphers)[/\\\\])',
|
|
62
|
-
],
|
|
63
|
-
|
|
64
|
-
// Ignore patterns
|
|
65
|
-
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
|
|
66
|
-
|
|
67
37
|
// Coverage settings (optional, disabled by default for E2E)
|
|
68
38
|
collectCoverage: false,
|
|
69
39
|
|
package/matchers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var matchers_exports={};__export(matchers_exports,{mcpMatchers:()=>mcpMatchers});module.exports=__toCommonJS(matchers_exports);function getPlatformMimeType(platform){return"text/html;profile=mcp-app"}function getToolCallMetaPrefixes(platform){return["ui/"]}function getForbiddenMetaPrefixes(platform){return["openai/","frontmcp/"]}function escapeRegex(str){return str.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function extractUiHtml(received){if(typeof received==="string"){return received}const wrapper=received;const meta=wrapper?.raw?._meta||wrapper?._meta;if(meta&&typeof meta==="object"){const uiHtml=meta["ui/html"];if(typeof uiHtml==="string"){return uiHtml}}return void 0}function extractMeta(received){const wrapper=received;const meta=wrapper?.raw?._meta||wrapper?._meta;if(meta&&typeof meta==="object"){return meta}return void 0}var toHaveRenderedHtml=function(received){const html=extractUiHtml(received);const hasHtml=html!==void 0&&html.length>0;const isFallback=hasHtml&&html.includes("mdx-fallback");const pass=hasHtml&&!isFallback;return{pass,message:()=>{if(isFallback){return"Expected rendered HTML but got mdx-fallback (raw escaped content). MDX rendering may have failed."}if(!hasHtml){return"Expected _meta to have ui/html property with rendered HTML"}return"Expected result not to have rendered HTML"}}};var toContainHtmlElement=function(received,tag){const html=extractUiHtml(received);if(!html){return{pass:false,message:()=>`Expected to find <${tag}> element, but no HTML content found`}}const regex=new RegExp(`<${escapeRegex(tag)}[\\s>]`,"i");const pass=regex.test(html);return{pass,message:()=>pass?`Expected HTML not to contain <${tag}> element`:`Expected HTML to contain <${tag}> element`}};var toContainBoundValue=function(received,value){const html=extractUiHtml(received);if(!html){return{pass:false,message:()=>`Expected HTML to contain bound value "${value}", but no HTML content found`}}const stringValue=String(value);const pass=html.includes(stringValue);return{pass,message:()=>pass?`Expected HTML not to contain bound value "${stringValue}"`:`Expected HTML to contain bound value "${stringValue}"`}};var toBeXssSafe=function(received){const html=extractUiHtml(received);if(!html){return{pass:true,message:()=>"Expected HTML to be XSS unsafe (no HTML found)"}}const hasScript=/<script[\s>]/i.test(html);const hasOnHandler=/\son\w+\s*=/i.test(html);const hasJavascriptUri=/javascript:/i.test(html);const issues=[];if(hasScript)issues.push("<script> tag");if(hasOnHandler)issues.push("inline event handler (onclick, etc.)");if(hasJavascriptUri)issues.push("javascript: URI");const pass=!hasScript&&!hasOnHandler&&!hasJavascriptUri;return{pass,message:()=>pass?"Expected HTML not to be XSS safe":`Expected HTML to be XSS safe, but found: ${issues.join(", ")}`}};var toHaveWidgetMetadata=function(received){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>"Expected _meta to have widget metadata, but no _meta found"}}const hasUiHtml=Boolean(meta["ui/html"]);const hasMimeType=Boolean(meta["ui/mimeType"]);const hasUiObject=Boolean(meta["ui"]&&typeof meta["ui"]==="object");const pass=hasUiHtml||hasMimeType||hasUiObject;return{pass,message:()=>pass?"Expected result not to have widget metadata":"Expected _meta to have widget metadata (ui/html, ui/mimeType, or ui object)"}};var toHaveCssClass=function(received,className){const html=extractUiHtml(received);if(!html){return{pass:false,message:()=>`Expected HTML to have CSS class "${className}", but no HTML content found`}}const classRegex=new RegExp(`class(?:Name)?\\s*=\\s*["'][^"']*\\b${escapeRegex(className)}\\b[^"']*["']`,"i");const pass=classRegex.test(html);return{pass,message:()=>pass?`Expected HTML not to have CSS class "${className}"`:`Expected HTML to have CSS class "${className}"`}};var toNotContainRawContent=function(received,content){const html=extractUiHtml(received);if(!html){return{pass:true,message:()=>`Expected HTML to contain raw content "${content}", but no HTML found`}}const pass=!html.includes(content);return{pass,message:()=>pass?`Expected HTML to contain raw content "${content}"`:`Expected HTML not to contain raw content "${content}" (may indicate rendering failure)`}};var toHaveProperHtmlStructure=function(received){const html=extractUiHtml(received);if(!html){return{pass:false,message:()=>"Expected proper HTML structure, but no HTML content found"}}const hasEscapedTags=html.includes("<")&&html.includes(">");const hasHtmlTags=/<[a-z]/i.test(html);const pass=hasHtmlTags&&!hasEscapedTags;return{pass,message:()=>{if(hasEscapedTags){return"Expected proper HTML structure, but found escaped HTML entities - content may not have been rendered"}if(!hasHtmlTags){return"Expected proper HTML structure, but found no HTML tags"}return"Expected result not to have proper HTML structure"}}};var toHavePlatformMeta=function(received,platform){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta to have platform meta for "${platform}", but no _meta found`}}const expectedPrefixes=getToolCallMetaPrefixes(platform);const forbiddenPrefixes=getForbiddenMetaPrefixes(platform);const metaKeys=Object.keys(meta);const hasExpectedPrefix=metaKeys.some(key=>expectedPrefixes.some(prefix=>key.startsWith(prefix)));const forbiddenKeys=metaKeys.filter(key=>forbiddenPrefixes.some(prefix=>key.startsWith(prefix)));const pass=hasExpectedPrefix&&forbiddenKeys.length===0;return{pass,message:()=>{if(!hasExpectedPrefix){return`Expected _meta to have keys with prefixes [${expectedPrefixes.join(", ")}] for platform "${platform}", but found: [${metaKeys.join(", ")}]`}if(forbiddenKeys.length>0){return`Expected _meta NOT to have keys [${forbiddenKeys.join(", ")}] for platform "${platform}" (forbidden prefixes: [${forbiddenPrefixes.join(", ")}])`}return`Expected result not to have platform meta for "${platform}"`}}};var toHaveMetaKey=function(received,key){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta to have key "${key}", but no _meta found`}}const pass=key in meta;return{pass,message:()=>pass?`Expected _meta not to have key "${key}"`:`Expected _meta to have key "${key}"`}};var toHaveMetaValue=function(received,key,value){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta["${key}"] to equal ${JSON.stringify(value)}, but no _meta found`}}const actualValue=meta[key];const pass=JSON.stringify(actualValue)===JSON.stringify(value);return{pass,message:()=>pass?`Expected _meta["${key}"] not to equal ${JSON.stringify(value)}`:`Expected _meta["${key}"] to equal ${JSON.stringify(value)}, but got ${JSON.stringify(actualValue)}`}};var toNotHaveMetaKey=function(received,key){const meta=extractMeta(received);if(!meta){return{pass:true,message:()=>`Expected _meta to have key "${key}", but no _meta found`}}const pass=!(key in meta);return{pass,message:()=>pass?`Expected _meta to have key "${key}"`:`Expected _meta not to have key "${key}"`}};var toHaveOnlyNamespacedMeta=function(received,namespace){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta to have keys with namespace "${namespace}", but no _meta found`}}const metaKeys=Object.keys(meta);const wrongKeys=metaKeys.filter(key=>!key.startsWith(namespace));const pass=wrongKeys.length===0&&metaKeys.length>0;return{pass,message:()=>{if(metaKeys.length===0){return`Expected _meta to have keys with namespace "${namespace}", but _meta is empty`}if(wrongKeys.length>0){return`Expected _meta to ONLY have keys with namespace "${namespace}", but found: [${wrongKeys.join(", ")}]`}return`Expected _meta not to have only keys with namespace "${namespace}"`}}};var toHavePlatformMimeType=function(received,platform){const meta=extractMeta(received);const expectedMimeType=getPlatformMimeType(platform);if(!meta){return{pass:false,message:()=>`Expected _meta to have MIME type "${expectedMimeType}" for platform "${platform}", but no _meta found`}}const mimeTypeKey="ui/mimeType";const actualMimeType=meta[mimeTypeKey];const pass=actualMimeType===expectedMimeType;return{pass,message:()=>pass?`Expected _meta["${mimeTypeKey}"] not to be "${expectedMimeType}"`:`Expected _meta["${mimeTypeKey}"] to be "${expectedMimeType}" for platform "${platform}", but got "${actualMimeType}"`}};var toHavePlatformHtml=function(received,platform){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta to have platform HTML for "${platform}", but no _meta found`}}const htmlKey="ui/html";const html=meta[htmlKey];const pass=typeof html==="string"&&html.length>0;return{pass,message:()=>pass?`Expected _meta not to have platform HTML in "${htmlKey}"`:`Expected _meta["${htmlKey}"] to contain HTML for platform "${platform}", but ${html===void 0?"key not found":`got ${typeof html}`}`}};var uiMatchers={toHaveRenderedHtml,toContainHtmlElement,toContainBoundValue,toBeXssSafe,toHaveWidgetMetadata,toHaveCssClass,toNotContainRawContent,toHaveProperHtmlStructure,toHavePlatformMeta,toHaveMetaKey,toHaveMetaValue,toNotHaveMetaKey,toHaveOnlyNamespacedMeta,toHavePlatformMimeType,toHavePlatformHtml};var toContainTool=function(received,toolName){const tools=received;if(!Array.isArray(tools)){return{pass:false,message:()=>`Expected an array of tools, but received ${typeof received}`}}const pass=tools.some(t=>t.name===toolName);const availableTools=tools.map(t=>t.name).join(", ");return{pass,message:()=>pass?`Expected tools not to contain "${toolName}"`:`Expected tools to contain "${toolName}", but got: [${availableTools}]`}};var toBeSuccessful=function(received){const result=received;if(typeof result!=="object"||result===null||!("isSuccess"in result)){return{pass:false,message:()=>`Expected a result wrapper object with isSuccess property`}}const pass=result.isSuccess;return{pass,message:()=>pass?"Expected result not to be successful":`Expected result to be successful, but got error: ${result.error?.message??"unknown error"}`}};var toBeError=function(received,expectedCode){const result=received;if(typeof result!=="object"||result===null||!("isError"in result)){return{pass:false,message:()=>`Expected a result wrapper object with isError property`}}const receivedCode=typeof expectedCode==="string"?result.raw?._meta?.["code"]:result.error?.code;const codeMatches=expectedCode===void 0||receivedCode===expectedCode;const pass=result.isError&&codeMatches;return{pass,message:()=>{if(!result.isError){return"Expected result to be an error, but it was successful"}if(!codeMatches){return`Expected error code ${expectedCode}, but got ${String(receivedCode)}`}return"Expected result not to be an error"}}};var toHaveTextContent=function(received,expectedText){const result=received;if(typeof result!=="object"||result===null||!("text"in result)){return{pass:false,message:()=>`Expected a ToolResultWrapper or ResourceContentWrapper object with text method`}}const text=result.text();const hasText="hasTextContent"in result?result.hasTextContent():text!==void 0;let pass=hasText;if(pass&&expectedText!==void 0){pass=text?.includes(expectedText)??false}return{pass,message:()=>{if(!hasText){return"Expected result to have text content"}if(expectedText!==void 0&&!text?.includes(expectedText)){return`Expected text to contain "${expectedText}", but got: "${text}"`}return"Expected result not to have text content"}}};var toHaveImageContent=function(received){const result=received;if(typeof result!=="object"||result===null||!("hasImageContent"in result)){return{pass:false,message:()=>`Expected a ToolResultWrapper object with hasImageContent method`}}const pass=result.hasImageContent();return{pass,message:()=>pass?"Expected result not to have image content":"Expected result to have image content"}};var toHaveResourceContent=function(received){const result=received;if(typeof result!=="object"||result===null||!("hasResourceContent"in result)){return{pass:false,message:()=>`Expected a ToolResultWrapper object with hasResourceContent method`}}const pass=result.hasResourceContent();return{pass,message:()=>pass?"Expected result not to have resource content":"Expected result to have resource content"}};var toContainResource=function(received,uri){const resources=received;if(!Array.isArray(resources)){return{pass:false,message:()=>`Expected an array of resources, but received ${typeof received}`}}const pass=resources.some(r=>r.uri===uri);const availableUris=resources.map(r=>r.uri).join(", ");return{pass,message:()=>pass?`Expected resources not to contain "${uri}"`:`Expected resources to contain "${uri}", but got: [${availableUris}]`}};var toContainResourceTemplate=function(received,uriTemplate){const templates=received;if(!Array.isArray(templates)){return{pass:false,message:()=>`Expected an array of resource templates, but received ${typeof received}`}}const pass=templates.some(t=>t.uriTemplate===uriTemplate);const availableTemplates=templates.map(t=>t.uriTemplate).join(", ");return{pass,message:()=>pass?`Expected templates not to contain "${uriTemplate}"`:`Expected templates to contain "${uriTemplate}", but got: [${availableTemplates}]`}};var toHaveMimeType=function(received,mimeType){const result=received;if(typeof result!=="object"||result===null||!("hasMimeType"in result)){return{pass:false,message:()=>`Expected a ResourceContentWrapper object with hasMimeType method`}}const pass=result.hasMimeType(mimeType);const actualMimeType=result.mimeType();return{pass,message:()=>pass?`Expected content not to have MIME type "${mimeType}"`:`Expected MIME type "${mimeType}", but got "${actualMimeType}"`}};var toContainPrompt=function(received,name){const prompts=received;if(!Array.isArray(prompts)){return{pass:false,message:()=>`Expected an array of prompts, but received ${typeof received}`}}const pass=prompts.some(p=>p.name===name);const availablePrompts=prompts.map(p=>p.name).join(", ");return{pass,message:()=>pass?`Expected prompts not to contain "${name}"`:`Expected prompts to contain "${name}", but got: [${availablePrompts}]`}};var toHaveMessages=function(received,count){const result=received;if(typeof result!=="object"||result===null||!("messages"in result)){return{pass:false,message:()=>`Expected a PromptResultWrapper object with messages property`}}const actualCount=result.messages?.length??0;const pass=actualCount===count;return{pass,message:()=>pass?`Expected prompt not to have ${count} messages`:`Expected prompt to have ${count} messages, but got ${actualCount}`}};var toBeValidJsonRpc=function(received){const response=received;if(typeof response!=="object"||response===null){return{pass:false,message:()=>`Expected an object, but received ${typeof received}`}}const hasJsonRpc=response["jsonrpc"]==="2.0";const hasId="id"in response;const hasResult="result"in response;const hasError="error"in response;const hasExactlyOneResultOrError=(hasResult||hasError)&&!(hasResult&&hasError);const pass=hasJsonRpc&&hasId&&hasExactlyOneResultOrError;return{pass,message:()=>{if(pass){return"Expected response not to be valid JSON-RPC"}const issues=[];if(!hasJsonRpc)issues.push('missing or invalid "jsonrpc": "2.0"');if(!hasId)issues.push('missing "id" field');if(!hasExactlyOneResultOrError){if(!hasResult&&!hasError)issues.push('missing "result" or "error"');else issues.push('cannot have both "result" and "error"')}return`Expected valid JSON-RPC 2.0 response: ${issues.join(", ")}`}}};var toHaveResult=function(received){const response=received;if(typeof response!=="object"||response===null){return{pass:false,message:()=>`Expected an object, but received ${typeof received}`}}const pass="result"in response;return{pass,message:()=>pass?"Expected response not to have result":"Expected response to have result"}};var toHaveError=function(received){const response=received;if(typeof response!=="object"||response===null){return{pass:false,message:()=>`Expected an object, but received ${typeof received}`}}const pass="error"in response;return{pass,message:()=>pass?"Expected response not to have error":"Expected response to have error"}};var toHaveErrorCode=function(received,code){const response=received;if(typeof response!=="object"||response===null){return{pass:false,message:()=>`Expected an object, but received ${typeof received}`}}const actualCode=response.error?.code;const pass=actualCode===code;return{pass,message:()=>pass?`Expected response not to have error code ${code}`:`Expected error code ${code}, but got ${actualCode??"no error"}`}};var mcpMatchers={toContainTool,toBeSuccessful,toBeError,toHaveTextContent,toHaveImageContent,toHaveResourceContent,toContainResource,toContainResourceTemplate,toHaveMimeType,toContainPrompt,toHaveMessages,toBeValidJsonRpc,toHaveResult,toHaveError,toHaveErrorCode,...uiMatchers};0&&(module.exports={mcpMatchers});
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var matchers_exports={};__export(matchers_exports,{mcpMatchers:()=>mcpMatchers});module.exports=__toCommonJS(matchers_exports);var import_lazy_zod2=require("@frontmcp/lazy-zod");var import_utils2=require("@frontmcp/utils");var import_lazy_zod=require("@frontmcp/lazy-zod");var import_utils=require("@frontmcp/utils");var REPLAYED_METHODS=["tools/call","resources/read","prompts/get"];var recordedCallSchema=import_lazy_zod.z.object({v:import_lazy_zod.z.literal(1,{message:"is not a recording version this replay reads"}),method:import_lazy_zod.z.enum(REPLAYED_METHODS,{message:`must be one of ${REPLAYED_METHODS.join(", ")}`}),name:import_lazy_zod.z.string(),input:import_lazy_zod.z.record(import_lazy_zod.z.string(),import_lazy_zod.z.unknown()).optional(),answer:import_lazy_zod.z.unknown().optional(),error:import_lazy_zod.z.object({code:import_lazy_zod.z.union([import_lazy_zod.z.string(),import_lazy_zod.z.number()]),message:import_lazy_zod.z.string().optional()}).optional(),session:import_lazy_zod.z.string().optional(),client:import_lazy_zod.z.object({name:import_lazy_zod.z.string(),version:import_lazy_zod.z.string()}).optional()});var OUTCOME_LABELS={same:"same",changed:"changed","new-error":"new error","gone-error":"gone error"};function preview(value){if(value===void 0)return"(none)";const json=JSON.stringify(value);return json.length>80?`${json.slice(0,77)}...`:json}function formatReplayReport({file,calls,differences}){if(differences.length===0)return`Replayed ${calls.length} calls from ${file}: every call answered as recorded`;const lines=[`Replayed ${calls.length} calls from ${file}: ${differences.length} differ`];for(const call of differences){lines.push(` line ${call.line} ${call.method} ${call.name}: ${OUTCOME_LABELS[call.outcome]}`);if(call.error){const{code,message}=call.error;lines.push(message===void 0?` ${code}`:` ${code}: ${message}`)}for(const change of call.changes){lines.push(` ${change.path}: ${preview(change.recorded)} -> ${preview(change.replayed)}`)}}return lines.join("\n")}function getPlatformMimeType(platform){return"text/html;profile=mcp-app"}function getToolCallMetaPrefixes(platform){return["ui/"]}function getForbiddenMetaPrefixes(platform){return["openai/","frontmcp/"]}function escapeRegex(str){return str.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function extractUiHtml(received){if(typeof received==="string"){return received}const wrapper=received;const meta=wrapper?.raw?._meta||wrapper?._meta;if(meta&&typeof meta==="object"){const uiHtml=meta["ui/html"];if(typeof uiHtml==="string"){return uiHtml}}return void 0}function extractMeta(received){const wrapper=received;const meta=wrapper?.raw?._meta||wrapper?._meta;if(meta&&typeof meta==="object"){return meta}return void 0}var toHaveRenderedHtml=function(received){const html=extractUiHtml(received);const hasHtml=html!==void 0&&html.length>0;const isFallback=hasHtml&&html.includes("mdx-fallback");const pass=hasHtml&&!isFallback;return{pass,message:()=>{if(isFallback){return"Expected rendered HTML but got mdx-fallback (raw escaped content). MDX rendering may have failed."}if(!hasHtml){return"Expected _meta to have ui/html property with rendered HTML"}return"Expected result not to have rendered HTML"}}};var toContainHtmlElement=function(received,tag){const html=extractUiHtml(received);if(!html){return{pass:false,message:()=>`Expected to find <${tag}> element, but no HTML content found`}}const regex=new RegExp(`<${escapeRegex(tag)}[\\s>]`,"i");const pass=regex.test(html);return{pass,message:()=>pass?`Expected HTML not to contain <${tag}> element`:`Expected HTML to contain <${tag}> element`}};var toContainBoundValue=function(received,value){const html=extractUiHtml(received);if(!html){return{pass:false,message:()=>`Expected HTML to contain bound value "${value}", but no HTML content found`}}const stringValue=String(value);const pass=html.includes(stringValue);return{pass,message:()=>pass?`Expected HTML not to contain bound value "${stringValue}"`:`Expected HTML to contain bound value "${stringValue}"`}};var toBeXssSafe=function(received){const html=extractUiHtml(received);if(!html){return{pass:true,message:()=>"Expected HTML to be XSS unsafe (no HTML found)"}}const hasScript=/<script[\s>]/i.test(html);const hasOnHandler=/\son\w+\s*=/i.test(html);const hasJavascriptUri=/javascript:/i.test(html);const issues=[];if(hasScript)issues.push("<script> tag");if(hasOnHandler)issues.push("inline event handler (onclick, etc.)");if(hasJavascriptUri)issues.push("javascript: URI");const pass=!hasScript&&!hasOnHandler&&!hasJavascriptUri;return{pass,message:()=>pass?"Expected HTML not to be XSS safe":`Expected HTML to be XSS safe, but found: ${issues.join(", ")}`}};var toHaveWidgetMetadata=function(received){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>"Expected _meta to have widget metadata, but no _meta found"}}const hasUiHtml=Boolean(meta["ui/html"]);const hasMimeType=Boolean(meta["ui/mimeType"]);const hasUiObject=Boolean(meta["ui"]&&typeof meta["ui"]==="object");const pass=hasUiHtml||hasMimeType||hasUiObject;return{pass,message:()=>pass?"Expected result not to have widget metadata":"Expected _meta to have widget metadata (ui/html, ui/mimeType, or ui object)"}};var toHaveCssClass=function(received,className){const html=extractUiHtml(received);if(!html){return{pass:false,message:()=>`Expected HTML to have CSS class "${className}", but no HTML content found`}}const classRegex=new RegExp(`class(?:Name)?\\s*=\\s*["'][^"']*\\b${escapeRegex(className)}\\b[^"']*["']`,"i");const pass=classRegex.test(html);return{pass,message:()=>pass?`Expected HTML not to have CSS class "${className}"`:`Expected HTML to have CSS class "${className}"`}};var toNotContainRawContent=function(received,content){const html=extractUiHtml(received);if(!html){return{pass:true,message:()=>`Expected HTML to contain raw content "${content}", but no HTML found`}}const pass=!html.includes(content);return{pass,message:()=>pass?`Expected HTML to contain raw content "${content}"`:`Expected HTML not to contain raw content "${content}" (may indicate rendering failure)`}};var toHaveProperHtmlStructure=function(received){const html=extractUiHtml(received);if(!html){return{pass:false,message:()=>"Expected proper HTML structure, but no HTML content found"}}const hasEscapedTags=html.includes("<")&&html.includes(">");const hasHtmlTags=/<[a-z]/i.test(html);const pass=hasHtmlTags&&!hasEscapedTags;return{pass,message:()=>{if(hasEscapedTags){return"Expected proper HTML structure, but found escaped HTML entities - content may not have been rendered"}if(!hasHtmlTags){return"Expected proper HTML structure, but found no HTML tags"}return"Expected result not to have proper HTML structure"}}};var toHavePlatformMeta=function(received,platform){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta to have platform meta for "${platform}", but no _meta found`}}const expectedPrefixes=getToolCallMetaPrefixes(platform);const forbiddenPrefixes=getForbiddenMetaPrefixes(platform);const metaKeys=Object.keys(meta);const hasExpectedPrefix=metaKeys.some(key=>expectedPrefixes.some(prefix=>key.startsWith(prefix)));const forbiddenKeys=metaKeys.filter(key=>forbiddenPrefixes.some(prefix=>key.startsWith(prefix)));const pass=hasExpectedPrefix&&forbiddenKeys.length===0;return{pass,message:()=>{if(!hasExpectedPrefix){return`Expected _meta to have keys with prefixes [${expectedPrefixes.join(", ")}] for platform "${platform}", but found: [${metaKeys.join(", ")}]`}if(forbiddenKeys.length>0){return`Expected _meta NOT to have keys [${forbiddenKeys.join(", ")}] for platform "${platform}" (forbidden prefixes: [${forbiddenPrefixes.join(", ")}])`}return`Expected result not to have platform meta for "${platform}"`}}};var toHaveMetaKey=function(received,key){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta to have key "${key}", but no _meta found`}}const pass=key in meta;return{pass,message:()=>pass?`Expected _meta not to have key "${key}"`:`Expected _meta to have key "${key}"`}};var toHaveMetaValue=function(received,key,value){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta["${key}"] to equal ${JSON.stringify(value)}, but no _meta found`}}const actualValue=meta[key];const pass=JSON.stringify(actualValue)===JSON.stringify(value);return{pass,message:()=>pass?`Expected _meta["${key}"] not to equal ${JSON.stringify(value)}`:`Expected _meta["${key}"] to equal ${JSON.stringify(value)}, but got ${JSON.stringify(actualValue)}`}};var toNotHaveMetaKey=function(received,key){const meta=extractMeta(received);if(!meta){return{pass:true,message:()=>`Expected _meta to have key "${key}", but no _meta found`}}const pass=!(key in meta);return{pass,message:()=>pass?`Expected _meta to have key "${key}"`:`Expected _meta not to have key "${key}"`}};var toHaveOnlyNamespacedMeta=function(received,namespace){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta to have keys with namespace "${namespace}", but no _meta found`}}const metaKeys=Object.keys(meta);const wrongKeys=metaKeys.filter(key=>!key.startsWith(namespace));const pass=wrongKeys.length===0&&metaKeys.length>0;return{pass,message:()=>{if(metaKeys.length===0){return`Expected _meta to have keys with namespace "${namespace}", but _meta is empty`}if(wrongKeys.length>0){return`Expected _meta to ONLY have keys with namespace "${namespace}", but found: [${wrongKeys.join(", ")}]`}return`Expected _meta not to have only keys with namespace "${namespace}"`}}};var toHavePlatformMimeType=function(received,platform){const meta=extractMeta(received);const expectedMimeType=getPlatformMimeType(platform);if(!meta){return{pass:false,message:()=>`Expected _meta to have MIME type "${expectedMimeType}" for platform "${platform}", but no _meta found`}}const mimeTypeKey="ui/mimeType";const actualMimeType=meta[mimeTypeKey];const pass=actualMimeType===expectedMimeType;return{pass,message:()=>pass?`Expected _meta["${mimeTypeKey}"] not to be "${expectedMimeType}"`:`Expected _meta["${mimeTypeKey}"] to be "${expectedMimeType}" for platform "${platform}", but got "${actualMimeType}"`}};var toHavePlatformHtml=function(received,platform){const meta=extractMeta(received);if(!meta){return{pass:false,message:()=>`Expected _meta to have platform HTML for "${platform}", but no _meta found`}}const htmlKey="ui/html";const html=meta[htmlKey];const pass=typeof html==="string"&&html.length>0;return{pass,message:()=>pass?`Expected _meta not to have platform HTML in "${htmlKey}"`:`Expected _meta["${htmlKey}"] to contain HTML for platform "${platform}", but ${html===void 0?"key not found":`got ${typeof html}`}`}};var uiMatchers={toHaveRenderedHtml,toContainHtmlElement,toContainBoundValue,toBeXssSafe,toHaveWidgetMetadata,toHaveCssClass,toNotContainRawContent,toHaveProperHtmlStructure,toHavePlatformMeta,toHaveMetaKey,toHaveMetaValue,toNotHaveMetaKey,toHaveOnlyNamespacedMeta,toHavePlatformMimeType,toHavePlatformHtml};var toContainTool=function(received,toolName){const tools=received;if(!Array.isArray(tools)){return{pass:false,message:()=>`Expected an array of tools, but received ${typeof received}`}}const pass=tools.some(t=>t.name===toolName);const availableTools=tools.map(t=>t.name).join(", ");return{pass,message:()=>pass?`Expected tools not to contain "${toolName}"`:`Expected tools to contain "${toolName}", but got: [${availableTools}]`}};var toBeSuccessful=function(received){const result=received;if(typeof result!=="object"||result===null||!("isSuccess"in result)){return{pass:false,message:()=>`Expected a result wrapper object with isSuccess property`}}const pass=result.isSuccess;return{pass,message:()=>pass?"Expected result not to be successful":`Expected result to be successful, but got error: ${result.error?.message??"unknown error"}`}};var toBeError=function(received,expectedCode){const result=received;if(typeof result!=="object"||result===null||!("isError"in result)){return{pass:false,message:()=>`Expected a result wrapper object with isError property`}}const receivedCode=typeof expectedCode==="string"?result.raw?._meta?.["code"]:result.error?.code;const codeMatches=expectedCode===void 0||receivedCode===expectedCode;const pass=result.isError&&codeMatches;return{pass,message:()=>{if(!result.isError){return"Expected result to be an error, but it was successful"}if(!codeMatches){return`Expected error code ${expectedCode}, but got ${String(receivedCode)}`}return"Expected result not to be an error"}}};var toHaveTextContent=function(received,expectedText){const result=received;if(typeof result!=="object"||result===null||!("text"in result)){return{pass:false,message:()=>`Expected a ToolResultWrapper or ResourceContentWrapper object with text method`}}const text=result.text();const hasText="hasTextContent"in result?result.hasTextContent():text!==void 0;let pass=hasText;if(pass&&expectedText!==void 0){pass=text?.includes(expectedText)??false}return{pass,message:()=>{if(!hasText){return"Expected result to have text content"}if(expectedText!==void 0&&!text?.includes(expectedText)){return`Expected text to contain "${expectedText}", but got: "${text}"`}return"Expected result not to have text content"}}};var toHaveImageContent=function(received){const result=received;if(typeof result!=="object"||result===null||!("hasImageContent"in result)){return{pass:false,message:()=>`Expected a ToolResultWrapper object with hasImageContent method`}}const pass=result.hasImageContent();return{pass,message:()=>pass?"Expected result not to have image content":"Expected result to have image content"}};var toHaveResourceContent=function(received){const result=received;if(typeof result!=="object"||result===null||!("hasResourceContent"in result)){return{pass:false,message:()=>`Expected a ToolResultWrapper object with hasResourceContent method`}}const pass=result.hasResourceContent();return{pass,message:()=>pass?"Expected result not to have resource content":"Expected result to have resource content"}};var toPassOutputSchemaWhole=function(received,outputSchema){const schema=outputSchema instanceof import_lazy_zod2.z.ZodType?outputSchema:import_lazy_zod2.z.object(outputSchema);if((0,import_lazy_zod2.hasTransform)(schema)){return{pass:false,message:()=>"toPassOutputSchemaWhole cannot compare keys through a transform (.transform(), z.preprocess(), .pipe()): assert on the parsed answer instead"}}const parsed=schema.safeParse(received);if(!parsed.success){const[firstIssue]=parsed.error.issues;const location=firstIssue?.path.length?` at ${firstIssue.path.join(".")}`:"";return{pass:false,message:()=>`Expected the answer to pass its output schema whole, but it does not match its output schema${location}: ${firstIssue?.message}`}}const droppedKeys=(0,import_utils2.findDroppedKeys)(received,parsed.data);const pass=droppedKeys.length===0;return{pass,message:()=>pass?"Expected the answer not to pass its output schema whole":`Expected the answer to pass its output schema whole, but parsing drops keys it does not declare: ${droppedKeys.join(", ")}`}};var toContainResource=function(received,uri){const resources=received;if(!Array.isArray(resources)){return{pass:false,message:()=>`Expected an array of resources, but received ${typeof received}`}}const pass=resources.some(r=>r.uri===uri);const availableUris=resources.map(r=>r.uri).join(", ");return{pass,message:()=>pass?`Expected resources not to contain "${uri}"`:`Expected resources to contain "${uri}", but got: [${availableUris}]`}};var toContainResourceTemplate=function(received,uriTemplate){const templates=received;if(!Array.isArray(templates)){return{pass:false,message:()=>`Expected an array of resource templates, but received ${typeof received}`}}const pass=templates.some(t=>t.uriTemplate===uriTemplate);const availableTemplates=templates.map(t=>t.uriTemplate).join(", ");return{pass,message:()=>pass?`Expected templates not to contain "${uriTemplate}"`:`Expected templates to contain "${uriTemplate}", but got: [${availableTemplates}]`}};var toHaveMimeType=function(received,mimeType){const result=received;if(typeof result!=="object"||result===null||!("hasMimeType"in result)){return{pass:false,message:()=>`Expected a ResourceContentWrapper object with hasMimeType method`}}const pass=result.hasMimeType(mimeType);const actualMimeType=result.mimeType();return{pass,message:()=>pass?`Expected content not to have MIME type "${mimeType}"`:`Expected MIME type "${mimeType}", but got "${actualMimeType}"`}};var toContainPrompt=function(received,name){const prompts=received;if(!Array.isArray(prompts)){return{pass:false,message:()=>`Expected an array of prompts, but received ${typeof received}`}}const pass=prompts.some(p=>p.name===name);const availablePrompts=prompts.map(p=>p.name).join(", ");return{pass,message:()=>pass?`Expected prompts not to contain "${name}"`:`Expected prompts to contain "${name}", but got: [${availablePrompts}]`}};var toHaveMessages=function(received,count){const result=received;if(typeof result!=="object"||result===null||!("messages"in result)){return{pass:false,message:()=>`Expected a PromptResultWrapper object with messages property`}}const actualCount=result.messages?.length??0;const pass=actualCount===count;return{pass,message:()=>pass?`Expected prompt not to have ${count} messages`:`Expected prompt to have ${count} messages, but got ${actualCount}`}};var toBeValidJsonRpc=function(received){const response=received;if(typeof response!=="object"||response===null){return{pass:false,message:()=>`Expected an object, but received ${typeof received}`}}const hasJsonRpc=response["jsonrpc"]==="2.0";const hasId="id"in response;const hasResult="result"in response;const hasError="error"in response;const hasExactlyOneResultOrError=(hasResult||hasError)&&!(hasResult&&hasError);const pass=hasJsonRpc&&hasId&&hasExactlyOneResultOrError;return{pass,message:()=>{if(pass){return"Expected response not to be valid JSON-RPC"}const issues=[];if(!hasJsonRpc)issues.push('missing or invalid "jsonrpc": "2.0"');if(!hasId)issues.push('missing "id" field');if(!hasExactlyOneResultOrError){if(!hasResult&&!hasError)issues.push('missing "result" or "error"');else issues.push('cannot have both "result" and "error"')}return`Expected valid JSON-RPC 2.0 response: ${issues.join(", ")}`}}};var toHaveResult=function(received){const response=received;if(typeof response!=="object"||response===null){return{pass:false,message:()=>`Expected an object, but received ${typeof received}`}}const pass="result"in response;return{pass,message:()=>pass?"Expected response not to have result":"Expected response to have result"}};var toHaveError=function(received){const response=received;if(typeof response!=="object"||response===null){return{pass:false,message:()=>`Expected an object, but received ${typeof received}`}}const pass="error"in response;return{pass,message:()=>pass?"Expected response not to have error":"Expected response to have error"}};var toHaveErrorCode=function(received,code){const response=received;if(typeof response!=="object"||response===null){return{pass:false,message:()=>`Expected an object, but received ${typeof received}`}}const actualCode=response.error?.code;const pass=actualCode===code;return{pass,message:()=>pass?`Expected response not to have error code ${code}`:`Expected error code ${code}, but got ${actualCode??"no error"}`}};function isReplayReport(value){const report=value;return typeof report?.file==="string"&&Array.isArray(report.calls)&&Array.isArray(report.differences)}var toMatchRecording=function(received){if(!isReplayReport(received)){return{pass:false,message:()=>"Expected the report replaySession() returns"}}const pass=received.differences.length===0;return{pass,message:()=>formatReplayReport(received)}};var mcpMatchers={toContainTool,toBeSuccessful,toBeError,toHaveTextContent,toHaveImageContent,toHaveResourceContent,toPassOutputSchemaWhole,toContainResource,toContainResourceTemplate,toHaveMimeType,toContainPrompt,toHaveMessages,toBeValidJsonRpc,toHaveResult,toHaveError,toHaveErrorCode,toMatchRecording,...uiMatchers};0&&(module.exports={mcpMatchers});
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* This file extends Jest's expect interface with MCP-specific matchers.
|
|
6
6
|
* Import this file or ensure it's included in your tsconfig to get type checking.
|
|
7
7
|
*/
|
|
8
|
+
import type { ZodRawShape, ZodType } from '@frontmcp/lazy-zod';
|
|
8
9
|
/**
|
|
9
|
-
* Custom MCP matchers for Jest
|
|
10
|
+
* Custom MCP matchers for Jest: tool, resource, prompt and protocol results
|
|
10
11
|
*/
|
|
11
|
-
export interface
|
|
12
|
+
export interface McpResultMatchers<R = unknown> {
|
|
12
13
|
/**
|
|
13
14
|
* Check if tools array contains a tool with the given name
|
|
14
15
|
* @param toolName - The name of the tool to find
|
|
@@ -75,6 +76,20 @@ export interface McpMatchers<R = unknown> {
|
|
|
75
76
|
* ```
|
|
76
77
|
*/
|
|
77
78
|
toHaveResourceContent(): R;
|
|
79
|
+
/**
|
|
80
|
+
* Check that a tool's answer passes its output schema whole: it matches the schema, and parsing
|
|
81
|
+
* drops no key the schema does not declare. The failure message names the undeclared keys, which
|
|
82
|
+
* the server would strip, warn about or refuse, per its `output.undeclaredKeys` policy. A schema with
|
|
83
|
+
* a transform (`.transform()`, `z.preprocess()`, `.pipe()`) cannot be compared key by key and fails.
|
|
84
|
+
* @param outputSchema - The tool's `outputSchema`: a Zod schema or a raw shape
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const answer = await tool.execute({ id: 'INV-1' });
|
|
89
|
+
* expect(answer).toPassOutputSchemaWhole(invoiceOutputSchema);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
toPassOutputSchemaWhole(outputSchema: ZodType | ZodRawShape): R;
|
|
78
93
|
/**
|
|
79
94
|
* Check if resources array contains a resource with the given URI
|
|
80
95
|
* @param uri - The URI of the resource to find
|
|
@@ -171,6 +186,21 @@ export interface McpMatchers<R = unknown> {
|
|
|
171
186
|
* ```
|
|
172
187
|
*/
|
|
173
188
|
toHaveErrorCode(code: number): R;
|
|
189
|
+
/**
|
|
190
|
+
* Check that every call of a replay answered as recorded; the failure names each call that differs, and how
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const report = await replaySession('calls.jsonl', server, { ignore: ['**.generatedAt'] });
|
|
195
|
+
* expect(report).toMatchRecording();
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
toMatchRecording(): R;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Custom MCP matchers for Jest: rendered tool UI
|
|
202
|
+
*/
|
|
203
|
+
export interface McpUiMatchers<R = unknown> {
|
|
174
204
|
/**
|
|
175
205
|
* Check if tool result has rendered HTML in _meta['ui/html'].
|
|
176
206
|
* Fails if the HTML is the mdx-fallback (escaped raw content).
|
|
@@ -254,13 +284,18 @@ export interface McpMatchers<R = unknown> {
|
|
|
254
284
|
*/
|
|
255
285
|
toHaveProperHtmlStructure(): R;
|
|
256
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Custom MCP matchers for Jest
|
|
289
|
+
*/
|
|
290
|
+
export interface McpMatchers<R = unknown> extends McpResultMatchers<R>, McpUiMatchers<R> {
|
|
291
|
+
}
|
|
257
292
|
declare global {
|
|
258
293
|
namespace jest {
|
|
259
|
-
interface Matchers<R> extends
|
|
294
|
+
interface Matchers<R> extends McpResultMatchers<R>, McpUiMatchers<R> {
|
|
260
295
|
}
|
|
261
|
-
interface Expect extends
|
|
296
|
+
interface Expect extends McpResultMatchers<void>, McpUiMatchers<void> {
|
|
262
297
|
}
|
|
263
|
-
interface InverseAsymmetricMatchers extends
|
|
298
|
+
interface InverseAsymmetricMatchers extends McpResultMatchers<void>, McpUiMatchers<void> {
|
|
264
299
|
}
|
|
265
300
|
}
|
|
266
301
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matcher-types.d.ts","sourceRoot":"","sources":["../../src/matchers/matcher-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"matcher-types.d.ts","sourceRoot":"","sources":["../../src/matchers/matcher-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,OAAO;IAK5C;;;;;;;;;OASG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC;IAEnC;;;;;;;;OAQG;IACH,cAAc,IAAI,CAAC,CAAC;IAEpB;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC;IAE7C;;;;;;;;;;OAUG;IACH,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;IAE5C;;;;;;;;OAQG;IACH,kBAAkB,IAAI,CAAC,CAAC;IAExB;;;;;;;;OAQG;IACH,qBAAqB,IAAI,CAAC,CAAC;IAE3B;;;;;;;;;;;;OAYG;IACH,uBAAuB,CAAC,YAAY,EAAE,OAAO,GAAG,WAAW,GAAG,CAAC,CAAC;IAMhE;;;;;;;;;OASG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;IAElC;;;;;;;;;OASG;IACH,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,CAAC;IAElD;;;;;;;;;OASG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC;IAMpC;;;;;;;;;OASG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;IAEjC;;;;;;;;;OASG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;IAMjC;;;;;;;;OAQG;IACH,gBAAgB,IAAI,CAAC,CAAC;IAEtB;;;;;;;;OAQG;IACH,YAAY,IAAI,CAAC,CAAC;IAElB;;;;;;;;OAQG;IACH,WAAW,IAAI,CAAC,CAAC;IAEjB;;;;;;;;;OASG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;IAMjC;;;;;;;;OAQG;IACH,gBAAgB,IAAI,CAAC,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IAKxC;;;;;;;;;OASG;IACH,kBAAkB,IAAI,CAAC,CAAC;IAExB;;;;;;;;;OASG;IACH,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;IAErC;;;;;;;;;;OAUG;IACH,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC;IAE/C;;;;;;;OAOG;IACH,WAAW,IAAI,CAAC,CAAC;IAEjB;;;;;;;OAOG;IACH,oBAAoB,IAAI,CAAC,CAAC;IAE1B;;;;;;;;OAQG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,CAAC;IAErC;;;;;;;;;OASG;IACH,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC;IAE3C;;;;;;;OAOG;IACH,yBAAyB,IAAI,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,iBAAiB,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;CAAG;AAQ3F,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,IAAI,CAAC;QAEb,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,iBAAiB,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;SAAG;QAGvE,UAAU,MAAO,SAAQ,iBAAiB,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC;SAAG;QAGxE,UAAU,yBAA0B,SAAQ,iBAAiB,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC;SAAG;KAC5F;CACF;AAID,OAAO,EAAE,CAAC"}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
import type { MatcherFunction } from 'expect';
|
|
20
|
+
import { type ZodType } from '@frontmcp/lazy-zod';
|
|
20
21
|
/**
|
|
21
22
|
* All MCP matchers as an object for expect.extend()
|
|
22
23
|
*/
|
|
@@ -42,6 +43,9 @@ export declare const mcpMatchers: {
|
|
|
42
43
|
toHaveTextContent: MatcherFunction<[expectedText?: string | undefined]>;
|
|
43
44
|
toHaveImageContent: MatcherFunction<[]>;
|
|
44
45
|
toHaveResourceContent: MatcherFunction<[]>;
|
|
46
|
+
toPassOutputSchemaWhole: MatcherFunction<[outputSchema: ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> | Readonly<{
|
|
47
|
+
[k: string]: import("zod/v4/core").$ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>;
|
|
48
|
+
}>]>;
|
|
45
49
|
toContainResource: MatcherFunction<[uri: string]>;
|
|
46
50
|
toContainResourceTemplate: MatcherFunction<[uriTemplate: string]>;
|
|
47
51
|
toHaveMimeType: MatcherFunction<[mimeType: string]>;
|
|
@@ -51,5 +55,6 @@ export declare const mcpMatchers: {
|
|
|
51
55
|
toHaveResult: MatcherFunction<[]>;
|
|
52
56
|
toHaveError: MatcherFunction<[]>;
|
|
53
57
|
toHaveErrorCode: MatcherFunction<[code: number]>;
|
|
58
|
+
toMatchRecording: MatcherFunction<[]>;
|
|
54
59
|
};
|
|
55
60
|
//# sourceMappingURL=mcp-matchers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-matchers.d.ts","sourceRoot":"","sources":["../../src/matchers/mcp-matchers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-matchers.d.ts","sourceRoot":"","sources":["../../src/matchers/mcp-matchers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAqC,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AA4erF;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontmcp/testing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0-rc.1",
|
|
4
4
|
"description": "End-to-end testing for FrontMCP servers: Jest fixtures with a connected MCP client, MCP matchers, JWT and OAuth mocks, and HTTP mocking",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"homepage": "https://frontmcp.dev/reference/testing",
|
|
@@ -54,6 +54,12 @@
|
|
|
54
54
|
"./jest-preset": {
|
|
55
55
|
"default": "./jest-preset.js"
|
|
56
56
|
},
|
|
57
|
+
"./jest-preset-unit": {
|
|
58
|
+
"default": "./jest-preset-unit.js"
|
|
59
|
+
},
|
|
60
|
+
"./jest-preset-unit/jest-preset": {
|
|
61
|
+
"default": "./jest-preset-unit.js"
|
|
62
|
+
},
|
|
57
63
|
"./fixtures": {
|
|
58
64
|
"require": {
|
|
59
65
|
"types": "./fixtures/index.d.ts",
|
|
@@ -87,9 +93,9 @@
|
|
|
87
93
|
"./esm": null
|
|
88
94
|
},
|
|
89
95
|
"peerDependencies": {
|
|
90
|
-
"@frontmcp/lazy-zod": "1.
|
|
91
|
-
"@frontmcp/sdk": "1.
|
|
92
|
-
"@frontmcp/ui": "1.
|
|
96
|
+
"@frontmcp/lazy-zod": "1.11.0-rc.1",
|
|
97
|
+
"@frontmcp/sdk": "1.11.0-rc.1",
|
|
98
|
+
"@frontmcp/ui": "1.11.0-rc.1",
|
|
93
99
|
"@jest/globals": "^29.0.0 || ^30.0.0",
|
|
94
100
|
"@playwright/test": "^1.40.0",
|
|
95
101
|
"jest": "^29.0.0 || ^30.0.0"
|
|
@@ -112,8 +118,8 @@
|
|
|
112
118
|
"node": ">=24.0.0"
|
|
113
119
|
},
|
|
114
120
|
"dependencies": {
|
|
115
|
-
"@frontmcp/protocol": "1.
|
|
116
|
-
"@frontmcp/utils": "1.
|
|
121
|
+
"@frontmcp/protocol": "1.11.0-rc.1",
|
|
122
|
+
"@frontmcp/utils": "1.11.0-rc.1",
|
|
117
123
|
"@swc/core": "~1.15.41",
|
|
118
124
|
"@swc/jest": "~0.2.38",
|
|
119
125
|
"jose": "^6.0.11",
|