Skip to content

Commit

Permalink
fix: passes, failed, skipped tests counting (#146)
Browse files Browse the repository at this point in the history
* fix: passes, failed, skipped tests counting

* fix: set empty attempts on skipped tests

* fix: tests count

* fix: failing unit tests

* fix: change skipped for pending test status

* fix: test

* fix: add _s as pending and status as skipped on skipped test

---------

Co-authored-by: miguelangarano <[email protected]>
  • Loading branch information
miguelangaranocurrents and miguelangarano authored Feb 6, 2025
1 parent 94b083a commit ca0e246
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const instanceReportTestWithFailure: InstanceReportTest = {
title: [suiteNameWithFailure, 'Test with failure'],
state: 'failed',
isFlaky: false,
expectedStatus: 'skipped',
expectedStatus: 'passed',
timeout: 0,
location: { ...location, file: 'testfile.ts' },
retries: 1,
Expand Down
4 changes: 2 additions & 2 deletions packages/cmd/src/services/convert/__tests__/instances.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('createSuiteJson', () => {
],
},
(suiteJson: InstanceReport) => {
expect(suiteJson.results.stats.passes).toBe(2);
expect(suiteJson.results.stats.passes).toBe(0);
},
],
[
Expand All @@ -182,7 +182,7 @@ describe('createSuiteJson', () => {
).toBeCloseTo(expectedEndTime, -3);
expect(suiteJson.groupId).toBe(groupId);
expect(suiteJson.spec).toBe(spec);
expect(suiteJson.results.stats.failures).toBe(1);
expect(suiteJson.results.stats.failures).toBe(2);
},
],
])('%s', async (_, suite, assertion) => {
Expand Down
13 changes: 5 additions & 8 deletions packages/cmd/src/services/convert/postman/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ export function createSuiteJson(

let accTestTime = 0;

const passes = testcases.filter(
(tc) => (tc.failure ?? []).length === 0
).length;
const failures = testcases.filter(
(tc) => (tc.failure ?? []).length > 0
).length;
const failures = testcases.filter((tc) => 'failure' in tc).length;
const skipped = testcases.filter((tc) => 'skipped' in tc).length;
const passes = testcases.length - failures - skipped;

const suiteJson: InstanceReport = {
groupId,
Expand All @@ -74,9 +71,9 @@ export function createSuiteJson(
results: {
stats: {
suites: 1,
tests: suite.tests ? parseInt(suite.tests) : 0,
tests: testcases.length,
passes,
pending: 0,
pending: skipped,
skipped: 0,
failures,
flaky: 0,
Expand Down
29 changes: 25 additions & 4 deletions packages/cmd/src/services/convert/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export function getTestCase(
const failures = ensureArray<string | Failure>(testCase.failure);
const hasFailure = failures.length > 0;
const suiteTimestamp = suite?.timestamp ?? '';
const skipped = 'skipped' in testCase;

const state = skipped ? 'pending' : hasFailure ? 'failed' : 'passed';

return {
_t: getTimestampValue(suiteTimestamp),
Expand All @@ -26,17 +29,18 @@ export function getTestCase(
suiteName
),
title: getTestTitle(testCase.name, suiteName),
state: hasFailure ? 'failed' : 'passed',
state: state,
isFlaky: getTestFlakiness(),
expectedStatus: hasFailure ? 'skipped' : 'passed',
expectedStatus: 'passed',
timeout: getTimeout(),
location: getTestCaseLocation(suite?.file ?? ''),
retries: getTestRetries(failures),
attempts: getTestAttempts(
testCase,
failures,
getISODateValue(suiteTimestamp),
time
time,
skipped
),
};
}
Expand Down Expand Up @@ -110,9 +114,26 @@ function getTestAttempts(
testCase: TestCase,
failures: (Failure | string)[],
suiteTimestamp: string,
time: number
time: number,
skipped?: boolean
): InstanceReportTestAttempt[] {
const testCaseTime = testCase.time ? timeToMilliseconds(testCase.time) : 0;
if (skipped) {
return [
{
_s: 'pending',
attempt: 0,
startTime: suiteTimestamp,
steps: [],
duration: testCaseTime,
status: 'skipped',
stdout: getStdOut(testCase?.['system-out']),
stderr: [],
errors: [],
error: undefined,
},
];
}
if (failures.length === 0) {
return [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/cmd/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type TestCaseStatus = 'passed' | 'failed' | 'pending';
export type TestRunnerStatus = 'passed' | 'failed' | 'skipped';

// currents values suitable for jest expected status
export type ExpectedStatus = 'passed' | 'skipped';
export type ExpectedStatus = 'passed' | 'pending' | 'failed';

// jest test case statuses available in results
export type JestTestCaseStatus = 'pending' | 'todo' | 'failed' | 'passed';
Expand Down

0 comments on commit ca0e246

Please sign in to comment.