Merge pull request #846 from microsoft/benjaminbi/issue840

[Feature] Add new unit test for internal error and telemetry events
This commit is contained in:
benjaminbi 2023-02-09 18:00:20 +08:00 коммит произвёл GitHub
Родитель 1626f783df 3d76efbb83
Коммит 0fc3c23a41
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 85 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,85 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
import { ErrorHelper } from "../../../src/common/error/errorHelper";
import { InternalErrorCode } from "../../../src/common/error/internalErrorCode";
import * as assert from "assert";
suite("errorHelper", function () {
suite("commonContext", function () {
const nestedErrorWithArgs = ErrorHelper.getNestedError(
new Error("Nested ES Error"),
InternalErrorCode.CommandFailed,
"Command failed with ES Error",
);
const commandFailedWithDetails = ErrorHelper.getInternalError(
InternalErrorCode.CommandFailedWithDetails,
"{command}",
"{details}",
);
const nvsHomeNotFoundMessage = ErrorHelper.getInternalError(
InternalErrorCode.NvsHomeNotFoundMessage,
);
const nvmWindowsNotFoundMessage = ErrorHelper.getInternalError(
InternalErrorCode.NvmWindowsNotFoundMessage,
);
const nvmHomeNotFoundMessage = ErrorHelper.getInternalError(
InternalErrorCode.NvmHomeNotFoundMessage,
);
const warning = ErrorHelper.getWarning("Warning");
const nestedWarning = ErrorHelper.getNestedWarning(new Error("Nested ES Error"), "Warning");
test("nested error object with arguments should have correct error message on English", (done: Mocha.Done) => {
assert.strictEqual(
nestedErrorWithArgs.message,
"Error while executing command 'Command failed with ES Error': Nested ES Error",
);
done();
});
test("internal error object with failed command and details should have correct CommandFailedWithDetails errors in English", (done: Mocha.Done) => {
assert.strictEqual(
commandFailedWithDetails.message,
"Error while executing command '{command}'.\nDetails: {details} (error code 102)",
);
done();
});
test("internal error object with failed command and details should have correct NvsHomeNotFoundMessage errors in English", (done: Mocha.Done) => {
assert.strictEqual(
nvsHomeNotFoundMessage.message,
"Attribute runtimeVersion requires Node.js version manager 'nvs' (error code 103)",
);
done();
});
test("internal error object with failed command and details should have correct NvmWindowsNotFoundMessage errors in English", (done: Mocha.Done) => {
assert.strictEqual(
nvmWindowsNotFoundMessage.message,
"Attribute runtimeVersion requires Node.js version manager nvm-windows or nvs (error code 104)",
);
done();
});
test("warning object should have correct error message on English", (done: Mocha.Done) => {
assert.strictEqual(warning.errorCode, -1);
assert.strictEqual(warning.message, "Warning");
done();
});
test("nested warning object should have correct error message on English", (done: Mocha.Done) => {
assert.strictEqual(nestedWarning.errorCode, -1);
assert.strictEqual(nestedWarning.message, "Warning: Nested ES Error");
done();
});
test("internal error object with failed command and details should have correct NvmHomeNotFoundMessage errors in English", (done: Mocha.Done) => {
assert.strictEqual(
nvmHomeNotFoundMessage.message,
"Attribute runtimeVersion requires Node.js version manager nvm or nvs (error code 105)",
);
done();
});
});
});