From 339bddd51abb66f1d99f70eb1072d9b456e1e40c Mon Sep 17 00:00:00 2001 From: To-Ki-O <108504207+To-Ki-O@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:18:20 +0000 Subject: [PATCH 1/5] add test which type dim uninstall before dim init --- tests/libs/actions.uninstall.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/libs/actions.uninstall.test.ts b/tests/libs/actions.uninstall.test.ts index 9e2fe07..fe4f9fb 100644 --- a/tests/libs/actions.uninstall.test.ts +++ b/tests/libs/actions.uninstall.test.ts @@ -111,6 +111,14 @@ describe("UninstallAction", () => { assertSpyCall(denoExitStub, 0, { args: [1] }); }); + it("runs without dim.json and dim-lock.json", async () => { + await new UninstallAction().execute(undefined as void, "dummy"); + assertSpyCall(consoleLogStub, 0, { + args: [Colors.red("Not found a dim.json. You should run a 'dim init'. ")], + }); + assertSpyCall(denoExitStub, 0, { args: [1] }); + }); + it("runs with a name not recorded in dim.json or dim-lock.json and displays an error message.", async () => { const dimData: DimJSON = { fileVersion: "1.1", From 04bb821fb6a4ff11d9bf5606667127b82e7b25e6 Mon Sep 17 00:00:00 2001 From: To-Ki-O <108504207+To-Ki-O@users.noreply.github.com> Date: Tue, 25 Oct 2022 07:12:40 +0000 Subject: [PATCH 2/5] delete existence check of temporary directory --- tests/helper.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/helper.ts b/tests/helper.ts index 45671f5..ec5b716 100644 --- a/tests/helper.ts +++ b/tests/helper.ts @@ -24,13 +24,6 @@ export const createKyGetStub = ( }; export const removeTemporaryFiles = () => { - // Skip removing process when temporary directory does not exist - try { - Deno.statSync(temporaryDirectory); - } catch { - return; - } - for (const path of Deno.readDirSync(temporaryDirectory)) { Deno.removeSync(temporaryDirectory + path.name, { recursive: true }); } From b6b740aa609b86878ef275087fc908aa34f8980b Mon Sep 17 00:00:00 2001 From: To-Ki-O <108504207+To-Ki-O@users.noreply.github.com> Date: Wed, 26 Oct 2022 00:17:05 +0000 Subject: [PATCH 3/5] delete undefined from UNION type dimJSON in accessor.ts --- libs/accessor.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/libs/accessor.ts b/libs/accessor.ts index ae8e0e3..9d5c251 100644 --- a/libs/accessor.ts +++ b/libs/accessor.ts @@ -8,7 +8,7 @@ import { import { Colors } from "../deps.ts"; export class DimFileAccessor { - private dimJSON: DimJSON | undefined; + private dimJSON: DimJSON; constructor(path = DEFAULT_DIM_FILE_PATH) { try { Deno.statSync(path); @@ -33,9 +33,6 @@ export class DimFileAccessor { ); } async addContent(content: Content) { - if (this.dimJSON === undefined) { - return; - } const contents = this.dimJSON.contents; const contentIndex = this.dimJSON.contents.findIndex((c) => c.name === content.name); if (contentIndex !== -1) { @@ -50,9 +47,6 @@ export class DimFileAccessor { }); } async addContents(contents: Content[]) { - if (this.dimJSON === undefined) { - return; - } // Override the existing content. const currentContents = this.dimJSON.contents.filter((c) => !contents.map((newContent) => newContent.name).includes( @@ -89,7 +83,7 @@ export class DimFileAccessor { } export class DimLockFileAccessor { - private dimLockJSON: DimLockJSON | undefined; + private dimLockJSON: DimLockJSON; constructor() { try { Deno.statSync(DEFAULT_DIM_LOCK_FILE_PATH); @@ -108,9 +102,6 @@ export class DimLockFileAccessor { ); } async addContent(content: LockContent) { - if (this.dimLockJSON === undefined) { - return; - } const contents = this.dimLockJSON.contents; const contentIndex = this.dimLockJSON.contents.findIndex((c) => c.name === content.name); if (contentIndex !== -1) { @@ -125,9 +116,6 @@ export class DimLockFileAccessor { }); } async addContents(contents: LockContent[]) { - if (this.dimLockJSON === undefined) { - return; - } // Override the existing content. const currentContents = this.dimLockJSON.contents.filter((c) => !contents.map((newContent) => newContent.name).includes( From d66c72f4ec25664e045ac0ea0c1842b1b71554b3 Mon Sep 17 00:00:00 2001 From: To-Ki-O <108504207+To-Ki-O@users.noreply.github.com> Date: Wed, 26 Oct 2022 00:57:18 +0000 Subject: [PATCH 4/5] delete the check if dimJSON is undefined in removeContent --- libs/accessor.ts | 3 --- tests/libs/actions.uninstall.test.ts | 10 +--------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/libs/accessor.ts b/libs/accessor.ts index 9d5c251..8615306 100644 --- a/libs/accessor.ts +++ b/libs/accessor.ts @@ -63,9 +63,6 @@ export class DimFileAccessor { }); } async removeContent(name: string) { - if (this.dimJSON === undefined) { - return; - } const contents = this.dimJSON.contents.filter((c) => c.name !== name); await this.writeToDimFile({ fileVersion: DIM_FILE_VERSION, diff --git a/tests/libs/actions.uninstall.test.ts b/tests/libs/actions.uninstall.test.ts index fe4f9fb..412ce92 100644 --- a/tests/libs/actions.uninstall.test.ts +++ b/tests/libs/actions.uninstall.test.ts @@ -110,15 +110,7 @@ describe("UninstallAction", () => { }); assertSpyCall(denoExitStub, 0, { args: [1] }); }); - - it("runs without dim.json and dim-lock.json", async () => { - await new UninstallAction().execute(undefined as void, "dummy"); - assertSpyCall(consoleLogStub, 0, { - args: [Colors.red("Not found a dim.json. You should run a 'dim init'. ")], - }); - assertSpyCall(denoExitStub, 0, { args: [1] }); - }); - + it("runs with a name not recorded in dim.json or dim-lock.json and displays an error message.", async () => { const dimData: DimJSON = { fileVersion: "1.1", From 1368e24b2647145247a25a5475c4b2b761736a63 Mon Sep 17 00:00:00 2001 From: To-Ki-O <108504207+To-Ki-O@users.noreply.github.com> Date: Wed, 26 Oct 2022 00:58:55 +0000 Subject: [PATCH 5/5] delete space to suit format --- tests/libs/actions.uninstall.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/libs/actions.uninstall.test.ts b/tests/libs/actions.uninstall.test.ts index 412ce92..9e2fe07 100644 --- a/tests/libs/actions.uninstall.test.ts +++ b/tests/libs/actions.uninstall.test.ts @@ -110,7 +110,7 @@ describe("UninstallAction", () => { }); assertSpyCall(denoExitStub, 0, { args: [1] }); }); - + it("runs with a name not recorded in dim.json or dim-lock.json and displays an error message.", async () => { const dimData: DimJSON = { fileVersion: "1.1",