-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
85 lines (71 loc) · 1.96 KB
/
Copy pathtest.js
File metadata and controls
85 lines (71 loc) · 1.96 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import test from "ava";
import detectRuntime, {
isBrowser,
isBun,
isCloudflareWorkers,
isDeno,
isEdgeLight,
isNode,
isServiceWorker,
} from "./index.js";
test("detectRuntime() returns a string", (t) => {
const result = detectRuntime();
t.is(typeof result, "string");
});
test('detectRuntime() returns "node" in Node.js environment', (t) => {
t.is(detectRuntime(), "node");
});
test("isNode is true in Node.js environment", (t) => {
t.true(isNode);
});
test("isBun is false in Node.js environment", (t) => {
t.false(isBun);
});
test("isDeno is false in Node.js environment", (t) => {
t.false(isDeno);
});
test("isBrowser is false in Node.js environment", (t) => {
t.false(isBrowser);
});
test("isEdgeLight is false in Node.js environment", (t) => {
t.false(isEdgeLight);
});
test("isCloudflareWorkers is false in Node.js environment", (t) => {
t.false(isCloudflareWorkers);
});
test("isServiceWorker is false in Node.js environment", (t) => {
t.false(isServiceWorker);
});
test("detectRuntime is a function", (t) => {
t.is(typeof detectRuntime, "function");
});
test("detectRuntime returns one of the known runtime strings", (t) => {
const validRuntimes = new Set([
"node",
"bun",
"deno",
"browser",
"cloudflare-workers",
"service-worker",
"edge-light",
"unknown",
]);
t.true(validRuntimes.has(detectRuntime()));
});
test("boolean flags are all booleans", (t) => {
t.is(typeof isNode, "boolean");
t.is(typeof isBun, "boolean");
t.is(typeof isDeno, "boolean");
t.is(typeof isBrowser, "boolean");
t.is(typeof isEdgeLight, "boolean");
t.is(typeof isCloudflareWorkers, "boolean");
t.is(typeof isServiceWorker, "boolean");
});
test("exactly one primary runtime flag is true", (t) => {
const trueFlags = [isNode, isBun, isDeno].filter(Boolean);
t.is(trueFlags.length, 1);
});
test("detectRuntime() is the default export", (t) => {
t.is(typeof detectRuntime, "function");
t.is(detectRuntime.length, 0);
});