Skip to content
Permalink
Browse files

Improve the error message for when a test report is not found.

  • Loading branch information...
thiagodp committed May 28, 2019
1 parent 52d9ec8 commit ef6580b867fd5f9cff987fbb7f5c6b501a8da2aa
Showing with 27 additions and 2 deletions.
  1. +14 −1 dist/plugins/codeceptjs/ReportConverter.js
  2. +13 −1 plugins/codeceptjs/ReportConverter.ts
@@ -32,7 +32,13 @@ class ReportConverter {
*/
convertFrom(resultFilePath, pluginConfigFilePath) {
return __awaiter(this, void 0, void 0, function* () {
const source = yield this.readJsonFile(resultFilePath);
let source;
try {
source = yield this.readJsonFile(resultFilePath);
}
catch (e) {
throw new Error('Cannot read the test report file. ' + e.message);
}
let pluginConfig = {};
try {
pluginConfig = yield this.readJsonFile(pluginConfigFilePath);
@@ -217,8 +223,15 @@ class ReportConverter {
}
readJsonFile(path) {
return __awaiter(this, void 0, void 0, function* () {
const fileExists = this._fs.existsSync(path);
if (!fileExists) {
throw new Error('File not found: ' + path);
}
const readFileAsync = util_1.promisify(this._fs.readFile);
const content = yield readFileAsync(path, this._encoding);
if (!content || content.length < 1) {
throw new Error('Empty JSON file: ' + path);
}
return JSON.parse(content.toString());
});
}
@@ -30,7 +30,12 @@ export class ReportConverter {
pluginConfigFilePath: string
): Promise< TestScriptExecutionResult > {

const source: any = await this.readJsonFile( resultFilePath );
let source: any;
try {
source = await this.readJsonFile( resultFilePath );
} catch ( e ) {
throw new Error( 'Cannot read the test report file. ' + e.message );
}

let pluginConfig = {};
try {
@@ -248,8 +253,15 @@ export class ReportConverter {
}

private async readJsonFile( path: string ): Promise< any > {
const fileExists: boolean = this._fs.existsSync( path );
if ( ! fileExists ) {
throw new Error( 'File not found: ' + path );
}
const readFileAsync = promisify( this._fs.readFile );
const content = await readFileAsync( path, this._encoding );
if ( ! content || content.length < 1 ) {
throw new Error( 'Empty JSON file: ' + path );
}
return JSON.parse( content.toString() );
}

0 comments on commit ef6580b

Please sign in to comment.
You can’t perform that action at this time.