Skip to content

Commit

Permalink
Feature/enhance accessor test coverage and helper test coverage (#92)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
To-Ki-O authored Oct 26, 2022
1 parent 770a23d commit 26d0526
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
19 changes: 2 additions & 17 deletions libs/accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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(
Expand Down
7 changes: 0 additions & 7 deletions tests/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down

0 comments on commit 26d0526

Please sign in to comment.