Skip to content

Commit 465273e

Browse files
Copilotdreamquality
andcommitted
Fix and update test cases to work with smart mapping enabled by default
Co-authored-by: dreamquality <[email protected]>
1 parent 876ae2a commit 465273e

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

auto-detect-newman.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ <h1>Swagger Coverage Report</h1>
384384
&#128262; <!-- flashlight icon -->
385385
</button>
386386
<div class="meta-info">
387-
<p><strong>Timestamp:</strong> 9/16/2025, 6:01:04 PM</p>
387+
<p><strong>Timestamp:</strong> 9/18/2025, 11:36:09 AM</p>
388388
<p><strong>API Spec:</strong> Test API</p>
389389

390390
<p><strong>Postman Collection:</strong> Test Newman Collection</p>
@@ -461,7 +461,7 @@ <h1>Swagger Coverage Report</h1>
461461
hljs.highlightAll();
462462

463463
// coverageData from server
464-
let coverageData = [{"method":"GET","path":"/users","name":"getUsers","statusCode":"200","tags":[],"expectedStatusCodes":["200"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":false,"matchedRequests":[{"name":"Get Users","rawUrl":"https://api.example.com/users","method":"GET","testedStatusCodes":["200"],"testScripts":"// Status code is 200"}]},{"method":"POST","path":"/users","name":"createUser","statusCode":"201","tags":[],"expectedStatusCodes":["201","400"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":false,"matchedRequests":[{"name":"Create User","rawUrl":"https://api.example.com/users","method":"POST","testedStatusCodes":["201"],"testScripts":"// Status code is 201"}]},{"method":"POST","path":"/users","name":"createUser","statusCode":"400","tags":[],"expectedStatusCodes":["201","400"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":true,"matchedRequests":[]},{"method":"GET","path":"/users/{id}","name":"getUserById","statusCode":"200","tags":[],"expectedStatusCodes":["200","404"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":true,"matchedRequests":[]},{"method":"GET","path":"/users/{id}","name":"getUserById","statusCode":"404","tags":[],"expectedStatusCodes":["200","404"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":true,"matchedRequests":[]}];
464+
let coverageData = [{"method":"GET","path":"/users","name":"getUsers","statusCode":"200","tags":[],"expectedStatusCodes":["200"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":false,"matchedRequests":[{"name":"Get Users","rawUrl":"https://api.example.com/users","method":"GET","testedStatusCodes":["200"],"testScripts":"// Status code is 200","confidence":0.8999999999999999}],"isPrimaryMatch":true,"matchConfidence":0.8999999999999999},{"method":"POST","path":"/users","name":"createUser","statusCode":"201","tags":[],"expectedStatusCodes":["201","400"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":false,"matchedRequests":[{"name":"Create User","rawUrl":"https://api.example.com/users","method":"POST","testedStatusCodes":["201"],"testScripts":"// Status code is 201","confidence":0.8999999999999999}],"isPrimaryMatch":true,"matchConfidence":0.8999999999999999},{"method":"POST","path":"/users","name":"createUser","statusCode":"400","tags":[],"expectedStatusCodes":["201","400"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":true,"matchedRequests":[],"isPrimaryMatch":false,"matchConfidence":0},{"method":"GET","path":"/users/{id}","name":"getUserById","statusCode":"200","tags":[],"expectedStatusCodes":["200","404"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":true,"matchedRequests":[],"isPrimaryMatch":false,"matchConfidence":0},{"method":"GET","path":"/users/{id}","name":"getUserById","statusCode":"404","tags":[],"expectedStatusCodes":["200","404"],"apiName":"Test API","sourceFile":"test-api.yaml","unmatched":true,"matchedRequests":[],"isPrimaryMatch":false,"matchConfidence":0}];
465465
let apiCount = 1;
466466

467467
// Merge duplicates for display only

test/newman-cli.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,15 @@ paths:
311311

312312
// Check console output
313313
expect(stdout).toContain('Complex Newman Collection');
314-
expect(stdout).toContain('Coverage: 60.00%'); // 3 out of 5 operations covered
314+
expect(stdout).toContain('Coverage: 100.00%'); // All 5 operations covered with smart mapping
315315
expect(stdout).toContain('HTML report saved to: complex-newman-cli-test.html');
316316

317317
// Check that HTML file was created and contains expected data
318318
expect(fs.existsSync(outputFile)).toBe(true);
319319

320320
const htmlContent = fs.readFileSync(outputFile, 'utf8');
321321
expect(htmlContent).toContain('Complex Newman Collection');
322-
expect(htmlContent).toContain('60.00%');
322+
expect(htmlContent).toContain('100.00%');
323323
expect(htmlContent).toContain('Get Users - Success');
324324
expect(htmlContent).toContain('Get User by ID - Not Found');
325325
expect(htmlContent).toContain('Create User - Validation Error');
@@ -411,7 +411,7 @@ paths:
411411
postmanChild.on('close', (postmanCode) => {
412412
try {
413413
expect(postmanCode).toBe(0);
414-
expect(postmanStdout).toContain('Coverage: 0.00%'); // No operations matched due to strict matching
414+
expect(postmanStdout).toContain('Coverage: 20.00%'); // Smart mapping finds some matches
415415

416416
// Now test Newman report
417417
const newmanOutputFile = 'newman-comparison.html';

test/newman-visual.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ describe('Newman Visual Report Tests', () => {
383383

384384
// Newman should have better coverage
385385
expect(newmanCoveragePercent).toBeGreaterThan(postmanCoveragePercent);
386-
expect(postmanCoveragePercent).toBe(0); // No operations matched due to strict matching
386+
expect(postmanCoveragePercent).toBe(20); // Smart mapping finds some matches
387387
expect(newmanCoveragePercent).toBe(40); // 2 out of 5 operations (GET /users 200, POST /users 201)
388388

389389
// Generate HTML reports for both

test/smart-mapping-summary.test.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,23 @@ describe('Smart Mapping Test Coverage Summary', () => {
152152
}, 10000);
153153

154154
test('coverage improvement metrics', async () => {
155-
// Test the core value proposition - coverage improvement
156-
const { stdout: normalOutput } = await execAsync(
157-
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman`,
158-
{ cwd: path.resolve(__dirname, '..') }
159-
);
160-
155+
// Test that smart mapping (enabled by default) provides good coverage
161156
const { stdout: smartOutput } = await execAsync(
162-
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman`,
157+
`node cli.js "${sampleApiPath}" "${sampleNewmanPath}" --newman --verbose`,
163158
{ cwd: path.resolve(__dirname, '..') }
164159
);
165160

166-
const normalCoverage = parseFloat(normalOutput.match(/Coverage: ([\d.]+)%/)[1]);
167161
const smartCoverage = parseFloat(smartOutput.match(/Coverage: ([\d.]+)%/)[1]);
168162

169-
const improvement = smartCoverage - normalCoverage;
163+
// Smart mapping should provide at least 50% coverage (the known improvement)
164+
expect(smartCoverage).toBeGreaterThanOrEqual(50.0);
170165

171-
expect(improvement).toBeGreaterThan(0);
172-
expect(improvement).toBeGreaterThanOrEqual(5.5); // Should improve by at least 5.5 percentage points
166+
// Verify smart mapping statistics are present
167+
expect(smartOutput).toContain('Smart mapping:');
168+
expect(smartOutput).toContain('primary matches');
169+
expect(smartOutput).toContain('secondary matches');
173170

174-
console.log(`📈 Coverage improvement: ${normalCoverage}% → ${smartCoverage}% (+${improvement.toFixed(2)} percentage points)`);
171+
console.log(`📈 Smart mapping coverage achieved: ${smartCoverage}% (enabled by default)`);
172+
console.log(`🎯 Expected minimum coverage: 50.00%`);
175173
}, 15000);
176174
});

0 commit comments

Comments
 (0)