Skip to content

Commit

Permalink
Merge pull request #577 from christoment/bugfix/fix-finish-time-on-trx
Browse files Browse the repository at this point in the history
fix: Calculate finish time based on the test results perfStats
  • Loading branch information
no23reason authored Jun 8, 2023
2 parents 4129303 + b60478d commit bdaba1e
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
108 changes: 108 additions & 0 deletions src/__tests__/trx-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,112 @@ describe("trx-generator", (): void => {
done();
});
});

it("calculate finishTime from test results", (done) => {
const input: AggregatedResult = {
numFailedTestSuites: 0,
numFailedTests: 0,
numPassedTestSuites: 1,
numPassedTests: 1,
numPendingTestSuites: 0,
numPendingTests: 0,
numRuntimeErrorTestSuites: 1,
numTodoTests: 0,
numTotalTestSuites: 2,
numTotalTests: 1,
openHandles: [],
snapshot: emptySnapshotSummary,
startTime: 1511376995239,
success: false,
testResults: [
{
leaks: false,
numFailingTests: 0,
numPassingTests: 1,
numPendingTests: 0,
numTodoTests: 0,
openHandles: [],
perfStats: {
end: 1511376996104,
start: 1511376995923,
runtime: 181,
slow: false,
},
snapshot: emptySnapshot,
testFilePath: "C:\\Users\\Github\\test\\test.spec.js",
testResults: [
{
ancestorTitles: [],
duration: 181,
failureMessages: [],
fullName: "first",
numPassingAsserts: 0,
status: "passed",
title: "first",
location: {
column: 0,
line: 0,
},
failureDetails: [],
},
],
sourceMaps: {},
skipped: false,
},
{
leaks: false,
numFailingTests: 0,
numPassingTests: 1,
numPendingTests: 0,
numTodoTests: 0,
openHandles: [],
perfStats: {
end: 1511376996304,
start: 1511376996104,
runtime: 200,
slow: false,
},
snapshot: emptySnapshot,
testFilePath: "C:\\Users\\Github\\test\\test.spec.js",
testResults: [
{
ancestorTitles: [],
duration: 181,
failureMessages: [],
fullName: "first",
numPassingAsserts: 0,
status: "passed",
title: "first",
location: {
column: 0,
line: 0,
},
failureDetails: [],
},
],
sourceMaps: {},
skipped: false,
},
],
wasInterrupted: false,
};

const result = generateTrx(input);

xml2js.parseString(result, (err, parsed) => {
expect(err).toBeFalsy();
expect(parsed).toBeTruthy();
expect(parsed.TestRun).toBeTruthy();

const timeElement = parsed.TestRun.Times[0].$;
expect(timeElement).toBeTruthy();
expect(timeElement.start).toBeTruthy();
expect(timeElement.finish).toBeTruthy();
expect(timeElement.start).not.toEqual(timeElement.finish);
expect(timeElement.start).toEqual(new Date(1511376995239).toISOString());
expect(timeElement.finish).toEqual(new Date(1511376995239 + 200 + 181).toISOString());

done();
});
});
});
5 changes: 4 additions & 1 deletion src/trx-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ const renderTimes = (
testRunResult: AggregatedResult,
): void => {
const startTime = new Date(testRunResult.startTime).toISOString();
const totalDuration = testRunResult.testResults.reduce((acc, tr) => acc + tr.perfStats.runtime, 0);
const finishTime = new Date(testRunResult.startTime + totalDuration).toISOString();

parentNode
.ele("Times")
.att("creation", startTime)
.att("queuing", startTime)
.att("start", startTime)
.att("finish", startTime);
.att("finish", finishTime);
};

const renderResultSummary = (
Expand Down

0 comments on commit bdaba1e

Please sign in to comment.