|
1 | 1 | import { execFileSync } from 'node:child_process'; |
2 | 2 | import { existsSync, readFileSync } from 'node:fs'; |
| 3 | +import { createRequire } from 'node:module'; |
3 | 4 | import { dirname, join } from 'node:path'; |
4 | 5 | import { fileURLToPath } from 'node:url'; |
5 | 6 |
|
6 | 7 | import { beforeAll, describe, expect, test } from 'vitest'; |
7 | 8 |
|
8 | 9 | const pkgDir = join(dirname(fileURLToPath(import.meta.url)), '../..'); |
9 | 10 | const distDir = join(pkgDir, 'dist'); |
| 11 | +const requireDist = createRequire(join(pkgDir, 'package.json')); |
10 | 12 | const NODE_ONLY = /\b(child_process|cross-spawn|node:stream|node:child_process)\b/; |
11 | 13 | // Anchored at start-of-line so JSDoc-example `from 'ajv'` strings in vendored chunks don't match. |
12 | 14 | const VALIDATOR_BACKEND_IMPORT = /^import[^\n]*?from\s+["'](?:ajv|ajv-formats|@cfworker\/json-schema)["']/m; |
@@ -67,4 +69,15 @@ describe('@modelcontextprotocol/client root entry is browser-safe', () => { |
67 | 69 | } |
68 | 70 | } |
69 | 71 | }); |
| 72 | + |
| 73 | + test('CJS AJV validator subpath exposes Ajv at runtime', () => { |
| 74 | + const { Ajv, AjvJsonSchemaValidator, addFormats } = requireDist( |
| 75 | + './dist/validators/ajv.cjs' |
| 76 | + ) as typeof import('../../src/validators/ajv'); |
| 77 | + |
| 78 | + const ajv = new Ajv({ strict: false, allErrors: true }); |
| 79 | + addFormats(ajv); |
| 80 | + |
| 81 | + expect(new AjvJsonSchemaValidator(ajv)).toBeInstanceOf(AjvJsonSchemaValidator); |
| 82 | + }); |
70 | 83 | }); |
0 commit comments