Skip to content

Commit

Permalink
Close #36
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodp committed Apr 20, 2019
1 parent b6f31e4 commit 059099e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 17 deletions.
15 changes: 12 additions & 3 deletions dist/modules/app/AppController.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const TestResultAnalyzer_1 = require("../testscript/TestResultAnalyzer");
const GuidedConfig_1 = require("./GuidedConfig");
const fs_1 = require("fs");
const util_1 = require("util");
const path_1 = require("path");
/**
* Application controller
*
Expand Down Expand Up @@ -243,12 +244,20 @@ class AppController {
cli.newLine(cli.symbolInfo, 'Script execution disabled.');
}
if (options.analyzeResult) { // Requires a plugin
let reportFile;
if (!executionResult) {
cli.newLine(cli.symbolError, 'Could not retrieve execution results.');
return false;
const defaultReportFile = path_1.join(options.dirResult, yield plugin.defaultReportFile());
if (!fs_1.existsSync(defaultReportFile)) {
cli.newLine(cli.symbolError, 'Could not retrieve execution results.');
return false;
}
reportFile = defaultReportFile;
}
else {
reportFile = executionResult.sourceFile;
}
try {
let reportedResult = yield plugin.convertReportFile(executionResult.sourceFile);
let reportedResult = yield plugin.convertReportFile(reportFile);
(new TestResultAnalyzer_1.TestResultAnalyzer()).adjustResult(reportedResult, abstractTestScripts);
(new CliScriptExecutionReporter_1.CliScriptExecutionReporter(cli)).scriptExecuted(reportedResult);
}
Expand Down
6 changes: 6 additions & 0 deletions dist/plugins/codeceptjs/CodeceptJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class CodeceptJS {
return yield reportConverter.convertFrom(filePath, this._descriptorPath);
});
}
/** @inheritDoc */
defaultReportFile() {
return __awaiter(this, void 0, void 0, function* () {
return 'output.json';
});
}
/**
* Tries to generate a source code file from an abstract test script.
*
Expand Down
25 changes: 17 additions & 8 deletions dist/plugins/fake/Fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ const TestScriptExecution_1 = require("../../modules/testscript/TestScriptExecut
* @author Thiago Delgado Pinto
*/
class Fake {
constructor() {
/** @inheritDoc */
this.executeCode = (options) => __awaiter(this, void 0, void 0, function* () {
/** @inheritDoc */
generateCode(abstractTestScripts, options, errors) {
return __awaiter(this, void 0, void 0, function* () {
return []; // No files
});
}
;
/** @inheritDoc */
executeCode(options) {
return __awaiter(this, void 0, void 0, function* () {
let r = new TestScriptExecution_1.TestScriptExecutionResult();
r.sourceFile = 'nofile.json';
r.schemaVersion = '1.0';
Expand All @@ -36,16 +43,18 @@ class Fake {
return r;
});
}
;
/** @inheritDoc */
generateCode(abstractTestScripts, options, errors) {
convertReportFile(filePath) {
return __awaiter(this, void 0, void 0, function* () {
return []; // No files
throw new Error("Method not implemented: convertReportFile.");
});
}
;
/** @inheritDoc */
convertReportFile(filePath) {
throw new Error("Method not implemented: convertReportFile.");
defaultReportFile() {
return __awaiter(this, void 0, void 0, function* () {
return 'fake-output.json';
});
}
}
exports.Fake = Fake;
22 changes: 18 additions & 4 deletions modules/app/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import * as updateNotifier from 'update-notifier';
import { AbstractTestScript } from '../testscript/AbstractTestScript';
import { TestResultAnalyzer } from '../testscript/TestResultAnalyzer';
import { GuidedConfig } from './GuidedConfig';
import { writeFile } from 'fs';
import { writeFile, existsSync } from 'fs';
import { promisify } from 'util';
import { join } from 'path';

/**
* Application controller
Expand Down Expand Up @@ -276,12 +277,25 @@ export class AppController {
}

if ( options.analyzeResult ) { // Requires a plugin

let reportFile: string;
if ( ! executionResult ) {
cli.newLine( cli.symbolError, 'Could not retrieve execution results.' );
return false;

const defaultReportFile: string = join(
options.dirResult, await plugin.defaultReportFile() );

if ( ! existsSync( defaultReportFile ) ) {
cli.newLine( cli.symbolError, 'Could not retrieve execution results.' );
return false;
}

reportFile = defaultReportFile;
} else {
reportFile = executionResult.sourceFile;
}

try {
let reportedResult = await plugin.convertReportFile( executionResult.sourceFile );
let reportedResult = await plugin.convertReportFile( reportFile );
( new TestResultAnalyzer() ).adjustResult( reportedResult, abstractTestScripts );
( new CliScriptExecutionReporter( cli ) ).scriptExecuted( reportedResult );
} catch ( err ) {
Expand Down
6 changes: 6 additions & 0 deletions modules/plugin/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ export interface Plugin {
*/
convertReportFile( filePath: string ): Promise< TestScriptExecutionResult >;

/**
* Returns the default report file name. Concordia may look for it in the
* output/result directory when the parameter `--just-report` is given.
*/
defaultReportFile(): Promise< string >;

}
5 changes: 5 additions & 0 deletions plugins/codeceptjs/CodeceptJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export class CodeceptJS implements Plugin {
return await reportConverter.convertFrom( filePath, this._descriptorPath );
}

/** @inheritDoc */
public async defaultReportFile(): Promise< string > {
return 'output.json';
}

/**
* Tries to generate a source code file from an abstract test script.
*
Expand Down
9 changes: 7 additions & 2 deletions plugins/fake/Fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Fake implements Plugin {
};

/** @inheritDoc */
public executeCode = async (options: TestScriptExecutionOptions): Promise< TestScriptExecutionResult > => {
public async executeCode(options: TestScriptExecutionOptions): Promise< TestScriptExecutionResult > {

let r = new TestScriptExecutionResult();
r.sourceFile = 'nofile.json';
Expand All @@ -42,8 +42,13 @@ export class Fake implements Plugin {
};

/** @inheritDoc */
public convertReportFile(filePath: string): Promise< TestScriptExecutionResult > {
public async convertReportFile(filePath: string): Promise< TestScriptExecutionResult > {
throw new Error("Method not implemented: convertReportFile.");
}

/** @inheritDoc */
public async defaultReportFile(): Promise< string > {
return 'fake-output.json';
}

}

0 comments on commit 059099e

Please sign in to comment.