-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Include folder-level tests in Postman collection coverage calculation #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,11 +31,63 @@ function loadPostmanCollection(filePath) { | |||||||||||||||||
| function extractRequestsFromPostman(collection, verbose = false) { | ||||||||||||||||||
| const requests = []; | ||||||||||||||||||
|
|
||||||||||||||||||
| function traverseItems(items, currentFolder = '') { | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Extract status codes and test scripts from events | ||||||||||||||||||
| */ | ||||||||||||||||||
| function extractTestsFromEvents(events) { | ||||||||||||||||||
| const testedStatusCodes = new Set(); | ||||||||||||||||||
| let testScripts = ''; | ||||||||||||||||||
|
|
||||||||||||||||||
| if (events && Array.isArray(events)) { | ||||||||||||||||||
| events.forEach(ev => { | ||||||||||||||||||
| if (ev.listen === 'test' && ev.script && ev.script.exec) { | ||||||||||||||||||
| const scriptCode = ev.script.exec.join('\n'); | ||||||||||||||||||
| testScripts += scriptCode + '\n'; // Aggregate all test scripts | ||||||||||||||||||
|
|
||||||||||||||||||
| // Ищем различные паттерны | ||||||||||||||||||
| const patterns = [ | ||||||||||||||||||
| /to\.have\.status\((\d+)\)/g, | ||||||||||||||||||
| /pm\.expect\(pm\.response\.code\)\.to\.eql\((\d+)\)/g, | ||||||||||||||||||
| /pm\.response\.code\s*={1,3}\s*(\d+)/g, | ||||||||||||||||||
| /pm\.response\.status\s*={1,3}\s*(\d+)/g, | ||||||||||||||||||
| /pm\.expect\(pm\.response\.code\)\.to\.be\.oneOf\(\[([^\]]+)\]\)/g, | ||||||||||||||||||
| /to\.be\.oneOf\(\[([^\]]+)\]\)/g | ||||||||||||||||||
| ]; | ||||||||||||||||||
| patterns.forEach(regex => { | ||||||||||||||||||
| let match; | ||||||||||||||||||
| while ((match = regex.exec(scriptCode)) !== null) { | ||||||||||||||||||
| if (regex === patterns[4] || regex === patterns[5]) { | ||||||||||||||||||
| // Extract multiple codes if present (oneOf pattern) | ||||||||||||||||||
| const codesStr = match[1]; | ||||||||||||||||||
| const codesArr = codesStr.match(/\d+/g); | ||||||||||||||||||
| if (codesArr) { | ||||||||||||||||||
| codesArr.forEach(c => testedStatusCodes.add(c)); | ||||||||||||||||||
| } | ||||||||||||||||||
| } else { | ||||||||||||||||||
| testedStatusCodes.add(match[1]); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return { testedStatusCodes, testScripts }; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function traverseItems(items, currentFolder = '', folderTests = { testedStatusCodes: new Set(), testScripts: '' }) { | ||||||||||||||||||
| items.forEach(item => { | ||||||||||||||||||
| if (item.item) { | ||||||||||||||||||
| // Это папка | ||||||||||||||||||
| traverseItems(item.item, item.name); | ||||||||||||||||||
| // Это папка - извлекаем тесты из папки | ||||||||||||||||||
| const folderTestData = extractTestsFromEvents(item.event); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Объединяем тесты папки с родительскими тестами | ||||||||||||||||||
| const combinedFolderTests = { | ||||||||||||||||||
| testedStatusCodes: new Set([...folderTests.testedStatusCodes, ...folderTestData.testedStatusCodes]), | ||||||||||||||||||
| testScripts: folderTests.testScripts + folderTestData.testScripts | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| traverseItems(item.item, item.name, combinedFolderTests); | ||||||||||||||||||
| } else { | ||||||||||||||||||
| // Это запрос | ||||||||||||||||||
|
||||||||||||||||||
| // Это запрос | |
| // This is a request |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Russian comments should be translated to English. Consider translating 'Извлекаем тесты из самого запроса' to 'Extract tests from the request itself' and 'Объединяем тесты запроса с тестами папки' to 'Combine request tests with folder tests'.
| // Извлекаем тесты из самого запроса | |
| const requestTestData = extractTestsFromEvents(item.event); | |
| // Объединяем тесты запроса с тестами папки | |
| // Extract tests from the request itself | |
| const requestTestData = extractTestsFromEvents(item.event); | |
| // Combine request tests with folder tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Russian comments should be translated to English for consistency with the rest of the codebase. Consider translating 'Это папка - извлекаем тесты из папки' to 'This is a folder - extract tests from folder' and 'Объединяем тесты папки с родительскими тестами' to 'Combine folder tests with parent tests'.