Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zowe Explorer Output Logger #2192

Merged
merged 61 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
08639b6
create output logger for ZE in vsc
JillieBeanSim Mar 3, 2023
1416c08
update LoggerUtils.ts to handle all logging needs
JillieBeanSim Mar 3, 2023
54f0e77
copy edits on timestamping and order
JillieBeanSim Mar 3, 2023
5050445
logger cleanup and ProfilesUtils use logger
JillieBeanSim Mar 6, 2023
a2754ea
fix unit tests
JillieBeanSim Mar 6, 2023
35f236b
Merge branch 'main' into output-logger
JillieBeanSim Mar 6, 2023
e221eeb
update Profiles.ts to use ZoweLogger
JillieBeanSim Mar 6, 2023
6a59d80
ZoweExplorerExtender & ApiRegister to use ZoweLogger
JillieBeanSim Mar 6, 2023
3f9396e
update files in abstract folder to use ZoweLogger, also called by err…
JillieBeanSim Mar 6, 2023
1167263
update command folder files to use ZoweLogger
JillieBeanSim Mar 6, 2023
49d4413
dataset folder files to use ZoweLogger
JillieBeanSim Mar 6, 2023
41a1575
run pre-publish
JillieBeanSim Mar 6, 2023
671526b
job dir files to use ZoweLogger
JillieBeanSim Mar 6, 2023
987931d
shared dir files to use ZoweLogger
JillieBeanSim Mar 6, 2023
6a07056
uss dir files to use ZoweLogger
JillieBeanSim Mar 6, 2023
5392d4b
utils dir files to use ZoweLogger
JillieBeanSim Mar 6, 2023
aff7266
created logger setting for output view logging
JillieBeanSim Mar 6, 2023
c11136d
fix type error
JillieBeanSim Mar 6, 2023
eeb67cc
refresh extension when log level setting changes
JillieBeanSim Mar 7, 2023
f1701d3
fix unit tests
JillieBeanSim Mar 7, 2023
3f1f44a
add some trace logging
JillieBeanSim Mar 8, 2023
46a1204
Merge remote-tracking branch 'origin/main' into output-logger
JillieBeanSim Mar 8, 2023
34027d5
add trace logging to abstract & command dir files
JillieBeanSim Mar 9, 2023
4c57bab
add trace logging to dataset & job dir files
JillieBeanSim Mar 9, 2023
a57b9da
add trace logs to shared dir files
JillieBeanSim Mar 14, 2023
e68866d
Merge remote-tracking branch 'origin/main' into output-logger
JillieBeanSim Mar 17, 2023
29fef01
add trace logs to uss dir files
JillieBeanSim Mar 17, 2023
37fd762
add trace logs for utils dir files
JillieBeanSim Mar 17, 2023
1e3b213
check for cli envar and prompt user only once to sync
JillieBeanSim Mar 20, 2023
4e65d50
copy edits on message and changelog
JillieBeanSim Mar 20, 2023
e9cb17f
enclose write to cli logger with setting check
JillieBeanSim Mar 20, 2023
e63c4a3
minimize naming for zowelogger
JillieBeanSim Mar 20, 2023
bf45c46
add more info logs during activation and simplify code
JillieBeanSim Mar 20, 2023
0c38895
fix unit tests
JillieBeanSim Mar 20, 2023
ab389b1
code cleaning
JillieBeanSim Mar 21, 2023
1ee1b61
Merge remote-tracking branch 'origin/main' into output-logger
JillieBeanSim Mar 21, 2023
55574ce
fix unit tests
JillieBeanSim Mar 21, 2023
d14c30e
add tests to make sure correct severity passed to writeLogMessage
JillieBeanSim Mar 22, 2023
32fac0b
more initialize logger unit tests
JillieBeanSim Mar 22, 2023
732c345
Merge remote-tracking branch 'origin/main' into output-logger
JillieBeanSim Mar 23, 2023
79ad1ff
add more unit tests for ZoweLogger
JillieBeanSim Mar 23, 2023
629b7c8
loggerutils unit tests
JillieBeanSim Mar 23, 2023
f3735ee
Merge remote-tracking branch 'origin/main' into output-logger
JillieBeanSim Mar 23, 2023
4b9b125
fix unit tests
JillieBeanSim Mar 23, 2023
51ba0ee
fixing tests for windows
JillieBeanSim Mar 23, 2023
d49d304
clean up strings add some logging
JillieBeanSim Mar 24, 2023
f0fdb37
Merge branch 'main' into output-logger
JillieBeanSim Mar 24, 2023
7714223
add more coverage
JillieBeanSim Mar 24, 2023
2d12ec7
add logging and tests coverage
JillieBeanSim Mar 27, 2023
8953919
additional Profiles unit tests added
JillieBeanSim Mar 27, 2023
decab8c
fix test
JillieBeanSim Mar 27, 2023
5d1affa
Merge remote-tracking branch 'origin/main' into output-logger
JillieBeanSim Mar 28, 2023
873e01a
Merge remote-tracking branch 'origin/main' into output-logger
JillieBeanSim Mar 29, 2023
f41ec24
fix after testing
JillieBeanSim Mar 29, 2023
f348a3f
Merge branch 'main' into output-logger
JillieBeanSim Mar 29, 2023
2a52d2d
Merge remote-tracking branch 'origin/main' into output-logger
JillieBeanSim Mar 29, 2023
c9a6186
fix regression introduced
JillieBeanSim Mar 29, 2023
d10918c
fix lint errors
JillieBeanSim Mar 29, 2023
524385e
add await to outputChannel.dispose call to handle promise error
JillieBeanSim Mar 31, 2023
560e9a4
address comments
JillieBeanSim Apr 4, 2023
2c04788
Merge remote-tracking branch 'origin/main' into output-logger
JillieBeanSim Apr 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen

### New features and enhancements

- Added a new Zowe Explorer setting, `zowe.logger`, with a default setting of `INFO`.
- Added an output channel, `Zowe Explorer`, for logging within VS Code's Output view. The log level is set by the new Zowe Explorer setting, `zowe.logger`.
- Opening a dialog for Upload or Download of files will now open at the project level directory or the user's home directory if no project is opened. [#2203](https://github.com/zowe/vscode-extension-for-zowe/issues/2203)
- Updated linter rules and addressed linter errors throughout the codebase. [#2184](https://github.com/zowe/vscode-extension-for-zowe/issues/2184)

Expand Down
13 changes: 13 additions & 0 deletions packages/zowe-explorer/__mocks__/mockCreators/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,16 @@ const originalGetDirectValue = SettingsConfig.getDirectValue;
export function createGetConfigMock(settings: { [key: string]: any }) {
return jest.fn((key: string) => settings[key] ?? originalGetDirectValue(key));
}

export function createOutputChannel() {
return {
append: jest.fn(),
name: "Zowe Explorer",
appendLine: jest.fn(),
clear: jest.fn(),
show: jest.fn(),
hide: jest.fn(),
dispose: jest.fn(),
replace: jest.fn(),
} as vscode.OutputChannel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
*/

import { PersistentFilters } from "../../src/PersistentFilters";
import { ZoweLogger } from "../../src/utils/LoggerUtils";

describe("PersistentFilters Unit Test", () => {
Object.defineProperty(ZoweLogger, "trace", { value: jest.fn(), configurable: true });
describe("addSearchHistory()", () => {
it("should pop search history if history length is larger than max length", () => {
const pf: PersistentFilters = new PersistentFilters("", 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { createUSSNode, createUSSSessionNode, createUSSTree } from "../../__mock
import { createIJobObject, createJobsTree } from "../../__mocks__/mockCreators/jobs";
import * as path from "path";
import { SettingsConfig } from "../../src/utils/SettingsConfig";
import { ZoweLogger } from "../../src/utils/LoggerUtils";

jest.mock("child_process");
jest.mock("fs");
Expand Down Expand Up @@ -106,12 +107,10 @@ async function createGlobalMocks() {
});
Object.defineProperty(globals, "LOG", { value: newMocks.mockLog, configurable: true });
Object.defineProperty(vscode.window, "createInputBox", { value: newMocks.mockCreateInputBox, configurable: true });
Object.defineProperty(globals.LOG, "debug", { value: newMocks.mockDebug, configurable: true });
Object.defineProperty(zowe.ZosmfSession, "createSessCfgFromArgs", {
value: newMocks.mockCreateSessCfgFromArgs,
configurable: true,
});
Object.defineProperty(globals.LOG, "error", { value: newMocks.mockError, configurable: true });
Object.defineProperty(globals, "ISTHEIA", { get: () => false, configurable: true });
Object.defineProperty(vscode.window, "createTreeView", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.workspace, "getConfiguration", {
Expand All @@ -124,6 +123,11 @@ async function createGlobalMocks() {
});
Object.defineProperty(vscode, "ProgressLocation", { value: newMocks.ProgressLocation, configurable: true });
Object.defineProperty(vscode.window, "withProgress", { value: newMocks.withProgress, configurable: true });
Object.defineProperty(ZoweLogger, "error", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "debug", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "warn", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "info", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "trace", { value: jest.fn(), configurable: true });

newMocks.mockProfileInstance = new Profiles(newMocks.log);
Object.defineProperty(Profiles, "CreateInstance", {
Expand Down Expand Up @@ -251,7 +255,7 @@ describe("Profiles Unit Tests - Function createNewConnection for v1 Profiles", (

await Profiles.getInstance().createNewConnection("");
expect(globalMocks.mockShowInformationMessage.mock.calls.length).toBe(1);
expect(globalMocks.mockShowInformationMessage.mock.calls[0][0]).toBe("Profile name was not supplied. Operation Cancelled");
expect(globalMocks.mockShowInformationMessage.mock.calls[0][0]).toBe("Operation Cancelled");
});

it("Tests that createNewConnection fails if profileType is missing", async () => {
Expand All @@ -260,7 +264,7 @@ describe("Profiles Unit Tests - Function createNewConnection for v1 Profiles", (

await Profiles.getInstance().createNewConnection(globalMocks.testProfile.name, undefined);
expect(globalMocks.mockShowInformationMessage.mock.calls.length).toBe(1);
expect(globalMocks.mockShowInformationMessage.mock.calls[0][0]).toBe("No profile type was chosen. Operation Cancelled");
expect(globalMocks.mockShowInformationMessage.mock.calls[0][0]).toBe("Operation Cancelled");
});

it("Tests that createNewConnection fails if zOSMF URL is missing", async () => {
Expand All @@ -272,7 +276,7 @@ describe("Profiles Unit Tests - Function createNewConnection for v1 Profiles", (

await Profiles.getInstance().createNewConnection(globalMocks.testProfile.name, "zosmf");
expect(globalMocks.mockShowInformationMessage.mock.calls.length).toBe(1);
expect(globalMocks.mockShowInformationMessage.mock.calls[0][0]).toBe("No valid value for z/OS URL. Operation Cancelled");
expect(globalMocks.mockShowInformationMessage.mock.calls[0][0]).toBe("Operation Cancelled");
});

it("Tests that createNewConnection fails if user escapes create at username", async () => {
Expand Down Expand Up @@ -535,15 +539,19 @@ describe("Profiles Unit Tests - Function createZoweSession", () => {
const globalMocks = await createGlobalMocks();
const blockMocks = await createBlockMocks(globalMocks);
const spy = jest.spyOn(Gui, "createQuickPick");
const spyDebug = jest.spyOn(ZoweLogger, "debug");
jest.spyOn(Gui, "resolveQuickPick").mockResolvedValueOnce(undefined);
await Profiles.getInstance().createZoweSession(blockMocks.testDatasetTree);
expect(spy).toBeCalled();
expect(globalMocks.mockShowInformationMessage.mock.calls[0][0]).toBe("No selection made. Operation cancelled.");
expect(globalMocks.mockShowInformationMessage.mock.calls[0][0]).toBe("Profile selection has been cancelled.");
expect(spyDebug).toBeCalledWith("Profile selection has been cancelled.");
spy.mockClear();
spyDebug.mockClear();
});

it("Tests that createZoweSession runs successfully", async () => {
const globalMocks = await createGlobalMocks();
const spyInfo = jest.spyOn(ZoweLogger, "info");
jest.spyOn(Gui, "createQuickPick").mockReturnValue({
show: jest.fn(),
hide: jest.fn(),
Expand All @@ -558,6 +566,25 @@ describe("Profiles Unit Tests - Function createZoweSession", () => {
const refreshSpy = jest.spyOn(Profiles.getInstance(), "refresh").mockImplementation();
await expect(Profiles.getInstance().createZoweSession(globalMocks.testUSSTree)).resolves.not.toThrow();
expect(refreshSpy).toBeCalledTimes(1);
expect(spyInfo).toBeCalledWith("New profile created, test.");
refreshSpy.mockClear();
spyInfo.mockClear();
});

it("Tests that createZoweSession catches error and log warning", async () => {
const globalMocks = await createGlobalMocks();
jest.spyOn(Gui, "createQuickPick").mockReturnValue({
show: jest.fn(),
hide: jest.fn(),
value: "test",
} as any);
jest.spyOn(Gui, "resolveQuickPick").mockResolvedValueOnce(new utils.FilterDescriptor("Test"));
jest.spyOn(Profiles.getInstance(), "getProfileInfo").mockRejectedValueOnce(new Error("test error"));
const warnSpy = jest.spyOn(ZoweLogger, "warn");
await expect(Profiles.getInstance().createZoweSession(globalMocks.testUSSTree)).resolves.not.toThrow();
expect(warnSpy).toBeCalledTimes(1);
expect(warnSpy).toBeCalledWith(Error("test error"));
warnSpy.mockClear();
});
});

Expand Down Expand Up @@ -1431,6 +1458,7 @@ describe("Profiles Unit Tests - function getProfileSetting", () => {
describe("Profiles Unit Tests - function disableValidationContext", () => {
it("should disable validation context and return updated node", async () => {
const globalMocks = await createGlobalMocks();
const spy = jest.spyOn(ZoweLogger, "trace");
const testNode = new (ZoweTreeNode as any)(
"test",
vscode.TreeItemCollapsibleState.None,
Expand All @@ -1442,12 +1470,15 @@ describe("Profiles Unit Tests - function disableValidationContext", () => {
const expectNode = testNode;
expectNode.contextValue = globals.VALIDATE_SUFFIX + "false";
await expect(Profiles.getInstance().disableValidationContext(testNode)).toEqual(expectNode);
expect(spy).toBeCalled();
spy.mockClear();
});
});

describe("Profiles Unit Tests - function enableValidationContext", () => {
it("should enable validation context and return updated node", async () => {
const globalMocks = await createGlobalMocks();
const spy = jest.spyOn(ZoweLogger, "trace");
const testNode = new (ZoweTreeNode as any)(
"test",
vscode.TreeItemCollapsibleState.None,
Expand All @@ -1459,6 +1490,8 @@ describe("Profiles Unit Tests - function enableValidationContext", () => {
const expectedNode = testNode;
expectedNode.contextValue = globals.VALIDATE_SUFFIX + "true";
await expect(Profiles.getInstance().enableValidationContext(testNode)).toEqual(expectedNode);
expect(spy).toBeCalled();
spy.mockClear();
});
});

Expand Down Expand Up @@ -1486,7 +1519,6 @@ describe("Profiles Unit Tests - function ssoLogin", () => {
});
jest.spyOn(Gui, "showMessage").mockImplementation();
});

it("should perform an SSOLogin successfully while fetching the base profile", async () => {
jest.spyOn(ZoweExplorerApiRegister.getInstance(), "getCommonApi").mockReturnValue({
getTokenTypeName: () => zowe.imperative.SessConstants.TOKEN_TYPE_APIML,
Expand All @@ -1496,7 +1528,6 @@ describe("Profiles Unit Tests - function ssoLogin", () => {
jest.spyOn(Profiles.getInstance() as any, "updateBaseProfileFileLogin").mockImplementation();
await expect(Profiles.getInstance().ssoLogin(testNode, "fake")).resolves.not.toThrow();
});

it("should perform an SSOLogin successfully while fetching from session", async () => {
jest.spyOn(ZoweExplorerApiRegister.getInstance(), "getCommonApi").mockReturnValue({
getTokenTypeName: () => "tokenType",
Expand All @@ -1506,6 +1537,31 @@ describe("Profiles Unit Tests - function ssoLogin", () => {
jest.spyOn(Profiles.getInstance() as any, "loginCredentialPrompt").mockReturnValue(["fake", "12345"]);
await expect(Profiles.getInstance().ssoLogin(testNode, "fake")).resolves.not.toThrow();
});
it("should catch error getting token type and log warning", async () => {
jest.spyOn(ZoweExplorerApiRegister.getInstance(), "getCommonApi").mockReturnValueOnce({
getTokenTypeName: () => {
throw new Error("test error.");
},
login: () => "ajshdlfkjshdalfjhas",
} as never);
const warnSpy = jest.spyOn(ZoweLogger, "warn");
await expect(Profiles.getInstance().ssoLogin(testNode, "fake")).resolves.not.toThrow();
expect(warnSpy).toBeCalledWith(Error("test error."));
warnSpy.mockClear();
});
it("should catch error during login and log error", async () => {
jest.spyOn(ZoweExplorerApiRegister.getInstance(), "getCommonApi").mockReturnValueOnce({
getTokenTypeName: () => zowe.imperative.SessConstants.TOKEN_TYPE_APIML,
login: () => {
throw new Error("test error.");
},
} as never);
jest.spyOn(Profiles.getInstance() as any, "loginCredentialPrompt").mockReturnValue(["fake", "12345"]);
const errorSpy = jest.spyOn(ZoweLogger, "error");
await expect(Profiles.getInstance().ssoLogin(testNode, "fake")).resolves.not.toThrow();
expect(errorSpy).toBeCalled();
errorSpy.mockClear();
});
});

describe("Profiles Unit Tests - function updateBaseProfileFileLogin", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as spoolprovider from "../../src/SpoolProvider";
import * as zowe from "@zowe/cli";
import * as vscode from "vscode";
import { Profiles } from "../../src/Profiles";
import { ZoweLogger } from "../../src/utils/LoggerUtils";

describe("SpoolProvider Unit Tests", () => {
const iJobFile: zowe.IJobFile = {
Expand Down Expand Up @@ -78,6 +79,7 @@ describe("SpoolProvider Unit Tests", () => {
};
}),
});
Object.defineProperty(ZoweLogger, "trace", { value: jest.fn(), configurable: true });

afterEach(() => {
jest.resetAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as path from "path";
import * as fs from "fs";
import { getZoweDir, Gui } from "@zowe/zowe-explorer-api";
import * as profilesUtils from "../../src/utils/ProfilesUtils";
import * as globals from "../../src/globals";
import { ZoweLogger } from "../../src/utils/LoggerUtils";
jest.mock("fs");

describe("ZoweExplorerExtender unit tests", () => {
Expand Down Expand Up @@ -66,8 +66,18 @@ describe("ZoweExplorerExtender unit tests", () => {
value: newMocks.mockGetConfiguration,
configurable: true,
});
Object.defineProperty(globals, "LOG", { value: jest.fn(), configurable: true });
Object.defineProperty(globals.LOG, "error", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "warn", {
value: jest.fn(),
configurable: true,
});
Object.defineProperty(ZoweLogger, "error", {
value: jest.fn(),
configurable: true,
});
Object.defineProperty(ZoweLogger, "trace", {
value: jest.fn(),
configurable: true,
});

return newMocks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ZoweDatasetNode } from "../../src/dataset/ZoweDatasetNode";
import { List, imperative } from "@zowe/cli";
import { Profiles } from "../../src/Profiles";
import * as globals from "../../src/globals";
import { ZoweLogger } from "../../src/utils/LoggerUtils";

describe("Unit Tests (Jest)", () => {
// Globals
Expand Down Expand Up @@ -48,6 +49,8 @@ describe("Unit Tests (Jest)", () => {
Object.defineProperty(globals.LOG, "error", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode, "ProgressLocation", { value: ProgressLocation });
Object.defineProperty(vscode.window, "withProgress", { value: withProgress });
Object.defineProperty(ZoweLogger, "error", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "trace", { value: jest.fn(), configurable: true });

beforeEach(() => {
withProgress.mockImplementation((progLocation, callback) => {
Expand Down
Loading