Skip to content

Commit 9d69f6e

Browse files
committed
refactor: optimize code structure and improve readability
1 parent 792a45b commit 9d69f6e

22 files changed

+42
-62
lines changed

tests/src/modules/canvas.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
1+
import { assertEquals, assert } from "jsr:@std/assert";
22
import { CanvasModule, CanvasWorker } from "../../../src/modules/canvas.js";
33
import { stub } from "https://deno.land/[email protected]/testing/mock.ts";
44

tests/src/modules/component.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { ComponentModule } from "../../../src/modules/component.js";
2-
import {
3-
assertEquals,
4-
assertThrowsAsync,
5-
} from "https://deno.land/[email protected]/testing/asserts.ts";
2+
import { assertEquals, assertThrows } from "jsr:@std/assert";
63

74
Deno.test("ComponentModule.load_html - should throw an error if url is not provided", async () => {
8-
await assertThrowsAsync(
5+
await assertThrows(
96
() => ComponentModule.load_html({}),
107
Error,
118
'ComponentModule.load_html: Argument "url" is required',

tests/src/modules/css-grid.test.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
assertEquals,
3-
assertThrowsAsync,
4-
} from "https://deno.land/[email protected]/testing/asserts.ts";
1+
import { assertEquals, assertThrows } from "jsr:@std/assert";
52

63
import { CssGridModule } from "./../../../src/modules/css-grid.js";
74

@@ -26,15 +23,15 @@ Deno.test("CssGridModule.create - should return grid with specified column and r
2623
});
2724

2825
Deno.test("CssGridModule.create - should throw an error if columnCount is not a number", async () => {
29-
await assertThrowsAsync(
26+
await assertThrows(
3027
() => CssGridModule.create({ columnCount: "invalid" }),
3128
Error,
3229
'CssGridModule.create: Argument "columnCount" should be of type "number"',
3330
);
3431
});
3532

3633
Deno.test("CssGridModule.create - should throw an error if rowCount is not a number", async () => {
37-
await assertThrowsAsync(
34+
await assertThrows(
3835
() => CssGridModule.create({ rowCount: "invalid" }),
3936
Error,
4037
'CssGridModule.create: Argument "rowCount" should be of type "number"',
@@ -61,7 +58,7 @@ Deno.test("CssGridModule.push - should add both a column and a row to the grid",
6158
});
6259

6360
Deno.test("CssGridModule.push - should throw an error if data is not provided", async () => {
64-
await assertThrowsAsync(
61+
await assertThrows(
6562
() => CssGridModule.push({ column: "2fr" }),
6663
Error,
6764
'CssGridModule.push: Argument "data" is required',
@@ -89,7 +86,7 @@ Deno.test("CssGridModule.to - should convert an object to CSS grid-template valu
8986
});
9087

9188
Deno.test("CssGridModule.to - should throw an error if data is not provided", async () => {
92-
await assertThrowsAsync(
89+
await assertThrows(
9390
() => CssGridModule.to({}),
9491
Error,
9592
'CssGridModule.to: Argument "data" is required',
@@ -117,7 +114,7 @@ Deno.test("CssGridModule.optimize - should handle no duplicates correctly", asyn
117114
});
118115

119116
Deno.test("CssGridModule.optimize - should throw an error if values are not provided", async () => {
120-
await assertThrowsAsync(
117+
await assertThrows(
121118
() => CssGridModule.optimize({}),
122119
Error,
123120
'CssGridModule.optimize: Argument "values" is required',
@@ -153,7 +150,7 @@ Deno.test("CssGridModule.to_regions - should handle single row and multiple colu
153150
});
154151

155152
Deno.test("CssGridModule.to_regions - should throw an error if data is not provided", async () => {
156-
await assertThrowsAsync(
153+
await assertThrows(
157154
() => CssGridModule.to_regions({}),
158155
Error,
159156
'CssGridModule.to_regions: Argument "data" is required',
@@ -202,7 +199,7 @@ Deno.test("CssGridModule.copyRegion - should throw an error if start point is ou
202199
["A1", "B1", "C1"],
203200
["A2", "B2", "C2"],
204201
];
205-
await assertThrowsAsync(
202+
await assertThrows(
206203
() => CssGridModule.copy_region({
207204
regions,
208205
start: { row: -1, column: 0 },
@@ -219,7 +216,7 @@ Deno.test("CssGridModule.copyRegion - should throw an error if end point is out
219216
["A1", "B1", "C1"],
220217
["A2", "B2", "C2"],
221218
];
222-
await assertThrowsAsync(
219+
await assertThrows(
223220
() => CssGridModule.copy_region({
224221
regions,
225222
start: { row: 0, column: 0 },

tests/src/modules/dom-parser.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {
2-
assertEquals,
3-
} from "https://deno.land/[email protected]/testing/asserts.ts";
1+
import { assertEquals, assert } from "jsr:@std/assert";
42

53
import { DomParserModule } from "../../../src/modules/dom-parser.js";
64

tests/src/modules/idle.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
assertEquals,
3-
assert,
4-
} from "https://deno.land/[email protected]/testing/asserts.ts";
1+
import { assertEquals, assert } from "jsr:@std/assert";
52
import { IdleModule } from "../../../src/modules/idle.js";
63

74
// Mock requestIdleCallback and cancelIdleCallback

tests/src/modules/markdown.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {assertEquals} from "https://deno.land/[email protected]/testing/asserts.ts";
2-
1+
import { assertEquals } from "jsr:@std/assert";
32
import {MarkdownModule} from "../../../src/modules/markdown.js";
43

54
Deno.test("MarkdownModule.to_html - should convert markdown to html", async () => {

tests/src/modules/messaging.test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
import { assertEquals, assertThrows } from "jsr:@std/assert";
12
import { MessagingModule } from "../../../src/modules/messaging.js";
2-
import {
3-
assertEquals,
4-
assertThrowsAsync,
5-
} from "https://deno.land/[email protected]/testing/asserts.ts";
63

74
Deno.test("MessagingModule.publish - should throw an error if topic is not provided", async () => {
8-
await assertThrowsAsync(
5+
await assertThrows(
96
() => MessagingModule.publish({ message: { text: "Hello World" } }),
107
Error,
118
'MessagingModule.publish: Argument "topic" is required',
129
);
1310
});
1411

1512
Deno.test("MessagingModule.publish - should throw an error if message is not provided", async () => {
16-
await assertThrowsAsync(
13+
await assertThrows(
1714
() => MessagingModule.publish({ topic: "my-topic" }),
1815
Error,
1916
'MessagingModule.publish: Argument "message" is required',

tests/src/modules/ollama.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert } from "jsr:@std/assert";
1+
import { assert, assertEquals, assert } from "jsr:@std/assert";
22
import { ChatRoles, OllamaModule } from "./../../../src/modules/ollama.js";
33

44
Deno.test("OllamaModule - create_message", async () => {

tests/src/modules/quadtree/quadtree.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals, assert } from "https://deno.land/[email protected]/testing/asserts.ts";
1+
import { assertEquals, assert } from "jsr:@std/assert";
22
import { QuadTree } from "./../../../../src/modules/quadtree/quadtree.js";
33

44
function pointsMatch(actual, expected) {

tests/src/modules/router.test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { assertEquals } from "jsr:@std/assert";
2-
import { assertThrowsAsync } from "https://deno.land/[email protected]/testing/asserts.ts";
1+
import { assertEquals, assertThrows } from "jsr:@std/assert";
32
import { RouterModule } from "../../../src/modules/router.js";
43

54
const sampleRoutes = {
@@ -24,7 +23,7 @@ const apiMock = {
2423
};
2524

2625
Deno.test("RouterModule init throws error if routes are not provided", async () => {
27-
await assertThrowsAsync(
26+
await assertThrows(
2827
async () => {
2928
await RouterModule.init({});
3029
},
@@ -52,7 +51,7 @@ Deno.test("RouterModule get returns correct route", async () => {
5251

5352
Deno.test("RouterModule get throws error for invalid route", async () => {
5453
await RouterModule.init({ routes: sampleRoutes });
55-
await assertThrowsAsync(
54+
await assertThrows(
5655
async () => {
5756
await RouterModule.get({ route: "invalid" });
5857
},
@@ -85,7 +84,7 @@ Deno.test("RouterModule.get - should throw an error if route is not found", asyn
8584
},
8685
});
8786

88-
await assertThrowsAsync(
87+
await assertThrows(
8988
async () => {
9089
await RouterModule.get({ route: "nonExistentRoute" });
9190
},
@@ -101,7 +100,7 @@ Deno.test("RouterModule.get - should throw an error if a parameter is missing",
101100
},
102101
});
103102

104-
await assertThrowsAsync(
103+
await assertThrows(
105104
async () => {
106105
await RouterModule.get({ route: "person" });
107106
},
@@ -126,7 +125,7 @@ Deno.test("RouterModule.get - should handle routes without parameters", async ()
126125
});
127126

128127
Deno.test("RouterModule.goto throws error when route is not provided", async () => {
129-
await assertThrowsAsync(
128+
await assertThrows(
130129
async () => {
131130
await RouterModule.goto({ params: {} });
132131
},

0 commit comments

Comments
 (0)