From e416b90106b45596be5276e46bc43bb01128d090 Mon Sep 17 00:00:00 2001 From: Yuri Skorokhodov Date: Fri, 14 Dec 2018 15:59:52 +0300 Subject: [PATCH] Add tests for errorHelper.ts, fix messages for warnings, fix gulp task build asynchronicity (#862) --- gulpfile.js | 12 ++++++++---- src/common/error/errorHelper.ts | 1 + src/common/error/internalError.ts | 2 +- test/common/error/errorHelper.test.ts | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 05c76ec7..f76cec0a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -133,13 +133,17 @@ gulp.task("tslint", function () { // We should also make sure that we always generate urls in all the path properties (We shouldn"t have \\s. This seems to // be an issue on Windows platforms) gulp.task("build", gulp.series("check-imports", "check-copyright", "tslint", function (done) { - build(true, true); - done(); + build(true, true) + .once("finish", () => { + done(); + }); })); gulp.task("build-dev", gulp.series("check-imports", "check-copyright", function (done) { - build(false, false); - done(); + build(false, false) + .once("finish", () => { + done(); + }); })); gulp.task("quick-build", gulp.series("build-dev")); diff --git a/src/common/error/errorHelper.ts b/src/common/error/errorHelper.ts index d635a0f3..0699ed8b 100644 --- a/src/common/error/errorHelper.ts +++ b/src/common/error/errorHelper.ts @@ -20,6 +20,7 @@ export class ErrorHelper { public static wrapError(error: InternalError, innerError: Error): NestedError { return NestedError.getWrappedError(error, innerError); } + public static getWarning(message: string, ...optionalArgs: any[]): InternalError { return new InternalError(-1, message, InternalErrorLevel.Warning); } diff --git a/src/common/error/internalError.ts b/src/common/error/internalError.ts index 4eb76f26..ae9267ce 100644 --- a/src/common/error/internalError.ts +++ b/src/common/error/internalError.ts @@ -18,7 +18,7 @@ export class InternalError extends Error { super(message); this.errorCode = errorCode; this.errorLevel = errorLevel; - this.message = message + ` (error code ${this.errorCode})`; + this.message = errorCode > 0 ? (message + ` (error code ${this.errorCode})`) : message; } } diff --git a/test/common/error/errorHelper.test.ts b/test/common/error/errorHelper.test.ts index a0000e15..0a886f70 100644 --- a/test/common/error/errorHelper.test.ts +++ b/test/common/error/errorHelper.test.ts @@ -8,6 +8,9 @@ suite("errorHelper", function() { suite("commonContext", function() { const internalErrorWithArgs = ErrorHelper.getInternalError(InternalErrorCode.NotAllSuccessPatternsMatched, "android", "ios"); const internalErrorWithoutArgs = ErrorHelper.getInternalError(InternalErrorCode.UnsupportedCommandStatus); + const nestedErrorWithArgs = ErrorHelper.getNestedError(new Error("Nested ES Error"), InternalErrorCode.CommandFailed, "Command failed with ES Error"); + const warning = ErrorHelper.getWarning("Warning"); + const nestedWarning = ErrorHelper.getNestedWarning(new Error("Nested ES Error"), "Warning"); test("internal error object with arguments should have correct NotAllSuccessPatternsMatched error message on English", (done: MochaDone) => { assert.equal(internalErrorWithArgs.message, "Unknown error: not all success patterns were matched. \n It means that \"react-native run-android\" command failed. \n Please, check the View -> Toggle Output -> React Native, \n View -> Toggle Output -> React Native: Run ios output windows. (error code 712)"); @@ -19,6 +22,22 @@ suite("errorHelper", function() { done(); }); + test("nested error object with arguments should have correct error message on English", (done: MochaDone) => { + assert.equal(nestedErrorWithArgs.message, "Error while executing command 'Command failed with ES Error': Nested ES Error"); + done(); + }); + + test("warning object should have correct error message on English", (done: MochaDone) => { + assert.equal(warning.errorCode, -1); + assert.equal(warning.message, "Warning"); + done(); + }); + + test("nested warning object should have correct error message on English", (done: MochaDone) => { + assert.equal(nestedWarning.errorCode, -1); + assert.equal(nestedWarning.message, "Warning: Nested ES Error"); + done(); + }); }); });