@frontmcp/testing 0.6.1 → 0.6.2

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.
Files changed (142) hide show
  1. package/esm/fixtures/index.mjs +2377 -0
  2. package/esm/index.mjs +4768 -0
  3. package/esm/matchers/index.mjs +646 -0
  4. package/esm/package.json +127 -0
  5. package/esm/playwright/index.mjs +19 -0
  6. package/esm/setup.mjs +680 -0
  7. package/fixtures/index.js +2418 -0
  8. package/index.js +4866 -0
  9. package/jest-preset.js +3 -3
  10. package/matchers/index.js +673 -0
  11. package/package.json +51 -23
  12. package/playwright/index.js +46 -0
  13. package/setup.js +651 -0
  14. package/src/assertions/index.js +0 -18
  15. package/src/assertions/index.js.map +0 -1
  16. package/src/assertions/mcp-assertions.js +0 -220
  17. package/src/assertions/mcp-assertions.js.map +0 -1
  18. package/src/auth/auth-headers.js +0 -62
  19. package/src/auth/auth-headers.js.map +0 -1
  20. package/src/auth/index.js +0 -15
  21. package/src/auth/index.js.map +0 -1
  22. package/src/auth/mock-api-server.js +0 -200
  23. package/src/auth/mock-api-server.js.map +0 -1
  24. package/src/auth/mock-oauth-server.js +0 -253
  25. package/src/auth/mock-oauth-server.js.map +0 -1
  26. package/src/auth/token-factory.js +0 -181
  27. package/src/auth/token-factory.js.map +0 -1
  28. package/src/auth/user-fixtures.js +0 -92
  29. package/src/auth/user-fixtures.js.map +0 -1
  30. package/src/client/index.js +0 -12
  31. package/src/client/index.js.map +0 -1
  32. package/src/client/mcp-test-client.builder.js +0 -163
  33. package/src/client/mcp-test-client.builder.js.map +0 -1
  34. package/src/client/mcp-test-client.js +0 -937
  35. package/src/client/mcp-test-client.js.map +0 -1
  36. package/src/client/mcp-test-client.types.js +0 -16
  37. package/src/client/mcp-test-client.types.js.map +0 -1
  38. package/src/errors/index.js +0 -85
  39. package/src/errors/index.js.map +0 -1
  40. package/src/example-tools/index.js +0 -40
  41. package/src/example-tools/index.js.map +0 -1
  42. package/src/example-tools/tool-configs.js +0 -222
  43. package/src/example-tools/tool-configs.js.map +0 -1
  44. package/src/expect.js +0 -31
  45. package/src/expect.js.map +0 -1
  46. package/src/fixtures/fixture-types.js +0 -7
  47. package/src/fixtures/fixture-types.js.map +0 -1
  48. package/src/fixtures/index.js +0 -16
  49. package/src/fixtures/index.js.map +0 -1
  50. package/src/fixtures/test-fixture.js +0 -311
  51. package/src/fixtures/test-fixture.js.map +0 -1
  52. package/src/http-mock/http-mock.js +0 -544
  53. package/src/http-mock/http-mock.js.map +0 -1
  54. package/src/http-mock/http-mock.types.js +0 -10
  55. package/src/http-mock/http-mock.types.js.map +0 -1
  56. package/src/http-mock/index.js +0 -11
  57. package/src/http-mock/index.js.map +0 -1
  58. package/src/index.js +0 -167
  59. package/src/index.js.map +0 -1
  60. package/src/interceptor/index.js +0 -15
  61. package/src/interceptor/index.js.map +0 -1
  62. package/src/interceptor/interceptor-chain.js +0 -207
  63. package/src/interceptor/interceptor-chain.js.map +0 -1
  64. package/src/interceptor/interceptor.types.js +0 -7
  65. package/src/interceptor/interceptor.types.js.map +0 -1
  66. package/src/interceptor/mock-registry.js +0 -189
  67. package/src/interceptor/mock-registry.js.map +0 -1
  68. package/src/matchers/index.js +0 -12
  69. package/src/matchers/index.js.map +0 -1
  70. package/src/matchers/matcher-types.js +0 -10
  71. package/src/matchers/matcher-types.js.map +0 -1
  72. package/src/matchers/mcp-matchers.js +0 -395
  73. package/src/matchers/mcp-matchers.js.map +0 -1
  74. package/src/platform/index.js +0 -47
  75. package/src/platform/index.js.map +0 -1
  76. package/src/platform/platform-client-info.js +0 -155
  77. package/src/platform/platform-client-info.js.map +0 -1
  78. package/src/platform/platform-types.js +0 -110
  79. package/src/platform/platform-types.js.map +0 -1
  80. package/src/playwright/index.js +0 -49
  81. package/src/playwright/index.js.map +0 -1
  82. package/src/server/index.js +0 -10
  83. package/src/server/index.js.map +0 -1
  84. package/src/server/test-server.js +0 -341
  85. package/src/server/test-server.js.map +0 -1
  86. package/src/setup.js +0 -30
  87. package/src/setup.js.map +0 -1
  88. package/src/transport/index.js +0 -10
  89. package/src/transport/index.js.map +0 -1
  90. package/src/transport/streamable-http.transport.js +0 -438
  91. package/src/transport/streamable-http.transport.js.map +0 -1
  92. package/src/transport/transport.interface.js +0 -7
  93. package/src/transport/transport.interface.js.map +0 -1
  94. package/src/ui/index.js +0 -23
  95. package/src/ui/index.js.map +0 -1
  96. package/src/ui/ui-assertions.js +0 -367
  97. package/src/ui/ui-assertions.js.map +0 -1
  98. package/src/ui/ui-matchers.js +0 -493
  99. package/src/ui/ui-matchers.js.map +0 -1
  100. /package/{src/assertions → assertions}/index.d.ts +0 -0
  101. /package/{src/assertions → assertions}/mcp-assertions.d.ts +0 -0
  102. /package/{src/auth → auth}/auth-headers.d.ts +0 -0
  103. /package/{src/auth → auth}/index.d.ts +0 -0
  104. /package/{src/auth → auth}/mock-api-server.d.ts +0 -0
  105. /package/{src/auth → auth}/mock-oauth-server.d.ts +0 -0
  106. /package/{src/auth → auth}/token-factory.d.ts +0 -0
  107. /package/{src/auth → auth}/user-fixtures.d.ts +0 -0
  108. /package/{src/client → client}/index.d.ts +0 -0
  109. /package/{src/client → client}/mcp-test-client.builder.d.ts +0 -0
  110. /package/{src/client → client}/mcp-test-client.d.ts +0 -0
  111. /package/{src/client → client}/mcp-test-client.types.d.ts +0 -0
  112. /package/{src/errors → errors}/index.d.ts +0 -0
  113. /package/{src/example-tools → example-tools}/index.d.ts +0 -0
  114. /package/{src/example-tools → example-tools}/tool-configs.d.ts +0 -0
  115. /package/{src/expect.d.ts → expect.d.ts} +0 -0
  116. /package/{src/fixtures → fixtures}/fixture-types.d.ts +0 -0
  117. /package/{src/fixtures → fixtures}/index.d.ts +0 -0
  118. /package/{src/fixtures → fixtures}/test-fixture.d.ts +0 -0
  119. /package/{src/http-mock → http-mock}/http-mock.d.ts +0 -0
  120. /package/{src/http-mock → http-mock}/http-mock.types.d.ts +0 -0
  121. /package/{src/http-mock → http-mock}/index.d.ts +0 -0
  122. /package/{src/index.d.ts → index.d.ts} +0 -0
  123. /package/{src/interceptor → interceptor}/index.d.ts +0 -0
  124. /package/{src/interceptor → interceptor}/interceptor-chain.d.ts +0 -0
  125. /package/{src/interceptor → interceptor}/interceptor.types.d.ts +0 -0
  126. /package/{src/interceptor → interceptor}/mock-registry.d.ts +0 -0
  127. /package/{src/matchers → matchers}/index.d.ts +0 -0
  128. /package/{src/matchers → matchers}/matcher-types.d.ts +0 -0
  129. /package/{src/matchers → matchers}/mcp-matchers.d.ts +0 -0
  130. /package/{src/platform → platform}/index.d.ts +0 -0
  131. /package/{src/platform → platform}/platform-client-info.d.ts +0 -0
  132. /package/{src/platform → platform}/platform-types.d.ts +0 -0
  133. /package/{src/playwright → playwright}/index.d.ts +0 -0
  134. /package/{src/server → server}/index.d.ts +0 -0
  135. /package/{src/server → server}/test-server.d.ts +0 -0
  136. /package/{src/setup.d.ts → setup.d.ts} +0 -0
  137. /package/{src/transport → transport}/index.d.ts +0 -0
  138. /package/{src/transport → transport}/streamable-http.transport.d.ts +0 -0
  139. /package/{src/transport → transport}/transport.interface.d.ts +0 -0
  140. /package/{src/ui → ui}/index.d.ts +0 -0
  141. /package/{src/ui → ui}/ui-assertions.d.ts +0 -0
  142. /package/{src/ui → ui}/ui-matchers.d.ts +0 -0
@@ -0,0 +1,646 @@
1
+ // libs/testing/src/platform/platform-types.ts
2
+ function getPlatformMimeType(platform) {
3
+ return platform === "openai" ? "text/html+skybridge" : "text/html+mcp";
4
+ }
5
+ function getToolCallMetaPrefixes(platform) {
6
+ switch (platform) {
7
+ case "openai":
8
+ return ["openai/"];
9
+ case "ext-apps":
10
+ return ["ui/"];
11
+ default:
12
+ return ["frontmcp/", "ui/"];
13
+ }
14
+ }
15
+ function getForbiddenMetaPrefixes(platform) {
16
+ switch (platform) {
17
+ case "openai":
18
+ return ["ui/", "frontmcp/"];
19
+ case "ext-apps":
20
+ return ["openai/", "frontmcp/"];
21
+ default:
22
+ return ["openai/"];
23
+ }
24
+ }
25
+
26
+ // libs/testing/src/ui/ui-matchers.ts
27
+ function escapeRegex(str) {
28
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
29
+ }
30
+ function extractUiHtml(received) {
31
+ if (typeof received === "string") {
32
+ return received;
33
+ }
34
+ const wrapper = received;
35
+ const meta = wrapper?.raw?._meta || wrapper?._meta;
36
+ if (meta && typeof meta === "object") {
37
+ const uiHtml = meta["ui/html"];
38
+ if (typeof uiHtml === "string") {
39
+ return uiHtml;
40
+ }
41
+ }
42
+ return void 0;
43
+ }
44
+ function extractMeta(received) {
45
+ const wrapper = received;
46
+ const meta = wrapper?.raw?._meta || wrapper?._meta;
47
+ if (meta && typeof meta === "object") {
48
+ return meta;
49
+ }
50
+ return void 0;
51
+ }
52
+ var toHaveRenderedHtml = function(received) {
53
+ const html = extractUiHtml(received);
54
+ const hasHtml = html !== void 0 && html.length > 0;
55
+ const isFallback = hasHtml && html.includes("mdx-fallback");
56
+ const pass = hasHtml && !isFallback;
57
+ return {
58
+ pass,
59
+ message: () => {
60
+ if (isFallback) {
61
+ return "Expected rendered HTML but got mdx-fallback (raw escaped content). MDX rendering may have failed.";
62
+ }
63
+ if (!hasHtml) {
64
+ return "Expected _meta to have ui/html property with rendered HTML";
65
+ }
66
+ return "Expected result not to have rendered HTML";
67
+ }
68
+ };
69
+ };
70
+ var toContainHtmlElement = function(received, tag) {
71
+ const html = extractUiHtml(received);
72
+ if (!html) {
73
+ return {
74
+ pass: false,
75
+ message: () => `Expected to find <${tag}> element, but no HTML content found`
76
+ };
77
+ }
78
+ const regex = new RegExp(`<${escapeRegex(tag)}[\\s>]`, "i");
79
+ const pass = regex.test(html);
80
+ return {
81
+ pass,
82
+ message: () => pass ? `Expected HTML not to contain <${tag}> element` : `Expected HTML to contain <${tag}> element`
83
+ };
84
+ };
85
+ var toContainBoundValue = function(received, value) {
86
+ const html = extractUiHtml(received);
87
+ if (!html) {
88
+ return {
89
+ pass: false,
90
+ message: () => `Expected HTML to contain bound value "${value}", but no HTML content found`
91
+ };
92
+ }
93
+ const stringValue = String(value);
94
+ const pass = html.includes(stringValue);
95
+ return {
96
+ pass,
97
+ message: () => pass ? `Expected HTML not to contain bound value "${stringValue}"` : `Expected HTML to contain bound value "${stringValue}"`
98
+ };
99
+ };
100
+ var toBeXssSafe = function(received) {
101
+ const html = extractUiHtml(received);
102
+ if (!html) {
103
+ return {
104
+ pass: true,
105
+ message: () => "Expected HTML to be XSS unsafe (no HTML found)"
106
+ };
107
+ }
108
+ const hasScript = /<script[\s>]/i.test(html);
109
+ const hasOnHandler = /\son\w+\s*=/i.test(html);
110
+ const hasJavascriptUri = /javascript:/i.test(html);
111
+ const issues = [];
112
+ if (hasScript) issues.push("<script> tag");
113
+ if (hasOnHandler) issues.push("inline event handler (onclick, etc.)");
114
+ if (hasJavascriptUri) issues.push("javascript: URI");
115
+ const pass = !hasScript && !hasOnHandler && !hasJavascriptUri;
116
+ return {
117
+ pass,
118
+ message: () => pass ? "Expected HTML not to be XSS safe" : `Expected HTML to be XSS safe, but found: ${issues.join(", ")}`
119
+ };
120
+ };
121
+ var toHaveWidgetMetadata = function(received) {
122
+ const meta = extractMeta(received);
123
+ if (!meta) {
124
+ return {
125
+ pass: false,
126
+ message: () => "Expected _meta to have widget metadata, but no _meta found"
127
+ };
128
+ }
129
+ const hasUiHtml = Boolean(meta["ui/html"]);
130
+ const hasOutputTemplate = Boolean(meta["openai/outputTemplate"]);
131
+ const hasMimeType = Boolean(meta["ui/mimeType"]);
132
+ const pass = hasUiHtml || hasOutputTemplate || hasMimeType;
133
+ return {
134
+ pass,
135
+ message: () => pass ? "Expected result not to have widget metadata" : "Expected _meta to have widget metadata (ui/html, openai/outputTemplate, or ui/mimeType)"
136
+ };
137
+ };
138
+ var toHaveCssClass = function(received, className) {
139
+ const html = extractUiHtml(received);
140
+ if (!html) {
141
+ return {
142
+ pass: false,
143
+ message: () => `Expected HTML to have CSS class "${className}", but no HTML content found`
144
+ };
145
+ }
146
+ const classRegex = new RegExp(`class(?:Name)?\\s*=\\s*["'][^"']*\\b${escapeRegex(className)}\\b[^"']*["']`, "i");
147
+ const pass = classRegex.test(html);
148
+ return {
149
+ pass,
150
+ message: () => pass ? `Expected HTML not to have CSS class "${className}"` : `Expected HTML to have CSS class "${className}"`
151
+ };
152
+ };
153
+ var toNotContainRawContent = function(received, content) {
154
+ const html = extractUiHtml(received);
155
+ if (!html) {
156
+ return {
157
+ pass: true,
158
+ message: () => `Expected HTML to contain raw content "${content}", but no HTML found`
159
+ };
160
+ }
161
+ const pass = !html.includes(content);
162
+ return {
163
+ pass,
164
+ message: () => pass ? `Expected HTML to contain raw content "${content}"` : `Expected HTML not to contain raw content "${content}" (may indicate rendering failure)`
165
+ };
166
+ };
167
+ var toHaveProperHtmlStructure = function(received) {
168
+ const html = extractUiHtml(received);
169
+ if (!html) {
170
+ return {
171
+ pass: false,
172
+ message: () => "Expected proper HTML structure, but no HTML content found"
173
+ };
174
+ }
175
+ const hasEscapedTags = html.includes("&lt;") && html.includes("&gt;");
176
+ const hasHtmlTags = /<[a-z]/i.test(html);
177
+ const pass = hasHtmlTags && !hasEscapedTags;
178
+ return {
179
+ pass,
180
+ message: () => {
181
+ if (hasEscapedTags) {
182
+ return "Expected proper HTML structure, but found escaped HTML entities - content may not have been rendered";
183
+ }
184
+ if (!hasHtmlTags) {
185
+ return "Expected proper HTML structure, but found no HTML tags";
186
+ }
187
+ return "Expected result not to have proper HTML structure";
188
+ }
189
+ };
190
+ };
191
+ var toHavePlatformMeta = function(received, platform) {
192
+ const meta = extractMeta(received);
193
+ if (!meta) {
194
+ return {
195
+ pass: false,
196
+ message: () => `Expected _meta to have platform meta for "${platform}", but no _meta found`
197
+ };
198
+ }
199
+ const expectedPrefixes = getToolCallMetaPrefixes(platform);
200
+ const forbiddenPrefixes = getForbiddenMetaPrefixes(platform);
201
+ const metaKeys = Object.keys(meta);
202
+ const hasExpectedPrefix = metaKeys.some((key) => expectedPrefixes.some((prefix) => key.startsWith(prefix)));
203
+ const forbiddenKeys = metaKeys.filter((key) => forbiddenPrefixes.some((prefix) => key.startsWith(prefix)));
204
+ const pass = hasExpectedPrefix && forbiddenKeys.length === 0;
205
+ return {
206
+ pass,
207
+ message: () => {
208
+ if (!hasExpectedPrefix) {
209
+ return `Expected _meta to have keys with prefixes [${expectedPrefixes.join(
210
+ ", "
211
+ )}] for platform "${platform}", but found: [${metaKeys.join(", ")}]`;
212
+ }
213
+ if (forbiddenKeys.length > 0) {
214
+ return `Expected _meta NOT to have keys [${forbiddenKeys.join(
215
+ ", "
216
+ )}] for platform "${platform}" (forbidden prefixes: [${forbiddenPrefixes.join(", ")}])`;
217
+ }
218
+ return `Expected result not to have platform meta for "${platform}"`;
219
+ }
220
+ };
221
+ };
222
+ var toHaveMetaKey = function(received, key) {
223
+ const meta = extractMeta(received);
224
+ if (!meta) {
225
+ return {
226
+ pass: false,
227
+ message: () => `Expected _meta to have key "${key}", but no _meta found`
228
+ };
229
+ }
230
+ const pass = key in meta;
231
+ return {
232
+ pass,
233
+ message: () => pass ? `Expected _meta not to have key "${key}"` : `Expected _meta to have key "${key}"`
234
+ };
235
+ };
236
+ var toHaveMetaValue = function(received, key, value) {
237
+ const meta = extractMeta(received);
238
+ if (!meta) {
239
+ return {
240
+ pass: false,
241
+ message: () => `Expected _meta["${key}"] to equal ${JSON.stringify(value)}, but no _meta found`
242
+ };
243
+ }
244
+ const actualValue = meta[key];
245
+ const pass = JSON.stringify(actualValue) === JSON.stringify(value);
246
+ return {
247
+ pass,
248
+ message: () => pass ? `Expected _meta["${key}"] not to equal ${JSON.stringify(value)}` : `Expected _meta["${key}"] to equal ${JSON.stringify(value)}, but got ${JSON.stringify(actualValue)}`
249
+ };
250
+ };
251
+ var toNotHaveMetaKey = function(received, key) {
252
+ const meta = extractMeta(received);
253
+ if (!meta) {
254
+ return {
255
+ pass: true,
256
+ message: () => `Expected _meta to have key "${key}", but no _meta found`
257
+ };
258
+ }
259
+ const pass = !(key in meta);
260
+ return {
261
+ pass,
262
+ message: () => pass ? `Expected _meta to have key "${key}"` : `Expected _meta not to have key "${key}"`
263
+ };
264
+ };
265
+ var toHaveOnlyNamespacedMeta = function(received, namespace) {
266
+ const meta = extractMeta(received);
267
+ if (!meta) {
268
+ return {
269
+ pass: false,
270
+ message: () => `Expected _meta to have keys with namespace "${namespace}", but no _meta found`
271
+ };
272
+ }
273
+ const metaKeys = Object.keys(meta);
274
+ const wrongKeys = metaKeys.filter((key) => !key.startsWith(namespace));
275
+ const pass = wrongKeys.length === 0 && metaKeys.length > 0;
276
+ return {
277
+ pass,
278
+ message: () => {
279
+ if (metaKeys.length === 0) {
280
+ return `Expected _meta to have keys with namespace "${namespace}", but _meta is empty`;
281
+ }
282
+ if (wrongKeys.length > 0) {
283
+ return `Expected _meta to ONLY have keys with namespace "${namespace}", but found: [${wrongKeys.join(", ")}]`;
284
+ }
285
+ return `Expected _meta not to have only keys with namespace "${namespace}"`;
286
+ }
287
+ };
288
+ };
289
+ var toHavePlatformMimeType = function(received, platform) {
290
+ const meta = extractMeta(received);
291
+ const expectedMimeType = getPlatformMimeType(platform);
292
+ if (!meta) {
293
+ return {
294
+ pass: false,
295
+ message: () => `Expected _meta to have MIME type "${expectedMimeType}" for platform "${platform}", but no _meta found`
296
+ };
297
+ }
298
+ let mimeTypeKey;
299
+ switch (platform) {
300
+ case "openai":
301
+ mimeTypeKey = "openai/mimeType";
302
+ break;
303
+ case "ext-apps":
304
+ mimeTypeKey = "ui/mimeType";
305
+ break;
306
+ default:
307
+ mimeTypeKey = "frontmcp/mimeType";
308
+ }
309
+ const actualMimeType = meta[mimeTypeKey];
310
+ const pass = actualMimeType === expectedMimeType;
311
+ return {
312
+ pass,
313
+ message: () => pass ? `Expected _meta["${mimeTypeKey}"] not to be "${expectedMimeType}"` : `Expected _meta["${mimeTypeKey}"] to be "${expectedMimeType}" for platform "${platform}", but got "${actualMimeType}"`
314
+ };
315
+ };
316
+ var toHavePlatformHtml = function(received, platform) {
317
+ const meta = extractMeta(received);
318
+ if (!meta) {
319
+ return {
320
+ pass: false,
321
+ message: () => `Expected _meta to have platform HTML for "${platform}", but no _meta found`
322
+ };
323
+ }
324
+ let htmlKey;
325
+ switch (platform) {
326
+ case "openai":
327
+ htmlKey = "openai/html";
328
+ break;
329
+ case "ext-apps":
330
+ htmlKey = "ui/html";
331
+ break;
332
+ default:
333
+ htmlKey = "frontmcp/html";
334
+ }
335
+ const html = meta[htmlKey];
336
+ const pass = typeof html === "string" && html.length > 0;
337
+ return {
338
+ pass,
339
+ 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}`}`
340
+ };
341
+ };
342
+ var uiMatchers = {
343
+ // Existing HTML matchers
344
+ toHaveRenderedHtml,
345
+ toContainHtmlElement,
346
+ toContainBoundValue,
347
+ toBeXssSafe,
348
+ toHaveWidgetMetadata,
349
+ toHaveCssClass,
350
+ toNotContainRawContent,
351
+ toHaveProperHtmlStructure,
352
+ // Platform meta matchers
353
+ toHavePlatformMeta,
354
+ toHaveMetaKey,
355
+ toHaveMetaValue,
356
+ toNotHaveMetaKey,
357
+ toHaveOnlyNamespacedMeta,
358
+ toHavePlatformMimeType,
359
+ toHavePlatformHtml
360
+ };
361
+
362
+ // libs/testing/src/matchers/mcp-matchers.ts
363
+ var toContainTool = function(received, toolName) {
364
+ const tools = received;
365
+ if (!Array.isArray(tools)) {
366
+ return {
367
+ pass: false,
368
+ message: () => `Expected an array of tools, but received ${typeof received}`
369
+ };
370
+ }
371
+ const pass = tools.some((t) => t.name === toolName);
372
+ const availableTools = tools.map((t) => t.name).join(", ");
373
+ return {
374
+ pass,
375
+ message: () => pass ? `Expected tools not to contain "${toolName}"` : `Expected tools to contain "${toolName}", but got: [${availableTools}]`
376
+ };
377
+ };
378
+ var toBeSuccessful = function(received) {
379
+ const result = received;
380
+ if (typeof result !== "object" || result === null || !("isSuccess" in result)) {
381
+ return {
382
+ pass: false,
383
+ message: () => `Expected a result wrapper object with isSuccess property`
384
+ };
385
+ }
386
+ const pass = result.isSuccess;
387
+ return {
388
+ pass,
389
+ message: () => pass ? "Expected result not to be successful" : `Expected result to be successful, but got error: ${result.error?.message ?? "unknown error"}`
390
+ };
391
+ };
392
+ var toBeError = function(received, expectedCode) {
393
+ const result = received;
394
+ if (typeof result !== "object" || result === null || !("isError" in result)) {
395
+ return {
396
+ pass: false,
397
+ message: () => `Expected a result wrapper object with isError property`
398
+ };
399
+ }
400
+ let pass = result.isError;
401
+ if (pass && expectedCode !== void 0) {
402
+ pass = result.error?.code === expectedCode;
403
+ }
404
+ return {
405
+ pass,
406
+ message: () => {
407
+ if (!result.isError) {
408
+ return "Expected result to be an error, but it was successful";
409
+ }
410
+ if (expectedCode !== void 0 && result.error?.code !== expectedCode) {
411
+ return `Expected error code ${expectedCode}, but got ${result.error?.code}`;
412
+ }
413
+ return "Expected result not to be an error";
414
+ }
415
+ };
416
+ };
417
+ var toHaveTextContent = function(received, expectedText) {
418
+ const result = received;
419
+ if (typeof result !== "object" || result === null || !("text" in result)) {
420
+ return {
421
+ pass: false,
422
+ message: () => `Expected a ToolResultWrapper or ResourceContentWrapper object with text method`
423
+ };
424
+ }
425
+ const text = result.text();
426
+ const hasText = "hasTextContent" in result ? result.hasTextContent() : text !== void 0;
427
+ let pass = hasText;
428
+ if (pass && expectedText !== void 0) {
429
+ pass = text?.includes(expectedText) ?? false;
430
+ }
431
+ return {
432
+ pass,
433
+ message: () => {
434
+ if (!hasText) {
435
+ return "Expected result to have text content";
436
+ }
437
+ if (expectedText !== void 0 && !text?.includes(expectedText)) {
438
+ return `Expected text to contain "${expectedText}", but got: "${text}"`;
439
+ }
440
+ return "Expected result not to have text content";
441
+ }
442
+ };
443
+ };
444
+ var toHaveImageContent = function(received) {
445
+ const result = received;
446
+ if (typeof result !== "object" || result === null || !("hasImageContent" in result)) {
447
+ return {
448
+ pass: false,
449
+ message: () => `Expected a ToolResultWrapper object with hasImageContent method`
450
+ };
451
+ }
452
+ const pass = result.hasImageContent();
453
+ return {
454
+ pass,
455
+ message: () => pass ? "Expected result not to have image content" : "Expected result to have image content"
456
+ };
457
+ };
458
+ var toHaveResourceContent = function(received) {
459
+ const result = received;
460
+ if (typeof result !== "object" || result === null || !("hasResourceContent" in result)) {
461
+ return {
462
+ pass: false,
463
+ message: () => `Expected a ToolResultWrapper object with hasResourceContent method`
464
+ };
465
+ }
466
+ const pass = result.hasResourceContent();
467
+ return {
468
+ pass,
469
+ message: () => pass ? "Expected result not to have resource content" : "Expected result to have resource content"
470
+ };
471
+ };
472
+ var toContainResource = function(received, uri) {
473
+ const resources = received;
474
+ if (!Array.isArray(resources)) {
475
+ return {
476
+ pass: false,
477
+ message: () => `Expected an array of resources, but received ${typeof received}`
478
+ };
479
+ }
480
+ const pass = resources.some((r) => r.uri === uri);
481
+ const availableUris = resources.map((r) => r.uri).join(", ");
482
+ return {
483
+ pass,
484
+ message: () => pass ? `Expected resources not to contain "${uri}"` : `Expected resources to contain "${uri}", but got: [${availableUris}]`
485
+ };
486
+ };
487
+ var toContainResourceTemplate = function(received, uriTemplate) {
488
+ const templates = received;
489
+ if (!Array.isArray(templates)) {
490
+ return {
491
+ pass: false,
492
+ message: () => `Expected an array of resource templates, but received ${typeof received}`
493
+ };
494
+ }
495
+ const pass = templates.some((t) => t.uriTemplate === uriTemplate);
496
+ const availableTemplates = templates.map((t) => t.uriTemplate).join(", ");
497
+ return {
498
+ pass,
499
+ message: () => pass ? `Expected templates not to contain "${uriTemplate}"` : `Expected templates to contain "${uriTemplate}", but got: [${availableTemplates}]`
500
+ };
501
+ };
502
+ var toHaveMimeType = function(received, mimeType) {
503
+ const result = received;
504
+ if (typeof result !== "object" || result === null || !("hasMimeType" in result)) {
505
+ return {
506
+ pass: false,
507
+ message: () => `Expected a ResourceContentWrapper object with hasMimeType method`
508
+ };
509
+ }
510
+ const pass = result.hasMimeType(mimeType);
511
+ const actualMimeType = result.mimeType();
512
+ return {
513
+ pass,
514
+ message: () => pass ? `Expected content not to have MIME type "${mimeType}"` : `Expected MIME type "${mimeType}", but got "${actualMimeType}"`
515
+ };
516
+ };
517
+ var toContainPrompt = function(received, name) {
518
+ const prompts = received;
519
+ if (!Array.isArray(prompts)) {
520
+ return {
521
+ pass: false,
522
+ message: () => `Expected an array of prompts, but received ${typeof received}`
523
+ };
524
+ }
525
+ const pass = prompts.some((p) => p.name === name);
526
+ const availablePrompts = prompts.map((p) => p.name).join(", ");
527
+ return {
528
+ pass,
529
+ message: () => pass ? `Expected prompts not to contain "${name}"` : `Expected prompts to contain "${name}", but got: [${availablePrompts}]`
530
+ };
531
+ };
532
+ var toHaveMessages = function(received, count) {
533
+ const result = received;
534
+ if (typeof result !== "object" || result === null || !("messages" in result)) {
535
+ return {
536
+ pass: false,
537
+ message: () => `Expected a PromptResultWrapper object with messages property`
538
+ };
539
+ }
540
+ const actualCount = result.messages?.length ?? 0;
541
+ const pass = actualCount === count;
542
+ return {
543
+ pass,
544
+ message: () => pass ? `Expected prompt not to have ${count} messages` : `Expected prompt to have ${count} messages, but got ${actualCount}`
545
+ };
546
+ };
547
+ var toBeValidJsonRpc = function(received) {
548
+ const response = received;
549
+ if (typeof response !== "object" || response === null) {
550
+ return {
551
+ pass: false,
552
+ message: () => `Expected an object, but received ${typeof received}`
553
+ };
554
+ }
555
+ const hasJsonRpc = response["jsonrpc"] === "2.0";
556
+ const hasId = "id" in response;
557
+ const hasResult = "result" in response;
558
+ const hasError = "error" in response;
559
+ const hasExactlyOneResultOrError = (hasResult || hasError) && !(hasResult && hasError);
560
+ const pass = hasJsonRpc && hasId && hasExactlyOneResultOrError;
561
+ return {
562
+ pass,
563
+ message: () => {
564
+ if (pass) {
565
+ return "Expected response not to be valid JSON-RPC";
566
+ }
567
+ const issues = [];
568
+ if (!hasJsonRpc) issues.push('missing or invalid "jsonrpc": "2.0"');
569
+ if (!hasId) issues.push('missing "id" field');
570
+ if (!hasExactlyOneResultOrError) {
571
+ if (!hasResult && !hasError) issues.push('missing "result" or "error"');
572
+ else issues.push('cannot have both "result" and "error"');
573
+ }
574
+ return `Expected valid JSON-RPC 2.0 response: ${issues.join(", ")}`;
575
+ }
576
+ };
577
+ };
578
+ var toHaveResult = function(received) {
579
+ const response = received;
580
+ if (typeof response !== "object" || response === null) {
581
+ return {
582
+ pass: false,
583
+ message: () => `Expected an object, but received ${typeof received}`
584
+ };
585
+ }
586
+ const pass = "result" in response;
587
+ return {
588
+ pass,
589
+ message: () => pass ? "Expected response not to have result" : "Expected response to have result"
590
+ };
591
+ };
592
+ var toHaveError = function(received) {
593
+ const response = received;
594
+ if (typeof response !== "object" || response === null) {
595
+ return {
596
+ pass: false,
597
+ message: () => `Expected an object, but received ${typeof received}`
598
+ };
599
+ }
600
+ const pass = "error" in response;
601
+ return {
602
+ pass,
603
+ message: () => pass ? "Expected response not to have error" : "Expected response to have error"
604
+ };
605
+ };
606
+ var toHaveErrorCode = function(received, code) {
607
+ const response = received;
608
+ if (typeof response !== "object" || response === null) {
609
+ return {
610
+ pass: false,
611
+ message: () => `Expected an object, but received ${typeof received}`
612
+ };
613
+ }
614
+ const actualCode = response.error?.code;
615
+ const pass = actualCode === code;
616
+ return {
617
+ pass,
618
+ message: () => pass ? `Expected response not to have error code ${code}` : `Expected error code ${code}, but got ${actualCode ?? "no error"}`
619
+ };
620
+ };
621
+ var mcpMatchers = {
622
+ // Tool matchers
623
+ toContainTool,
624
+ toBeSuccessful,
625
+ toBeError,
626
+ toHaveTextContent,
627
+ toHaveImageContent,
628
+ toHaveResourceContent,
629
+ // Resource matchers
630
+ toContainResource,
631
+ toContainResourceTemplate,
632
+ toHaveMimeType,
633
+ // Prompt matchers
634
+ toContainPrompt,
635
+ toHaveMessages,
636
+ // Protocol matchers
637
+ toBeValidJsonRpc,
638
+ toHaveResult,
639
+ toHaveError,
640
+ toHaveErrorCode,
641
+ // UI matchers (for testing tool UI responses)
642
+ ...uiMatchers
643
+ };
644
+ export {
645
+ mcpMatchers
646
+ };