From 26d0526409ac63ea62dd36f2c7f57304873abedc Mon Sep 17 00:00:00 2001 From: To-Ki-O <108504207+To-Ki-O@users.noreply.github.com> Date: Wed, 26 Oct 2022 12:47:19 +0900 Subject: [PATCH] Feature/enhance accessor test coverage and helper test coverage (#92) * add test which type dim uninstall before dim init * delete existence check of temporary directory * delete undefined from UNION type dimJSON in accessor.ts * delete the check if dimJSON is undefined in removeContent * delete space to suit format --- libs/accessor.ts | 19 ++----------------- tests/helper.ts | 7 ------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/libs/accessor.ts b/libs/accessor.ts index ae8e0e3..8615306 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( @@ -69,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, @@ -89,7 +80,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 +99,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 +113,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( 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 }); }