Skip to content

Commit

Permalink
Fix #24
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodp committed Feb 25, 2019
1 parent c21d4ca commit 2e2fea6
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 41 deletions.
66 changes: 46 additions & 20 deletions dist/plugins/codeceptjs/ReportConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const fs = require("fs");
const util_1 = require("util");
const FileInstrumentationReader_1 = require("../../modules/plugin/FileInstrumentationReader");
/**
* Converts a CodeceptJS execution result to Concordia's format.
* Converts a Mocha Multi Report to Concordia's format.
*
* @see https://github.com/stanleyhlng/mocha-multi-reporters
*/
class ReportConverter {
constructor(_fs = fs, _encoding = 'utf-8') {
Expand Down Expand Up @@ -48,32 +50,56 @@ class ReportConverter {
});
}
/**
* Fills test result metadata.
* Fills the basic metadata
*
* @param source The CodeceptJS' result in JSON format.
* @param result The Concordia's result to fill.
* @param source Object read from the original report.
* @param result Concordia format.
*/
fillMetadata(source, result) {
result.sourceFile = source.resultFilePath;
}
/**
* Fills test result status.
* Fills the status
*
* @param source The CodeceptJS' result in JSON format.
* @param result The Concordia's result to fill.
* @param source Object read from the original report.
* @param result Concordia format.
*/
fillStatus(source, result) {
result.started = source.stats.start;
result.finished = source.stats.end;
result.durationMs = source.stats.duration;
const stats = source.stats;
if (!stats) {
result.started = 'Unknown';
result.finished = (new Date()).toUTCString();
// Get the needed details from `tests`
if (!source.tests) {
return;
}
const tests = source.tests;
// Duration
let totalDuration = 0;
for (let t of tests) {
totalDuration += t.duration;
}
result.durationMs = totalDuration;
// Total tests
if (!result.total) {
result.total = new TestScriptExecution_1.TotalExecutionResult();
}
result.total.tests = tests.length;
result.total.passed = (source.passes || []).length;
result.total.failed = (source.failures || []).length;
return;
}
result.started = stats.start;
result.finished = stats.end;
result.durationMs = stats.duration;
// Because of a bug in CodeceptJS JSON's counting
let failed = source.stats.failures;
if (failed === source.stats.tests && source.stats.passes > 0) {
failed -= source.stats.passes;
let failed = stats.failures;
if (failed === stats.tests && stats.passes > 0) {
failed -= stats.passes;
}
result.total = {
tests: source.stats.tests,
passed: source.stats.passes,
tests: stats.tests,
passed: stats.passes,
failed: failed,
skipped: 0,
error: 0,
Expand All @@ -83,8 +109,8 @@ class ReportConverter {
/**
* Fills plugin's info.
*
* @param source The CodeceptJS plugin configuration.
* @param result The Concordia's result to fill.
* @param source Object read from the original report.
* @param result Concordia format.
*/
fillPluginInfo(pluginConfig, result) {
result.plugin = {
Expand All @@ -97,8 +123,8 @@ class ReportConverter {
/**
* Fills execution results.
*
* @param source The CodeceptJS' result in JSON format.
* @param result The Concordia's result to fill.
* @param source Object read from the original report.
* @param result Concordia format.
*/
fillResults(source, result) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -136,7 +162,7 @@ class ReportConverter {
/**
* Pushes a Test Method Result to a Test Script Execution Result.
*
* @param result The Concordia's result to fill.
* @param result Concordia format.
* @param testMethodResult TestMethodResult to be pushed.
* @param suiteName Test Suite Result name.
*/
Expand Down
73 changes: 52 additions & 21 deletions plugins/codeceptjs/ReportConverter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { TestMethodResult, TestScriptExecutionResult, TestSuiteResult } from '../../modules/testscript/TestScriptExecution';
import { TestMethodResult, TestScriptExecutionResult, TestSuiteResult, TotalExecutionResult } from '../../modules/testscript/TestScriptExecution';
import { DefaultInstrumentationReader } from '../../modules/plugin/InstrumentationReader';
import { Location } from '../../modules/ast/Location';
import * as fs from 'fs';
import { promisify } from 'util';
import { FileInstrumentationReader } from '../../modules/plugin/FileInstrumentationReader';

/**
* Converts a CodeceptJS execution result to Concordia's format.
* Converts a Mocha Multi Report to Concordia's format.
*
* @see https://github.com/stanleyhlng/mocha-multi-reporters
*/
export class ReportConverter {

Expand Down Expand Up @@ -49,35 +51,64 @@ export class ReportConverter {
}

/**
* Fills test result metadata.
* Fills the basic metadata
*
* @param source The CodeceptJS' result in JSON format.
* @param result The Concordia's result to fill.
* @param source Object read from the original report.
* @param result Concordia format.
*/
private fillMetadata( source: any, result: TestScriptExecutionResult ): void {
result.sourceFile = source.resultFilePath;
}

/**
* Fills test result status.
* Fills the status
*
* @param source The CodeceptJS' result in JSON format.
* @param result The Concordia's result to fill.
* @param source Object read from the original report.
* @param result Concordia format.
*/
private fillStatus( source: any, result: TestScriptExecutionResult ): void {
result.started = source.stats.start;
result.finished = source.stats.end;
result.durationMs = source.stats.duration;
const stats = source.stats;
if ( ! stats ) {
result.started = 'Unknown';
result.finished = ( new Date() ).toUTCString();

// Get the needed details from `tests`
if ( ! source.tests ) {
return;
}
const tests = source.tests;

// Duration
let totalDuration = 0;
for ( let t of tests ) {
totalDuration += t.duration;
}
result.durationMs = totalDuration;

// Total tests
if ( ! result.total ) {
result.total = new TotalExecutionResult();
}
result.total.tests = tests.length;
result.total.passed = ( source.passes || [] ).length;
result.total.failed = ( source.failures || [] ).length;

return;
}

result.started = stats.start;
result.finished = stats.end;
result.durationMs = stats.duration;

// Because of a bug in CodeceptJS JSON's counting
let failed = source.stats.failures;
if ( failed === source.stats.tests && source.stats.passes > 0 ) {
failed -= source.stats.passes;
let failed = stats.failures;
if ( failed === stats.tests && stats.passes > 0 ) {
failed -= stats.passes;
}

result.total = {
tests: source.stats.tests,
passed: source.stats.passes,
tests: stats.tests,
passed: stats.passes,
failed: failed,
skipped: 0,
error: 0,
Expand All @@ -88,8 +119,8 @@ export class ReportConverter {
/**
* Fills plugin's info.
*
* @param source The CodeceptJS plugin configuration.
* @param result The Concordia's result to fill.
* @param source Object read from the original report.
* @param result Concordia format.
*/
private fillPluginInfo( pluginConfig: any, result: TestScriptExecutionResult ): void {
result.plugin = {
Expand All @@ -103,8 +134,8 @@ export class ReportConverter {
/**
* Fills execution results.
*
* @param source The CodeceptJS' result in JSON format.
* @param result The Concordia's result to fill.
* @param source Object read from the original report.
* @param result Concordia format.
*/
private async fillResults( source: any, result: TestScriptExecutionResult ): Promise< void > {

Expand Down Expand Up @@ -151,7 +182,7 @@ export class ReportConverter {
/**
* Pushes a Test Method Result to a Test Script Execution Result.
*
* @param result The Concordia's result to fill.
* @param result Concordia format.
* @param testMethodResult TestMethodResult to be pushed.
* @param suiteName Test Suite Result name.
*/
Expand Down

0 comments on commit 2e2fea6

Please sign in to comment.