Skip to content

Commit

Permalink
fix: wrong generated paths for root commands
Browse files Browse the repository at this point in the history
  • Loading branch information
carloscortonc committed Sep 20, 2023
1 parent 4ce969c commit 220ab33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cli-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@ export async function executeScript({ location, options }: Omit<ParsingOutput, "
const isDefaultImport = index === list.length - 1;
const locationPaths = [];
// Include index import
locationPaths.push(path.join(...location.slice(0, index), "index"));
locationPaths.push(path.join(...finalLocation.slice(0, index), "index"));
if (index > 0) {
// Include location-name import
locationPaths.push(path.join(...location.slice(0, index)));
locationPaths.push(path.join(...finalLocation.slice(0, index)));
} else {
// Include entryfile-name import
locationPaths.push(entryFile.name);
Expand Down
15 changes: 15 additions & 0 deletions test/cli-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,21 @@ describe("executeScript", () => {
]);
pathListSpy.mockRestore();
});
it("Generates all valid paths with the corresponding named/default import - single command", () => {
const c = new Cli(definition, { baseScriptLocation: "/" });
const pathListSpy = jest.spyOn(fs, "existsSync").mockImplementation(() => false);
executeScript({ location: ["gcmd"], options: {} as any }, c.options);
const norm = (p: string) => p.replace(/\//g, path.sep);
expect(pathListSpy.mock.calls).toEqual([
[norm("/commands/gcmd/index.js")],
[norm("/commands/gcmd.js")],
[norm("/commands/index.js")],
[norm("/commands.js")],
[norm("/index.js")],
[norm("/script.js")],
]);
pathListSpy.mockRestore();
});
it("Script execution fails: logs error", () => {
(gcmd as any).mockImplementation(() => {
throw new Error("errormessage");
Expand Down

0 comments on commit 220ab33

Please sign in to comment.