Skip to content

Commit

Permalink
Fix floating promises to satisfy lint rule
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
  • Loading branch information
t1m0thyj committed May 18, 2023
1 parent bd18c8f commit b2e0502
Show file tree
Hide file tree
Showing 35 changed files with 145 additions and 132 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ overrides:
"@typescript-eslint/restrict-template-expressions": warn
"@typescript-eslint/explicit-function-return-type": warn
"@typescript-eslint/unbound-method": warn
zowe-explorer/no-floating-promises: warn
parser: "@typescript-eslint/parser"
parserOptions:
ecmaVersion: 6
Expand Down
2 changes: 2 additions & 0 deletions packages/zowe-explorer-api/src/utils/Poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class Poller {
data = await requestData.request();
} catch (err) {
if (requestData.reject) {
// eslint-disable-next-line zowe-explorer/no-floating-promises
requestData.reject(err);
} else {
reject(err);
Expand All @@ -65,6 +66,7 @@ export class Poller {
Poller.pollRequests[uniqueId] = request;

// Initialize the poll request
// eslint-disable-next-line zowe-explorer/no-floating-promises
this.poll(uniqueId, request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ describe("DatasetTree Integration Tests", async () => {
});

describe("removeFavorite()", () => {
beforeEach(() => {
beforeEach(async () => {
const favoriteNode1 = new ZoweDatasetNode(pattern + ".TPDS1", vscode.TreeItemCollapsibleState.Collapsed, sessNode, null);
testTree.addFavorite(favoriteNode1);
await testTree.addFavorite(favoriteNode1);
});
afterEach(() => {
testTree.mFavorites = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ describe("Extension Integration Tests", async () => {
const doc2 = await vscode.workspace.openTextDocument(
path.join(globals.ZOWETEMPFOLDER, children[0].label.toString() + "(" + childrenMembers[0].label.toString() + ")")
);
dsActions.saveFile(doc2, testTree);
await dsActions.saveFile(doc2, testTree);

// Download file
await dsActions.openPS(childrenMembers[0], true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ async function main() {
}
}

// eslint-disable-next-line zowe-explorer/no-floating-promises
main();
1 change: 1 addition & 0 deletions packages/zowe-explorer/__tests__/__theia__/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ async function main() {
}
}

// eslint-disable-next-line zowe-explorer/no-floating-promises
main();
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe("ZoweExplorerApiRegister unit testing", () => {
const api2 = new MockUssApi2();

globalMocks.registry.registerUssApi(api1);
globalMocks.registry.getExplorerExtenderApi().reloadProfiles();
await globalMocks.registry.getExplorerExtenderApi().reloadProfiles();
globalMocks.registry.registerUssApi(api2);
await globalMocks.registry.getExplorerExtenderApi().reloadProfiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ describe("Dataset Tree Unit Tests - Function removeFileHistory", () => {
});
});
describe("Dataset Tree Unit Tests - Function addSession", () => {
async function createBlockMocks() {
function createBlockMocks() {
const newMocks = {
log: zowe.imperative.Logger.getAppLogger(),
session: createISession(),
Expand Down Expand Up @@ -894,20 +894,20 @@ describe("Dataset Tree Unit Tests - Function addSession", () => {
return newMocks;
}
it("Checking successful adding of session", async () => {
await createGlobalMocks();
const blockMocks = await createBlockMocks();
createGlobalMocks();
const blockMocks = createBlockMocks();

mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
testTree.mSessionNodes.push(blockMocks.datasetSessionNode);

testTree.addSession(blockMocks.imperativeProfile.name);
await testTree.addSession(blockMocks.imperativeProfile.name);
expect(testTree.mSessionNodes[1].label).toBe(blockMocks.imperativeProfile.name);
});

it("Checking successful adding of session with disabled validation", async () => {
await createGlobalMocks();
const blockMocks = await createBlockMocks();
createGlobalMocks();
const blockMocks = createBlockMocks();

mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = createDatasetTree(blockMocks.datasetSessionNode, blockMocks.treeView);
Expand All @@ -925,8 +925,8 @@ describe("Dataset Tree Unit Tests - Function addSession", () => {
});

it("Checking successful adding of session without sessname passed", async () => {
await createGlobalMocks();
const blockMocks = await createBlockMocks();
createGlobalMocks();
const blockMocks = createBlockMocks();

mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = createDatasetTree(blockMocks.datasetSessionNode, blockMocks.treeView);
Expand All @@ -938,20 +938,21 @@ describe("Dataset Tree Unit Tests - Function addSession", () => {
});

it("Checking failed attempt to add a session due to the missing profile", async () => {
await createGlobalMocks();
const blockMocks = await createBlockMocks();
createGlobalMocks();
const blockMocks = createBlockMocks();

mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
jest.spyOn(Profiles.getInstance(), "loadNamedProfile").mockReturnValueOnce(null);

testTree.addSession("fake");
await testTree.addSession("fake");

expect(testTree.mSessionNodes[1]).not.toBeDefined();
});

it("Checking failed attempt to add a session due to the missing profile", async () => {
it("Checking successful adding of session with profile type passed", async () => {
createGlobalMocks();
const blockMocks = await createBlockMocks();
const blockMocks = createBlockMocks();

mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
Expand Down Expand Up @@ -1057,7 +1058,7 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {
testTree.mSessionNodes.push(blockMocks.datasetSessionNode);
const node = new ZoweDatasetNode("Dataset", vscode.TreeItemCollapsibleState.None, testTree.mSessionNodes[1], null);

testTree.addFavorite(node);
await testTree.addFavorite(node);

expect(testTree.mFavorites[0].label).toBe(`${blockMocks.datasetSessionNode.label}`);
expect(testTree.mFavorites[0].contextValue).toBe(`${globals.FAV_PROFILE_CONTEXT}`);
Expand All @@ -1074,7 +1075,7 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {
const node = new ZoweDatasetNode("Dataset", vscode.TreeItemCollapsibleState.None, testTree.mSessionNodes[1], null);
node.contextValue = globals.DS_PDS_CONTEXT;

testTree.addFavorite(node);
await testTree.addFavorite(node);

expect(testTree.mFavorites[0].label).toBe(`${blockMocks.datasetSessionNode.label}`);
expect(testTree.mFavorites[0].contextValue).toBe(`${globals.FAV_PROFILE_CONTEXT}`);
Expand All @@ -1093,7 +1094,7 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {
parent.contextValue = globals.DS_PDS_CONTEXT;
child.contextValue = globals.DS_MEMBER_CONTEXT;

testTree.addFavorite(child);
await testTree.addFavorite(child);

expect(testTree.mFavorites[0].label).toBe(`${blockMocks.datasetSessionNode.label}`);
expect(testTree.mFavorites[0].contextValue).toBe(`${globals.FAV_PROFILE_CONTEXT}`);
Expand Down Expand Up @@ -1126,8 +1127,8 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {
testTree.mSessionNodes.push(blockMocks.datasetSessionNode);
const node = new ZoweDatasetNode("Dataset", vscode.TreeItemCollapsibleState.None, testTree.mSessionNodes[1], null);

testTree.addFavorite(node);
testTree.addFavorite(node);
await testTree.addFavorite(node);
await testTree.addFavorite(node);

expect(testTree.mFavorites[0].children.map((entry) => entry.label)).toEqual([`${node.label}`]);
});
Expand All @@ -1143,7 +1144,7 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {
parent.contextValue = globals.DS_PDS_CONTEXT + globals.FAV_SUFFIX;
child.contextValue = globals.DS_MEMBER_CONTEXT;

testTree.addFavorite(child);
await testTree.addFavorite(child);

expect(mocked(Gui.showMessage)).toBeCalledWith("PDS already in favorites");
});
Expand Down Expand Up @@ -1175,14 +1176,14 @@ describe("Dataset Tree Unit Tests - Function removeFavorite", () => {

// We're breaking rule 1 function call per 1 it block, but there's no over proper way to verify the functionality
// First we need to have the item and be sure that it's properly added to have legit removal operation
testTree.addFavorite(node1);
testTree.addFavorite(node2);
await testTree.addFavorite(node1);
await testTree.addFavorite(node2);
const profileNodeInFavs = testTree.mFavorites[0];
expect(profileNodeInFavs.children[0].label).toBe(`${node1.label}`);
expect(profileNodeInFavs.children[1].label).toBe(`${node2.label}`);

// Actual test
testTree.removeFavorite(profileNodeInFavs.children[0]);
await testTree.removeFavorite(profileNodeInFavs.children[0]);
expect(removeFavProfileSpy).not.toBeCalled();
expect(profileNodeInFavs.children.length).toBe(1);
expect(profileNodeInFavs.children[0].label).toBe(`${node2.label}`);
Expand All @@ -1200,7 +1201,7 @@ describe("Dataset Tree Unit Tests - Function removeFavorite", () => {

// We're breaking rule 1 function call per 1 it block, but there's no over proper way to verify the functionality
// First we need to have the item and be sure that it's properly added to have legit removal operation
testTree.addFavorite(node);
await testTree.addFavorite(node);
const profileNodeInFavs = testTree.mFavorites[0];
expect(profileNodeInFavs.children[0].label).toBe(`${node.label}`);
await testTree.removeFavorite(profileNodeInFavs.children[0]);
Expand All @@ -1226,7 +1227,7 @@ describe("Dataset Tree Unit Tests - Function removeFavorite", () => {
});
});
describe("Dataset Tree Unit Tests - Function - Function removeFavProfile", () => {
function createBlockMocks() {
async function createBlockMocks() {
const session = createISession();
const imperativeProfile = createIProfile();
const treeView = createTreeView();
Expand All @@ -1235,7 +1236,7 @@ describe("Dataset Tree Unit Tests - Function - Function removeFavProfile", () =
testTree.mFavorites = [];
testTree.mSessionNodes.push(datasetSessionNode);
const node = new ZoweDatasetNode("Dataset", vscode.TreeItemCollapsibleState.None, testTree.mSessionNodes[1], null);
testTree.addFavorite(node);
await testTree.addFavorite(node);
const profileNodeInFavs: IZoweDatasetTreeNode = testTree.mFavorites[0];

return {
Expand All @@ -1246,7 +1247,7 @@ describe("Dataset Tree Unit Tests - Function - Function removeFavProfile", () =
}
it("Tests successful removal of profile node in Favorites when user confirms they want to Continue removing it", async () => {
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocks();
const blockMocks = await createBlockMocks();
const updateFavoritesSpy = jest.spyOn(blockMocks.testTree, "updateFavorites");
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
// Make sure favorite is added before the actual unit test
Expand All @@ -1262,7 +1263,7 @@ describe("Dataset Tree Unit Tests - Function - Function removeFavProfile", () =
});
it("Tests that removeFavProfile leaves profile node in Favorites when user cancels", async () => {
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocks();
const blockMocks = await createBlockMocks();
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
// Make sure favorite is added before the actual unit test
expect(blockMocks.testTree.mFavorites.length).toEqual(1);
Expand All @@ -1277,7 +1278,7 @@ describe("Dataset Tree Unit Tests - Function - Function removeFavProfile", () =
});
it("Tests that removeFavProfile successfully removes profile node in Favorites when called outside user command", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
const blockMocks = await createBlockMocks();
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
// Make sure favorite is added before the actual unit test
expect(blockMocks.testTree.mFavorites.length).toEqual(1);
Expand Down Expand Up @@ -1330,7 +1331,7 @@ describe("Dataset Tree Unit Tests - Function flipState", () => {
};
}

it("Checking flipping of PDS Dataset node", async () => {
it("Checking flipping of PDS Dataset node", () => {
createGlobalMocks();
const blockMocks = createBlockMocks();

Expand All @@ -1340,14 +1341,14 @@ describe("Dataset Tree Unit Tests - Function flipState", () => {
const node = new ZoweDatasetNode("Dataset", vscode.TreeItemCollapsibleState.Collapsed, testTree.mSessionNodes[1], null);
node.contextValue = globals.DS_PDS_CONTEXT;

await testTree.flipState(node, true);
testTree.flipState(node, true);
expect(JSON.stringify(node.iconPath)).toContain("folder-open.svg");
await testTree.flipState(node, false);
testTree.flipState(node, false);
expect(JSON.stringify(node.iconPath)).toContain("folder-closed.svg");
await testTree.flipState(node, true);
testTree.flipState(node, true);
expect(JSON.stringify(node.iconPath)).toContain("folder-open.svg");
});
it("Checking flipping of Favorite PDS Dataset node", async () => {
it("Checking flipping of Favorite PDS Dataset node", () => {
createGlobalMocks();
const blockMocks = createBlockMocks();

Expand All @@ -1357,14 +1358,14 @@ describe("Dataset Tree Unit Tests - Function flipState", () => {
const node = new ZoweDatasetNode("Dataset", vscode.TreeItemCollapsibleState.Collapsed, testTree.mSessionNodes[1], null);
node.contextValue = globals.DS_PDS_CONTEXT + globals.FAV_SUFFIX;

await testTree.flipState(node, true);
testTree.flipState(node, true);
expect(JSON.stringify(node.iconPath)).toContain("folder-open.svg");
await testTree.flipState(node, false);
testTree.flipState(node, false);
expect(JSON.stringify(node.iconPath)).toContain("folder-closed.svg");
await testTree.flipState(node, true);
testTree.flipState(node, true);
expect(JSON.stringify(node.iconPath)).toContain("folder-open.svg");
});
it("Checking flipping of PDS Dataset with credential prompt", async () => {
it("Checking flipping of PDS Dataset with credential prompt", () => {
createGlobalMocks();
const blockMocks = createBlockMocks();

Expand All @@ -1379,11 +1380,11 @@ describe("Dataset Tree Unit Tests - Function flipState", () => {
);
node.contextValue = globals.DS_PDS_CONTEXT;

await testTree.flipState(node, true);
testTree.flipState(node, true);
expect(JSON.stringify(node.iconPath)).toContain("folder-open.svg");
await testTree.flipState(node, false);
testTree.flipState(node, false);
expect(JSON.stringify(node.iconPath)).toContain("folder-closed.svg");
await testTree.flipState(node, true);
testTree.flipState(node, true);
expect(JSON.stringify(node.iconPath)).toContain("folder-open.svg");
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2056,7 +2056,9 @@ describe("Dataset Actions Unit Tests - Function copyDataSets", () => {

try {
await dsActions.downloadDs(node);
} catch (err) {}
} catch (err) {
/* Do nothing */
}

expect(mocked(Gui.errorMessage)).toBeCalledWith("Cannot download, item invalid.");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe("dsNodeActions", () => {
}),
});
const spy = jest.spyOn(refreshActions, "refreshAll");
refreshActions.refreshAll(testDSTree);
await refreshActions.refreshAll(testDSTree);
expect(spy).toHaveBeenCalledTimes(1);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ describe("ZosJobsProvider unit tests - Function initializeFavChildNodeForProfile
return newMocks;
}
it("Checks that profile-less node is initiated for favorited Job", async () => {
createGlobalMocks();
await createGlobalMocks();
const blockMocks = createBlockMocks();
const testTree = new ZosJobsProvider();

Expand All @@ -312,7 +312,7 @@ describe("ZosJobsProvider unit tests - Function initializeFavChildNodeForProfile
expect(favChildNodeForProfile).toEqual(node);
});
it("Checks that profile-less node is initiated for favorited search", async () => {
createGlobalMocks();
await createGlobalMocks();
const blockMocks = createBlockMocks();
const testTree = new ZosJobsProvider();

Expand Down Expand Up @@ -354,7 +354,7 @@ describe("ZosJobsProvider unit tests - Function loadProfilesForFavorites", () =>
}

it("Checks that loaded profile and session values are added to the profile grouping node in Favorites", async () => {
createGlobalMocks();
await createGlobalMocks();
const blockMocks = createBlockMocks();
const favProfileNode = new Job("testProfile", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.jobFavoritesNode, null, null, null);
favProfileNode.contextValue = globals.FAV_PROFILE_CONTEXT;
Expand Down Expand Up @@ -410,7 +410,7 @@ describe("ZosJobsProvider unit tests - Function loadProfilesForFavorites", () =>
expect(resultFavProfileNode).toEqual(expectedFavProfileNode);
});
it("Checks that the error is handled if profile fails to load", async () => {
createGlobalMocks();
await createGlobalMocks();
const blockMocks = createBlockMocks();
const testTree = new ZosJobsProvider();
const favProfileNode = new Job("badTestProfile", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.jobFavoritesNode, null, null, null);
Expand Down Expand Up @@ -445,7 +445,7 @@ describe("ZosJobsProvider unit tests - Function loadProfilesForFavorites", () =>
showErrorMessageSpy.mockClear();
});
it("Checks that favorite nodes with pre-existing profile/session values continue using those values", async () => {
createGlobalMocks();
await createGlobalMocks();
const blockMocks = createBlockMocks();
const favProfileNode = new Job(
"testProfile",
Expand Down Expand Up @@ -485,7 +485,7 @@ describe("ZosJobsProvider unit tests - Function loadProfilesForFavorites", () =>
expect(resultFavJobNode).toEqual(expectedFavJobNode);
});
it("Checks that profile, session, and owner from profile node in Favorites get passed to child favorites without those values", async () => {
createGlobalMocks();
await createGlobalMocks();
const blockMocks = createBlockMocks();
const favProfileNode = new Job(
"testProfile",
Expand Down
Loading

0 comments on commit b2e0502

Please sign in to comment.