From e5f79739d42864e71ef4deb336e5babafd51eeb8 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sat, 7 Apr 2018 01:52:51 -0300 Subject: [PATCH 1/2] See #58. Improve Dependency not installed error message --- src/DependencyManager/Dependency.ts | 5 ++++- test/DependencyManager/DependencyManager.spec.ts | 3 ++- test/DependencyManager/ExecutableDependency.spec.ts | 6 ++++-- test/DependencyManager/NodeDependency.spec.ts | 7 ++++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/DependencyManager/Dependency.ts b/src/DependencyManager/Dependency.ts index e5dcba10..9bed859c 100644 --- a/src/DependencyManager/Dependency.ts +++ b/src/DependencyManager/Dependency.ts @@ -29,7 +29,10 @@ export abstract class Dependency { .then(isInstalled => { if (this.required && !isInstalled) { throw new Error( - `Dependency "${this.name}" is required and not installed.` + [ + `Dependency "${this.name}" is required and not installed.`, + ...this.errors.map(error => ` - ${error.message}`), + ].join("\n") ); } return isInstalled; diff --git a/test/DependencyManager/DependencyManager.spec.ts b/test/DependencyManager/DependencyManager.spec.ts index 8a52f432..81bd37da 100644 --- a/test/DependencyManager/DependencyManager.spec.ts +++ b/test/DependencyManager/DependencyManager.spec.ts @@ -6,7 +6,7 @@ import { } from "../../src/DependencyManager"; test("should fail to load dependencies", async () => { - expect.assertions(1); + expect.assertions(2); const options: DependencyOptions = { name: "NotFound", package: "notfound", @@ -18,6 +18,7 @@ test("should fail to load dependencies", async () => { expect(error.message).toMatch( 'Dependency "NotFound" is required and not installed.' ); + expect(error.message).toMatch("Cannot find module package.json"); }); }); diff --git a/test/DependencyManager/ExecutableDependency.spec.ts b/test/DependencyManager/ExecutableDependency.spec.ts index 3d20ee45..95e7a234 100644 --- a/test/DependencyManager/ExecutableDependency.spec.ts +++ b/test/DependencyManager/ExecutableDependency.spec.ts @@ -5,7 +5,7 @@ import { } from "../../src/DependencyManager"; test("should fail to load Executable dependency", async () => { - expect.assertions(3); + expect.assertions(4); const options: DependencyOptions = { name: "NotFound", program: "NotFound", @@ -17,6 +17,7 @@ test("should fail to load Executable dependency", async () => { expect(error.message).toMatch( 'Dependency "NotFound" is required and not installed.' ); + expect(error.message).toMatch("spawn NotFound ENOENT"); expect(dependency.isInstalled).toBe(false); expect(dependency.errors).toHaveLength(1); }); @@ -279,7 +280,7 @@ describe("successfully loaded Executable dependency", () => { }); test("should fail to parse version from text without numbers with RegExp pattern", () => { - expect.assertions(2); + expect.assertions(3); const options: DependencyOptions = { name: "Node", parseVersion: /v/, @@ -292,6 +293,7 @@ describe("successfully loaded Executable dependency", () => { expect(error.message).toMatch( 'Dependency "Node" is required and not installed.' ); + expect(error.message).toMatch("Invalid Version:"); }); }); diff --git a/test/DependencyManager/NodeDependency.spec.ts b/test/DependencyManager/NodeDependency.spec.ts index 22d9e8fa..baed583f 100644 --- a/test/DependencyManager/NodeDependency.spec.ts +++ b/test/DependencyManager/NodeDependency.spec.ts @@ -5,7 +5,7 @@ import { } from "../../src/DependencyManager"; test("should fail to load Node dependency", async () => { - expect.assertions(3); + expect.assertions(5); const options: DependencyOptions = { name: "NotFound", package: "NotFound", @@ -17,8 +17,13 @@ test("should fail to load Node dependency", async () => { expect(error.message).toMatch( 'Dependency "NotFound" is required and not installed.' ); + expect(error.message).toMatch("Cannot find module package.json"); expect(dependency.isInstalled).toBe(false); expect(dependency.errors).toHaveLength(1); + expect(error.message).toMatch( + 'Dependency "NotFound" is required and not installed.\n' + + " - Cannot find module package.json" + ); }); }); From e2220b0cbbe7a7b719033e443a0540bbe5eae4bd Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sat, 7 Apr 2018 02:11:34 -0300 Subject: [PATCH 2/2] See #58. Fix bug in NodeDependency error message --- src/DependencyManager/NodeDependency.ts | 8 ++++---- test/DependencyManager/DependencyManager.spec.ts | 2 +- test/DependencyManager/NodeDependency.spec.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/DependencyManager/NodeDependency.ts b/src/DependencyManager/NodeDependency.ts index 5b8f02d1..670ecb4c 100644 --- a/src/DependencyManager/NodeDependency.ts +++ b/src/DependencyManager/NodeDependency.ts @@ -23,17 +23,17 @@ export class NodeDependency extends Dependency { // tslint:disable-next-line:no-reserved-keywords private require(id?: string): any { - const modulePath = this.resolve(id); + const path = this.fullPath(id); + const modulePath = this.resolve(path); if (modulePath) { // tslint:disable-next-line:no-require-imports non-literal-require return require(modulePath); } else { - throw new Error(`Cannot find module ${id}`); + throw new Error(`Cannot find module ${path}`); } } - private resolve(file?: string): string | undefined { - const path = this.fullPath(file); + private resolve(path: string): string | undefined { return this.resolveLocal(path) || this.resolveGlobal(path); } diff --git a/test/DependencyManager/DependencyManager.spec.ts b/test/DependencyManager/DependencyManager.spec.ts index 81bd37da..3f7eddb3 100644 --- a/test/DependencyManager/DependencyManager.spec.ts +++ b/test/DependencyManager/DependencyManager.spec.ts @@ -18,7 +18,7 @@ test("should fail to load dependencies", async () => { expect(error.message).toMatch( 'Dependency "NotFound" is required and not installed.' ); - expect(error.message).toMatch("Cannot find module package.json"); + expect(error.message).toMatch("Cannot find module notfound/package.json"); }); }); diff --git a/test/DependencyManager/NodeDependency.spec.ts b/test/DependencyManager/NodeDependency.spec.ts index baed583f..9c51f535 100644 --- a/test/DependencyManager/NodeDependency.spec.ts +++ b/test/DependencyManager/NodeDependency.spec.ts @@ -8,7 +8,7 @@ test("should fail to load Node dependency", async () => { expect.assertions(5); const options: DependencyOptions = { name: "NotFound", - package: "NotFound", + package: "notfound", type: DependencyType.Node, }; const dependency = new NodeDependency(options); @@ -17,12 +17,12 @@ test("should fail to load Node dependency", async () => { expect(error.message).toMatch( 'Dependency "NotFound" is required and not installed.' ); - expect(error.message).toMatch("Cannot find module package.json"); + expect(error.message).toMatch("Cannot find module notfound/package.json"); expect(dependency.isInstalled).toBe(false); expect(dependency.errors).toHaveLength(1); expect(error.message).toMatch( 'Dependency "NotFound" is required and not installed.\n' + - " - Cannot find module package.json" + " - Cannot find module notfound/package.json" ); }); });