fix(tapParser/logger): Fix test duration reporting and summary formatting in TAP parser and logger
This commit is contained in:
@@ -22,6 +22,7 @@ export class TapParser {
|
||||
private logger: TsTestLogger;
|
||||
private protocolParser: ProtocolParser;
|
||||
private protocolVersion: string | null = null;
|
||||
private startTime: number;
|
||||
|
||||
/**
|
||||
* the constructor for TapParser
|
||||
@@ -29,6 +30,7 @@ export class TapParser {
|
||||
constructor(public fileName: string, logger?: TsTestLogger) {
|
||||
this.logger = logger;
|
||||
this.protocolParser = new ProtocolParser();
|
||||
this.startTime = Date.now();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,6 +482,7 @@ export class TapParser {
|
||||
|
||||
public async evaluateFinalResult() {
|
||||
this.receivedTests = this.testStore.length;
|
||||
const duration = Date.now() - this.startTime;
|
||||
|
||||
// check wether all tests ran
|
||||
if (this.expectedTests === this.receivedTests) {
|
||||
@@ -494,23 +497,23 @@ export class TapParser {
|
||||
if (!this.expectedTests && this.receivedTests === 0) {
|
||||
if (this.logger) {
|
||||
this.logger.error('No tests were defined. Therefore the testfile failed!');
|
||||
this.logger.testFileEnd(0, 1, 0); // Count as 1 failure
|
||||
this.logger.testFileEnd(0, 1, duration); // Count as 1 failure
|
||||
}
|
||||
} else if (this.expectedTests !== this.receivedTests) {
|
||||
if (this.logger) {
|
||||
this.logger.error('The amount of received tests and expectedTests is unequal! Therefore the testfile failed');
|
||||
const errorCount = this.getErrorTests().length || 1; // At least 1 error
|
||||
this.logger.testFileEnd(this.receivedTests - errorCount, errorCount, 0);
|
||||
this.logger.testFileEnd(this.receivedTests - errorCount, errorCount, duration);
|
||||
}
|
||||
} else if (this.getErrorTests().length === 0) {
|
||||
if (this.logger) {
|
||||
this.logger.tapOutput('All tests are successfull!!!');
|
||||
this.logger.testFileEnd(this.receivedTests, 0, 0);
|
||||
this.logger.testFileEnd(this.receivedTests, 0, duration);
|
||||
}
|
||||
} else {
|
||||
if (this.logger) {
|
||||
this.logger.tapOutput(`${this.getErrorTests().length} tests threw an error!!!`, true);
|
||||
this.logger.testFileEnd(this.receivedTests - this.getErrorTests().length, this.getErrorTests().length, 0);
|
||||
this.logger.testFileEnd(this.receivedTests - this.getErrorTests().length, this.getErrorTests().length, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user