Skip to content

Commit

Permalink
fix: display average time, use duration field for testplane tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Dec 11, 2024
1 parent 9f459ad commit c301e6d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
4 changes: 1 addition & 3 deletions lib/server-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ export const formatTestResult = (
status: TestStatus,
attempt: number = UNKNOWN_ATTEMPT
): ReporterTestResult => {
const startTime = (rawResult as TestplaneTestResult).startTime;

return new TestplaneTestResultAdapter(rawResult, {attempt, status, duration: startTime !== undefined ? Date.now() - startTime : 0});
return new TestplaneTestResultAdapter(rawResult, {attempt, status, duration: (rawResult as TestplaneTestResult).duration});
};

export const saveErrorDetails = async (testResult: ReporterTestResult, reportPath: string): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,15 @@ export const sortTreeNodes = (entitiesContext: EntitiesContext, treeNodes: TreeN
const duration = weight.metadata.duration;
if (duration !== undefined) {
const durationSeconds = Math.round(duration / 1000 * 10) / 10;
let averageDurationSeconds = 0;
if (weight.metadata.runsCount && weight.metadata.runsCount > 1) {
averageDurationSeconds = Math.round(durationSeconds / weight.metadata.runsCount * 10) / 10;
}

if (durationSeconds < 0.1) {
tags.push('<0s in total');
} else {
tags.push(`${durationSeconds}s in total`);
tags.push(`${durationSeconds}s in total${averageDurationSeconds > 0.1 ? `, ${averageDurationSeconds}s on avg.` : ''}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/adapters/test-result/testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('TestplaneTestResultAdapter', () => {
testResult: TestplaneTestResult,
{status = TestStatus.SUCCESS}: {status?: TestStatus} = {}
): TestplaneTestResultAdapter => {
return new TestplaneTestResultAdapter(testResult, {status, attempt: 0}) as TestplaneTestResultAdapter;
return new TestplaneTestResultAdapter(testResult, {status, attempt: 0, duration: 0}) as TestplaneTestResultAdapter;
};

const mkTestResult_ = (result: Partial<TestplaneTestResult>): TestplaneTestResult => _.defaults(result, {
Expand Down
12 changes: 6 additions & 6 deletions test/unit/lib/adapters/test/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('lib/adapters/test/playwright', () => {
});
const testAdapter = PlaywrightTestAdapter.create(test);

testAdapter.createTestResult({status: TestStatus.SUCCESS});
testAdapter.createTestResult({status: TestStatus.SUCCESS, duration: 0});
const testCase = (PlaywrightTestResultAdapter.create as SinonStub).args[0][0] as unknown as TestCase;

assert.calledOnceWith(PlaywrightTestResultAdapter.create as SinonStub, {
Expand All @@ -111,7 +111,7 @@ describe('lib/adapters/test/playwright', () => {
it('should create test result adapter with generated test result', () => {
const testAdapter = PlaywrightTestAdapter.create(mkTest_());

testAdapter.createTestResult({status: TestStatus.SUCCESS, attempt: 100500});
testAdapter.createTestResult({status: TestStatus.SUCCESS, attempt: 100500, duration: 0});

assert.calledOnceWith(PlaywrightTestResultAdapter.create as SinonStub, sinon.match.any, {
attachments: [],
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('lib/adapters/test/playwright', () => {
isUpdated: true
};

testAdapter.createTestResult({status: TestStatus.UPDATED, assertViewResults: [assertViewResult]});
testAdapter.createTestResult({status: TestStatus.UPDATED, assertViewResults: [assertViewResult], duration: 0});
const testResult = (PlaywrightTestResultAdapter.create as SinonStub).args[0][1] as unknown as TestResult;

assert.deepEqual(testResult.attachments as PlaywrightAttachment[], [{
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('lib/adapters/test/playwright', () => {
isUpdated: false
} as unknown as ImageDiffError;

testAdapter.createTestResult({status: TestStatus.FAIL, assertViewResults: [assertViewResult]});
testAdapter.createTestResult({status: TestStatus.FAIL, assertViewResults: [assertViewResult], duration: 0});
const testResult = (PlaywrightTestResultAdapter.create as SinonStub).args[0][1] as unknown as TestResult;

assert.deepEqual(testResult.attachments[1] as PlaywrightAttachment, {
Expand All @@ -194,7 +194,7 @@ describe('lib/adapters/test/playwright', () => {
isUpdated: false
} as unknown as ImageDiffError;

testAdapter.createTestResult({status: TestStatus.FAIL, assertViewResults: [assertViewResult]});
testAdapter.createTestResult({status: TestStatus.FAIL, assertViewResults: [assertViewResult], duration: 0});
const testResult = (PlaywrightTestResultAdapter.create as SinonStub).args[0][1] as unknown as TestResult;

assert.deepEqual(testResult.attachments[1] as PlaywrightAttachment, {
Expand All @@ -221,7 +221,7 @@ describe('lib/adapters/test/playwright', () => {
isUpdated: false
} as unknown as ImageDiffError;

testAdapter.createTestResult({status: TestStatus.FAIL, assertViewResults: [assertViewResult]});
testAdapter.createTestResult({status: TestStatus.FAIL, assertViewResults: [assertViewResult], duration: 0});
const testResult = (PlaywrightTestResultAdapter.create as SinonStub).args[0][1] as unknown as TestResult;

assert.deepEqual(testResult.attachments[1] as PlaywrightAttachment, {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/lib/adapters/test/testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ describe('lib/adapters/test/testplane', () => {
const test = mkState({clone: () => clonedTest}) as unknown as Test;
const status = TestStatus.SUCCESS;
const attempt = 0;
sandbox.stub(TestplaneTestResultAdapter, 'create').withArgs(clonedTest, {status, attempt}).returns(testResultAdapter);
sandbox.stub(TestplaneTestResultAdapter, 'create').withArgs(clonedTest, {status, attempt, duration: 0}).returns(testResultAdapter);

const formattedTestResult = TestplaneTestAdapter.create(test).createTestResult({status, attempt});
const formattedTestResult = TestplaneTestAdapter.create(test).createTestResult({status, attempt, duration: 0});

assert.equal(formattedTestResult, testResultAdapter);
assert.calledOnceWith(TestplaneTestResultAdapter.create as SinonStub, clonedTest, {status, attempt});
assert.calledOnceWith(TestplaneTestResultAdapter.create as SinonStub, clonedTest, {status, attempt, duration: 0});
});
});
});
3 changes: 2 additions & 1 deletion test/unit/lib/sqlite-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ describe('lib/sqlite-client', () => {
{cid: 10, name: 'screenshot', type: 'INT'},
{cid: 11, name: 'multipleTabs', type: 'INT'},
{cid: 12, name: 'status', type: 'TEXT'},
{cid: 13, name: 'timestamp', type: 'INT'}
{cid: 13, name: 'timestamp', type: 'INT'},
{cid: 14, name: 'duration', type: 'INT'}
];

const columns = db.prepare('PRAGMA table_info(suites);').all();
Expand Down

0 comments on commit c301e6d

Please sign in to comment.