-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2118 from zowe/poc-1987-mvp
MVP: Imperative Event Emitter
- Loading branch information
Showing
33 changed files
with
1,127 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...mperative/src/events/__tests__/__integration__/ImperativeEventEmitter.integration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
* | ||
*/ | ||
|
||
import { IImperativeEventJson, ImperativeEventEmitter, ImperativeSharedEvents } from "../../.."; | ||
import { ITestEnvironment } from "../../../../__tests__/__src__/environment/doc/response/ITestEnvironment"; | ||
import { TestLogger } from "../../../../__tests__/src/TestLogger"; | ||
import * as TestUtil from "../../../../__tests__/src/TestUtil"; | ||
import { SetupTestEnvironment } from "../../../../__tests__/__src__/environment/SetupTestEnvironment"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
|
||
let TEST_ENVIRONMENT: ITestEnvironment; | ||
const iee = ImperativeEventEmitter; | ||
const iee_s = ImperativeSharedEvents; | ||
let cwd = ''; | ||
|
||
describe("Event Emitter", () => { | ||
const mainModule = process.mainModule; | ||
const testLogger = TestLogger.getTestLogger(); | ||
|
||
beforeAll(async () => { | ||
(process.mainModule as any) = { | ||
filename: __filename | ||
}; | ||
|
||
TEST_ENVIRONMENT = await SetupTestEnvironment.createTestEnv({ | ||
cliHomeEnvVar: "ZOWE_CLI_HOME", | ||
testName: "event_emitter" | ||
}); | ||
cwd = TEST_ENVIRONMENT.workingDir; | ||
}); | ||
|
||
beforeEach(() => { | ||
iee.initialize("zowe", { logger: testLogger }); | ||
}); | ||
|
||
afterEach(() => { | ||
iee.teardown(); | ||
}); | ||
|
||
afterAll(() => { | ||
process.mainModule = mainModule; | ||
TestUtil.rimraf(cwd); | ||
}); | ||
|
||
const doesEventFileExists = (eventType: string) => { | ||
const eventDir = iee.instance.getEventDir(eventType); | ||
if (!fs.existsSync(eventDir)) return false; | ||
if (fs.existsSync(path.join(eventDir, eventType))) return true; | ||
return false; | ||
}; | ||
|
||
describe("Shared Events", () => { | ||
it("should create an event file upon first subscription if the file does not exist", () => { | ||
const theEvent = iee_s.ON_CREDENTIAL_MANAGER_CHANGED; | ||
|
||
expect(doesEventFileExists(theEvent)).toBeFalsy(); | ||
|
||
const subSpy = jest.fn(); | ||
iee.instance.subscribe(theEvent, subSpy); | ||
|
||
expect(subSpy).not.toHaveBeenCalled(); | ||
expect(doesEventFileExists(theEvent)).toBeTruthy(); | ||
|
||
expect(iee.instance.getEventContents(theEvent)).toBeFalsy(); | ||
|
||
iee.instance.emitEvent(theEvent); | ||
|
||
(iee.instance as any).subscriptions.get(theEvent)[1][0](); // simulate FSWatcher called | ||
|
||
expect(doesEventFileExists(theEvent)).toBeTruthy(); | ||
const eventDetails: IImperativeEventJson = JSON.parse(iee.instance.getEventContents(theEvent)); | ||
expect(eventDetails.type).toEqual(theEvent); | ||
expect(eventDetails.user).toBeFalsy(); | ||
|
||
expect(subSpy).toHaveBeenCalled(); | ||
}); | ||
it("should trigger subscriptions for all instances watching for onCredentialManagerChanged", () => { }); | ||
it("should not affect subscriptions from another instance when unsubscribing from events", () => { }); | ||
}); | ||
|
||
describe("User Events", () => { | ||
it("should create an event file upon first subscription if the file does not exist", () => { }); | ||
it("should trigger subscriptions for all instances watching for onVaultChanged", () => { }); | ||
it("should not affect subscriptions from another instance when unsubscribing from events", () => { }); | ||
}); | ||
|
||
describe("Custom Events", () => { | ||
it("should create an event file upon first subscription if the file does not exist", () => { }); | ||
it("should trigger subscriptions for all instances watching for onMyCustomEvent", () => { }); | ||
it("should not affect subscriptions from another instance when unsubscribing from events", () => { }); | ||
}); | ||
}); |
Oops, something went wrong.