Skip to content

Commit 19de9b5

Browse files
committed
test: harden documentation test execution
Run the cookbook assertions only when invoked directly and keep Markdown fence parsing friendly to static analyzers. Tests: Docker lint and test:coverage (589 passed; 96.41% lines, 92.95% branches)
1 parent db94934 commit 19de9b5

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

__tests__/unit/documentation.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
import { strict as assert } from 'node:assert';
1010
import { readFileSync } from 'node:fs';
11+
import { fileURLToPath } from 'node:url';
1112
import { createTestResults, printTestSummary, TestResult, testFunction } from '../helpers/test-utils.js';
1213

1314
const results = createTestResults();
1415
const guideUrl = new URL('../../docs/client-configurations.md', import.meta.url);
16+
const markdownFence = String.fromCharCode(96).repeat(3);
1517

1618
const expectedMatrixRows = [
1719
'| Claude Desktop | Yes | Yes | No |',
@@ -41,9 +43,9 @@ function extractFences(markdown: string, language: string): string[] {
4143
let active: string[] | null = null;
4244

4345
for (const line of markdown.split(/\r?\n/u)) {
44-
if (active === null && line.trim() === `\`\`\`${language}`) {
46+
if (active === null && line.trim() === markdownFence + language) {
4547
active = [];
46-
} else if (active !== null && line.trim() === '```') {
48+
} else if (active !== null && line.trim() === markdownFence) {
4749
blocks.push(active.join('\n'));
4850
active = null;
4951
} else if (active !== null) {
@@ -190,4 +192,6 @@ export async function runTests(): Promise<TestResult> {
190192
return results;
191193
}
192194

193-
runTests();
195+
if (process.argv[1] !== undefined && fileURLToPath(import.meta.url) === process.argv[1]) {
196+
runTests();
197+
}

0 commit comments

Comments
 (0)