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

Introduce fixes v1 #991

Merged
merged 2 commits into from May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Imperative package will be documented in this file.

## Recent Changes

- BugFix: Handle logic for if a null command handler is provided

## `4.18.15`

- BugFix: Fixed the `login` and `logout` handlers, fixing the `li` and `lo` aliases.
Expand Down
64 changes: 64 additions & 0 deletions packages/imperative/__tests__/DefinitionTreeResolver.test.ts
Expand Up @@ -13,6 +13,25 @@ import { DefinitionTreeResolver } from "../src/DefinitionTreeResolver";
import { ImperativeError } from "../../error";
import { Logger } from "../../logger";
import { Console } from "../../console";
import { ICommandDefinition } from "../../cmd";

const fakeDefinition: ICommandDefinition = {
name: "users",
aliases: ["u"],
description: "Users list",
type: "command",
handler: "/no/exist/some.handler",
options: [
{
name: "host",
description: "Hostname",
type: "string",
}
],
profile: {
required: ["sample"]
}
};

describe("DefinitionTreeResolver tests", () => {

Expand Down Expand Up @@ -47,6 +66,51 @@ describe("DefinitionTreeResolver tests", () => {
expect(def.children[0].profile.optional).toBeUndefined();
});

it("should match on definition with dummy handler", () => {
const def = DefinitionTreeResolver.resolve("", "", __dirname, new Logger(new Console()), [fakeDefinition], []);
expect(def.children).toBeDefined();
expect(def.children.length).toBe(1);
expect(def.children[0].profile).toBeDefined();
expect(def.children[0].profile.required).toEqual(["sample"]);
expect(def.children[0].profile.optional).toBeUndefined();
});

it("should match on glob with dummy handler with null child definitions", () => {
const def = DefinitionTreeResolver.resolve("", "", __dirname, new Logger(new Console()), null as any, ["**/*.definition!(.d).*s"]);
expect(def.children).toBeDefined();
expect(def.children.length).toBe(1);
expect(def.children[0].profile).toBeDefined();
expect(def.children[0].profile.required).toEqual(["sample"]);
expect(def.children[0].profile.optional).toBeUndefined();
});

it("should match on glob with dummy handler with undefined child definitions", () => {
const def = DefinitionTreeResolver.resolve("", "", __dirname, new Logger(new Console()), undefined, ["**/*.definition!(.d).*s"]);
expect(def.children).toBeDefined();
expect(def.children.length).toBe(1);
expect(def.children[0].profile).toBeDefined();
expect(def.children[0].profile.required).toEqual(["sample"]);
expect(def.children[0].profile.optional).toBeUndefined();
});

it("should match on child definition with undefined glob", () => {
const def = DefinitionTreeResolver.resolve("", "", __dirname, new Logger(new Console()), [fakeDefinition], undefined);
expect(def.children).toBeDefined();
expect(def.children.length).toBe(1);
expect(def.children[0].profile).toBeDefined();
expect(def.children[0].profile.required).toEqual(["sample"]);
expect(def.children[0].profile.optional).toBeUndefined();
});

it("should match on child definition with null glob", () => {
const def = DefinitionTreeResolver.resolve("", "", __dirname, new Logger(new Console()), [fakeDefinition], null as any);
expect(def.children).toBeDefined();
expect(def.children.length).toBe(1);
expect(def.children[0].profile).toBeDefined();
expect(def.children[0].profile.required).toEqual(["sample"]);
expect(def.children[0].profile.optional).toBeUndefined();
});

it("should match on glob with dummy handler and add base profile", () => {
const def = DefinitionTreeResolver.resolve("", "", __dirname, new Logger(new Console()), [], ["**/*.definition!(.d).*s"], true);
expect(def.children).toBeDefined();
Expand Down
6 changes: 5 additions & 1 deletion packages/imperative/src/DefinitionTreeResolver.ts
Expand Up @@ -47,6 +47,10 @@ export class DefinitionTreeResolver {
"to Imperative. Specify modules and/or definitions on your Imperative" +
"configuration."
});
} else if (childrenDefinitions == null) {
childrenDefinitions = [];
} else if (childrenModuleGlobs == null) {
childrenModuleGlobs = [];
}
const root: ICommandDefinition =
{
Expand Down Expand Up @@ -91,7 +95,7 @@ export class DefinitionTreeResolver {
*/
public static combineAllCmdDefs(
callerDir: string,
cmdDefs: ICommandDefinition[]= [],
cmdDefs: ICommandDefinition[] = [],
cmdModuleGlobs: string[] = [],
addBaseProfile?: boolean
): ICommandDefinition[] {
Expand Down