Skip to content

Commit 39dc57c

Browse files
committed
fix dynamic tests processing
1 parent f2d1d7f commit 39dc57c

3 files changed

Lines changed: 80 additions & 7 deletions

File tree

dist/index.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27381,6 +27381,8 @@ class MarkdownDocsGenerator {
2738127381
let inComment = false;
2738227382
let commentLines = [];
2738327383
let braceLevel = 0;
27384+
let inDynamicTestBlock = false;
27385+
let dynamicTestTemplate = '';
2738427386
for (let i = 0; i < lines.length; i++) {
2738527387
const line = lines[i].trim();
2738627388
const lineNumber = i + 1;
@@ -27417,9 +27419,39 @@ class MarkdownDocsGenerator {
2741727419
};
2741827420
continue;
2741927421
}
27420-
// Extract test cases (it, test, bench) including Vitest modifiers
27421-
const testMatch = line.match(/(?:it|test|bench)(?:\.(?:skip|only|todo|concurrent|each\([^)]*\)))?\s*\(\s*['"`]([^'"`]+)['"`]/);
27422-
if (testMatch && currentDescribe) {
27422+
// Check for dynamic test patterns (forEach, map, etc.)
27423+
const dynamicTestMatch = line.match(/\.forEach\s*\(\s*\([^)]*\)\s*=>\s*\{/);
27424+
if (dynamicTestMatch && currentDescribe) {
27425+
inDynamicTestBlock = true;
27426+
// Look ahead to find the test template
27427+
for (let j = i + 1; j < Math.min(i + 10, lines.length); j++) {
27428+
const testTemplateMatch = lines[j].match(/(?:it|test|bench)(?:\.(?:skip|only|todo|concurrent|each\([^)]*\)))?\s*\(\s*[`'"]([^`'"]*)[`'"]/);
27429+
if (testTemplateMatch) {
27430+
dynamicTestTemplate = testTemplateMatch[1];
27431+
const description = commentLines.length > 0 ? this.parseTestDescription(commentLines) : 'Dynamic test generated from forEach loop';
27432+
const link = this.generateTestLink(filePath, lineNumber, currentDescribe.name, dynamicTestTemplate);
27433+
tests.push({
27434+
testName: `${currentDescribe.name} > ${dynamicTestTemplate} (dynamic)`,
27435+
shortName: `${dynamicTestTemplate} (dynamic)`,
27436+
describeName: currentDescribe.name,
27437+
link,
27438+
description,
27439+
lineNumber,
27440+
tags: this.extractTags(currentDescribe.name, description).concat(['dynamic'])
27441+
});
27442+
if (this.verbose) {
27443+
console.log(` Found dynamic test pattern: ${dynamicTestTemplate}`);
27444+
}
27445+
break;
27446+
}
27447+
}
27448+
// Reset comment lines after processing
27449+
commentLines = [];
27450+
continue;
27451+
}
27452+
// Extract regular test cases (it, test, bench) with template literal support
27453+
const testMatch = line.match(/(?:it|test|bench)(?:\.(?:skip|only|todo|concurrent|each\([^)]*\)))?\s*\(\s*[`'"]([^`'"]*)[`'"]/);
27454+
if (testMatch && currentDescribe && !inDynamicTestBlock) {
2742327455
const testName = testMatch[1];
2742427456
const fullTestName = `${currentDescribe.name} > ${testName}`;
2742527457
const description = this.parseTestDescription(commentLines);
@@ -27440,6 +27472,7 @@ class MarkdownDocsGenerator {
2744027472
// Reset scope tracking when leaving blocks
2744127473
if (currentDescribe && braceLevel < currentDescribe.level) {
2744227474
currentDescribe = null;
27475+
inDynamicTestBlock = false;
2744327476
}
2744427477
}
2744527478
return tests;

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/markdown-docs.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ class MarkdownDocsGenerator {
221221
let inComment = false;
222222
let commentLines: string[] = [];
223223
let braceLevel = 0;
224+
let inDynamicTestBlock = false;
225+
let dynamicTestTemplate = '';
224226

225227
for (let i = 0; i < lines.length; i++) {
226228
const line = lines[i].trim();
@@ -261,9 +263,46 @@ class MarkdownDocsGenerator {
261263
continue;
262264
}
263265

264-
// Extract test cases (it, test, bench) including Vitest modifiers
265-
const testMatch = line.match(/(?:it|test|bench)(?:\.(?:skip|only|todo|concurrent|each\([^)]*\)))?\s*\(\s*['"`]([^'"`]+)['"`]/);
266-
if (testMatch && currentDescribe) {
266+
// Check for dynamic test patterns (forEach, map, etc.)
267+
const dynamicTestMatch = line.match(/\.forEach\s*\(\s*\([^)]*\)\s*=>\s*\{/);
268+
if (dynamicTestMatch && currentDescribe) {
269+
inDynamicTestBlock = true;
270+
271+
// Look ahead to find the test template
272+
for (let j = i + 1; j < Math.min(i + 10, lines.length); j++) {
273+
const testTemplateMatch = lines[j].match(/(?:it|test|bench)(?:\.(?:skip|only|todo|concurrent|each\([^)]*\)))?\s*\(\s*[`'"]([^`'"]*)[`'"]/);
274+
if (testTemplateMatch) {
275+
dynamicTestTemplate = testTemplateMatch[1];
276+
277+
const description = commentLines.length > 0 ? this.parseTestDescription(commentLines) : 'Dynamic test generated from forEach loop';
278+
const link = this.generateTestLink(filePath, lineNumber, currentDescribe.name, dynamicTestTemplate);
279+
280+
tests.push({
281+
testName: `${currentDescribe.name} > ${dynamicTestTemplate} (dynamic)`,
282+
shortName: `${dynamicTestTemplate} (dynamic)`,
283+
describeName: currentDescribe.name,
284+
link,
285+
description,
286+
lineNumber,
287+
tags: this.extractTags(currentDescribe.name, description).concat(['dynamic'])
288+
});
289+
290+
if (this.verbose) {
291+
console.log(` Found dynamic test pattern: ${dynamicTestTemplate}`);
292+
}
293+
294+
break;
295+
}
296+
}
297+
298+
// Reset comment lines after processing
299+
commentLines = [];
300+
continue;
301+
}
302+
303+
// Extract regular test cases (it, test, bench) with template literal support
304+
const testMatch = line.match(/(?:it|test|bench)(?:\.(?:skip|only|todo|concurrent|each\([^)]*\)))?\s*\(\s*[`'"]([^`'"]*)[`'"]/);
305+
if (testMatch && currentDescribe && !inDynamicTestBlock) {
267306
const testName = testMatch[1];
268307
const fullTestName = `${currentDescribe.name} > ${testName}`;
269308
const description = this.parseTestDescription(commentLines);
@@ -288,6 +327,7 @@ class MarkdownDocsGenerator {
288327
// Reset scope tracking when leaving blocks
289328
if (currentDescribe && braceLevel < currentDescribe.level) {
290329
currentDescribe = null;
330+
inDynamicTestBlock = false;
291331
}
292332
}
293333

0 commit comments

Comments
 (0)