feat: update deno commons
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
// Reference:
|
// Reference:
|
||||||
// - https://docs.deno.com/runtime/fundamentals/testing/
|
// - https://docs.deno.com/runtime/fundamentals/testing/
|
||||||
|
|
||||||
|
import { assert } from "jsr:@std/assert/assert";
|
||||||
import { assertEquals } from "jsr:@std/assert";
|
import { assertEquals } from "jsr:@std/assert";
|
||||||
|
|
||||||
|
export async function sleep(timeoutMillis: number): Promise<void> {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, timeoutMillis))
|
||||||
|
}
|
||||||
|
|
||||||
export function compareVersion(ver1: string, ver2: string): 0 | 1 | -1 {
|
export function compareVersion(ver1: string, ver2: string): 0 | 1 | -1 {
|
||||||
if (ver1 === ver2) return 0;
|
if (ver1 === ver2) return 0;
|
||||||
const ver1Parts = ver1.split(".");
|
const ver1Parts = ver1.split(".");
|
||||||
@@ -287,3 +292,10 @@ Deno.test("formatPercent", () => {
|
|||||||
assertEquals("0.00%", formatPercent(1, 100000));
|
assertEquals("0.00%", formatPercent(1, 100000));
|
||||||
assertEquals("100.00%", formatPercent(100, 100));
|
assertEquals("100.00%", formatPercent(100, 100));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("sleep", async () => {
|
||||||
|
const t1 = new Date().getTime();
|
||||||
|
await sleep(1000)
|
||||||
|
const t2 = new Date().getTime();
|
||||||
|
assert(Math.abs(1000 - (t2 - t1)) < 20);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user