-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2530fae
commit 8d06345
Showing
22 changed files
with
153 additions
and
168 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export async function setup(): Promise<void> {} | ||
export async function teardown(): Promise<void> {} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import "../setup.js"; | ||
import {expect} from "chai"; | ||
import {describe, it, expect} from "vitest"; | ||
import {toBase64, fromBase64} from "../../src/index.js"; | ||
|
||
describe("toBase64", () => { | ||
it("should encode UTF-8 string as base64 string", () => { | ||
expect(toBase64("user:password")).to.be.equal("dXNlcjpwYXNzd29yZA=="); | ||
expect(toBase64("user:password")).toBe("dXNlcjpwYXNzd29yZA=="); | ||
}); | ||
}); | ||
|
||
describe("fromBase64", () => { | ||
it("should decode UTF-8 string from base64 string", () => { | ||
expect(fromBase64("dXNlcjpwYXNzd29yZA==")).to.be.equal("user:password"); | ||
expect(fromBase64("dXNlcjpwYXNzd29yZA==")).toBe("user:password"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {describe, it, expect, vi, beforeEach, afterEach} from "vitest"; | ||
import {callFnWhenAwait} from "../../src/promise.js"; | ||
|
||
// TODO: Need to debug why vi.useFakeTimers() is not working for the browsers | ||
describe("callFnWhenAwait util", function () { | ||
beforeEach(() => { | ||
vi.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllTimers(); | ||
}); | ||
|
||
it("should call function while awaing for promise", async () => { | ||
const p = new Promise<string>((resolve) => setTimeout(() => resolve("done"), 5 * 1000)); | ||
const stub = vi.fn(); | ||
const result = await Promise.all([callFnWhenAwait(p, stub, 2 * 1000), vi.advanceTimersByTimeAsync(5000)]); | ||
expect(result[0]).toBe("done"); | ||
expect(stub).toHaveBeenCalledTimes(2); | ||
await vi.advanceTimersByTimeAsync(5000); | ||
expect(stub).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it("should throw error", async () => { | ||
const stub = vi.fn(); | ||
const p = new Promise<string>((_, reject) => setTimeout(() => reject(new Error("done")), 5 * 1000)); | ||
try { | ||
await Promise.all([callFnWhenAwait(p, stub, 2 * 1000), vi.advanceTimersByTimeAsync(5000)]); | ||
expect.fail("should throw error here"); | ||
} catch (e) { | ||
expect((e as Error).message).toBe("done"); | ||
expect(stub).toHaveBeenCalledTimes(2); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.