Skip to content

Commit 26d0526

Browse files
authored
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
1 parent 770a23d commit 26d0526

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

libs/accessor.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { Colors } from "../deps.ts";
99

1010
export class DimFileAccessor {
11-
private dimJSON: DimJSON | undefined;
11+
private dimJSON: DimJSON;
1212
constructor(path = DEFAULT_DIM_FILE_PATH) {
1313
try {
1414
Deno.statSync(path);
@@ -33,9 +33,6 @@ export class DimFileAccessor {
3333
);
3434
}
3535
async addContent(content: Content) {
36-
if (this.dimJSON === undefined) {
37-
return;
38-
}
3936
const contents = this.dimJSON.contents;
4037
const contentIndex = this.dimJSON.contents.findIndex((c) => c.name === content.name);
4138
if (contentIndex !== -1) {
@@ -50,9 +47,6 @@ export class DimFileAccessor {
5047
});
5148
}
5249
async addContents(contents: Content[]) {
53-
if (this.dimJSON === undefined) {
54-
return;
55-
}
5650
// Override the existing content.
5751
const currentContents = this.dimJSON.contents.filter((c) =>
5852
!contents.map((newContent) => newContent.name).includes(
@@ -69,9 +63,6 @@ export class DimFileAccessor {
6963
});
7064
}
7165
async removeContent(name: string) {
72-
if (this.dimJSON === undefined) {
73-
return;
74-
}
7566
const contents = this.dimJSON.contents.filter((c) => c.name !== name);
7667
await this.writeToDimFile({
7768
fileVersion: DIM_FILE_VERSION,
@@ -89,7 +80,7 @@ export class DimFileAccessor {
8980
}
9081

9182
export class DimLockFileAccessor {
92-
private dimLockJSON: DimLockJSON | undefined;
83+
private dimLockJSON: DimLockJSON;
9384
constructor() {
9485
try {
9586
Deno.statSync(DEFAULT_DIM_LOCK_FILE_PATH);
@@ -108,9 +99,6 @@ export class DimLockFileAccessor {
10899
);
109100
}
110101
async addContent(content: LockContent) {
111-
if (this.dimLockJSON === undefined) {
112-
return;
113-
}
114102
const contents = this.dimLockJSON.contents;
115103
const contentIndex = this.dimLockJSON.contents.findIndex((c) => c.name === content.name);
116104
if (contentIndex !== -1) {
@@ -125,9 +113,6 @@ export class DimLockFileAccessor {
125113
});
126114
}
127115
async addContents(contents: LockContent[]) {
128-
if (this.dimLockJSON === undefined) {
129-
return;
130-
}
131116
// Override the existing content.
132117
const currentContents = this.dimLockJSON.contents.filter((c) =>
133118
!contents.map((newContent) => newContent.name).includes(

tests/helper.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ export const createKyGetStub = (
2424
};
2525

2626
export const removeTemporaryFiles = () => {
27-
// Skip removing process when temporary directory does not exist
28-
try {
29-
Deno.statSync(temporaryDirectory);
30-
} catch {
31-
return;
32-
}
33-
3427
for (const path of Deno.readDirSync(temporaryDirectory)) {
3528
Deno.removeSync(temporaryDirectory + path.name, { recursive: true });
3629
}

0 commit comments

Comments
 (0)