-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.ts
33 lines (26 loc) · 1.02 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Plausible from "./index.ts";
import { assert } from "@std/assert";
import { initializeEnv } from "./helper.ts";
// Initialize environment variables for test runs
initializeEnv(["PLAUSIBLE_TOKEN", "PLAUSIBLE_SITE", "PLAUSIBLE_URL"]);
const plausible = new Plausible(
Deno.env.get("PLAUSIBLE_TOKEN")!,
Deno.env.get("PLAUSIBLE_SITE")!,
Deno.env.get("PLAUSIBLE_URL")!,
);
Deno.test("retrieves the number of current visitors", async () => {
const currentVisitors = await plausible.getRealtime();
assert(typeof currentVisitors === "number");
});
Deno.test("retrieves aggregated data", async () => {
const data = await plausible.getAggregate("30d", "visitors");
assert(typeof data === "object");
});
Deno.test("retrieves timeseries data", async () => {
const data = await plausible.getTimeseries("30d", "visitors");
assert(Array.isArray(data));
});
Deno.test("retrieves breakdown data", async () => {
const data = await plausible.getBreakdown("30d", "pageviews", "visit:source");
assert(typeof data === "object");
});