Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
#21 - Add checks for the new plugin nonsense
Browse files Browse the repository at this point in the history
Signed-off-by: Wright, Christopher R <Christopher.Wright@ca.com>
  • Loading branch information
Wright, Christopher R authored and Wright, Christopher R committed Sep 20, 2018
1 parent 5be5b54 commit 258307b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/imperative/__tests__/Imperative.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import { join } from "path";
import { generateRandomAlphaNumericString } from "../../../__tests__/src/TestUtil";
import { IImperativeOverrides } from "../src/doc/IImperativeOverrides";

describe("Imperative", () => {
const loadImperative = () => {
Expand Down Expand Up @@ -169,6 +170,39 @@ describe("Imperative", () => {

expect(PluginManagementFacility.instance.init).toHaveBeenCalledTimes(1);
expect(PluginManagementFacility.instance.loadAllPluginCfgProps).toHaveBeenCalledTimes(1);

expect(PluginManagementFacility.instance.addAllPluginsToHostCli).toHaveBeenCalledTimes(1);
expect(
PluginManagementFacility.instance.addAllPluginsToHostCli
).toHaveBeenCalledWith(mocks.ImperativeConfig.instance.resolvedCmdTree);
});

// @FUTURE When there are more overrides we should think about making this function dynamic
it("should allow a plugin to override modules", async () => {
const testOverrides: IImperativeOverrides = {
CredentialManager: generateRandomAlphaNumericString(16) //tslint:disable-line
};

// Formulate a deep copy of the expected overrides. Ensures that we are comparing values
// and not references to values.
const expectedConfig = JSON.parse(JSON.stringify(defaultConfig));
Object.assign(expectedConfig.overrides, JSON.parse(JSON.stringify(testOverrides)));

PluginManagementFacility.instance.pluginOverrides = testOverrides;

await Imperative.init();

expect(mocks.ImperativeConfig.instance.loadedConfig).toEqual(expectedConfig);
});

it("should not override modules not specified by a plugin", async () => {
const expectedConfig = JSON.parse(JSON.stringify(defaultConfig));

PluginManagementFacility.instance.pluginOverrides = {};

await Imperative.init();

expect(mocks.ImperativeConfig.instance.loadedConfig).toEqual(expectedConfig);
});
});
}); // end describe init
Expand Down

0 comments on commit 258307b

Please sign in to comment.