-
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
Conversation
Co-authored-by: dreamquality <130073078+dreamquality@users.noreply.github.com>
Co-authored-by: dreamquality <130073078+dreamquality@users.noreply.github.com>
|
@copilot add tests, verify cli works with such collections where checks are collected in the folders, test edge cases, update readme.md and prepare release.yml file |
Co-authored-by: dreamquality <130073078+dreamquality@users.noreply.github.com>
All requested items completed in commit ee59206: ✅ Tests added: 18 total tests in postman.test.js (9 new edge case tests)
✅ CLI verified: Tested with real collection containing folder-level tests
✅ Edge cases tested: 9 comprehensive edge case tests covering:
✅ README updated: Added "Edge Cases Handled" section documenting all supported scenarios ✅ release.yml prepared: Updated with folder-level tests feature, test count (198 tests), and quality assurance details All 198 tests pass with no regressions. |
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.
Pull Request Overview
This PR implements support for folder-level tests in Postman collections to provide more accurate coverage calculations. Previously, tests defined at the folder level were ignored, leading to inaccurate coverage metrics and forcing users to duplicate common tests across requests.
- Implemented folder-level test extraction and inheritance through the collection hierarchy
- Enhanced regex patterns for better status code extraction from test scripts
- Added comprehensive test coverage with 18 new tests covering various scenarios and edge cases
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
lib/postman.js |
Core implementation of folder-level test extraction and inheritance logic |
test/postman.test.js |
18 comprehensive tests covering folder-level functionality and edge cases |
readme.md |
Documentation updates including new section on folder-level tests with examples |
.github/workflows/release.yml |
Updated release notes with folder-level tests feature description |
auto-detect-newman.html |
Timestamp update from test execution |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Это папка - извлекаем тесты из папки | ||
| const folderTestData = extractTestsFromEvents(item.event); | ||
|
|
||
| // Объединяем тесты папки с родительскими тестами | ||
| const combinedFolderTests = { | ||
| testedStatusCodes: new Set([...folderTests.testedStatusCodes, ...folderTestData.testedStatusCodes]), | ||
| testScripts: folderTests.testScripts + folderTestData.testScripts | ||
| }; |
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 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'.
|
|
||
| traverseItems(item.item, item.name, combinedFolderTests); | ||
| } else { | ||
| // Это запрос |
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 comment should be translated to English. Consider translating 'Это запрос' to 'This is a request'.
| // Это запрос | |
| // This is a request |
| // Извлекаем тесты из самого запроса | ||
| const requestTestData = extractTestsFromEvents(item.event); | ||
|
|
||
| // Объединяем тесты запроса с тестами папки |
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 |
Overview
This PR implements support for folder-level tests in Postman collections. Previously, tests defined at the folder level were ignored during coverage calculation. Now, folder-level tests are automatically extracted and applied to all requests within that folder and its subfolders, ensuring more accurate coverage metrics.
Problem
When organizing Postman collections into folders with common test assertions at the folder level, these tests were not being included in the coverage calculation. This led to:
Example
Consider this Postman collection structure:
{ "name": "Users API", "item": [ { "name": "Get Users", "request": { "method": "GET", "url": "/users" } }, { "name": "Create User", "request": { "method": "POST", "url": "/users" } } ], "event": [{ "listen": "test", "script": { "exec": ["pm.expect(pm.response.code).to.be.oneOf([200, 201]);"] } }] }Before: Both requests showed
testedStatusCodes = []❌After: Both requests show
testedStatusCodes = [200, 201]✅Solution
Implementation
Created
extractTestsFromEvents()helper functionModified
traverseItems()to support test inheritancefolderTestsparameter to track inherited tests through the folder hierarchyEnhanced regex patterns for better status code extraction
oneOfpattern to properly match:pm.expect(pm.response.code).to.be.oneOf([200, 201])to.be.oneOf([200, 201])Key Features
✅ Folder-level test extraction: Tests defined at folder level are now included
✅ Recursive inheritance: Supports nested folder hierarchies with multiple levels
✅ Combined tests: Folder-level tests are merged with request-level tests
✅ Backward compatible: Existing collections without folder tests work exactly as before
✅ Comprehensive test coverage: 18 tests covering all scenarios including edge cases
✅ Robust edge case handling: Handles empty folders, deep nesting, null events, and mixed patterns
Testing
New Tests Added (18 total)
Original Tests (9):
Edge Case Tests (9):
Test Results
CLI Verification
Tested with real Postman collection containing folder-level tests:
Documentation
Updated README.md with:
Updated
.github/workflows/release.ymlwith:Impact
This change provides:
Files Changed
lib/postman.js: Core implementation (103 lines modified)test/postman.test.js: Comprehensive test coverage (18 tests total - 9 original + 9 edge cases)readme.md: Documentation and examples including edge cases section.github/workflows/release.yml: Updated release notes with feature detailsFixes the issue where tests defined at the Postman collection folder level were not being included in coverage calculations.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.