aboutsummaryrefslogtreecommitdiff
path: root/tests/timing.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/timing.test.ts')
-rw-r--r--tests/timing.test.ts21
1 files changed, 15 insertions, 6 deletions
diff --git a/tests/timing.test.ts b/tests/timing.test.ts
index e2a0a06..589443d 100644
--- a/tests/timing.test.ts
+++ b/tests/timing.test.ts
@@ -8,15 +8,15 @@ import { expect, test } from "vitest";
/*** UTILITY ------------------------------------------ ***/
-import type { Fetcher, FetcherResult } from "../source/library/fetcher/types.ts";
-import { SessionStore } from "../source/library/state/session.svelte.ts";
import { createMemoryStorage } from "../source/library/state/storage.ts";
+import { SessionStore } from "../source/library/state/session.svelte.ts";
-function delay(ms: number): Promise<void> {
- return new Promise((resolve) => setTimeout(resolve, ms));
-}
+import {
+ type Fetcher,
+ type FetcherResult
+} from "../source/library/fetcher/types.ts";
-/*** TESTS -------------------------------------------- ***/
+/*** PROGRAM ------------------------------------------ ***/
test("run() populates timing for a one-shot fetcher", async () => {
const store = new SessionStore(createMemoryStorage());
@@ -54,8 +54,10 @@ test("run() records intervals between async iterable payloads", async () => {
async function* stream(): AsyncGenerator<FetcherResult> {
yield { data: { n: 1 } };
await delay(5);
+
yield { data: { n: 2 } };
await delay(5);
+
yield { data: { n: 3 } };
}
@@ -88,6 +90,7 @@ test("run() resets timing and streamIntervals on each invocation", async () => {
async function* stream(): AsyncGenerator<FetcherResult> {
yield { data: { n: 1 } };
await delay(5);
+
yield { data: { n: 2 } };
}
@@ -98,3 +101,9 @@ test("run() resets timing and streamIntervals on each invocation", async () => {
expect(tab.streamIntervals.length).toEqual(0);
expect(tab.timing).not.toBeNull();
});
+
+/*** HELPER ------------------------------------------- ***/
+
+function delay(ms: number): Promise<void> {
+ return new Promise((resolve) => setTimeout(resolve, ms));
+}