-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathenv.test.ts
83 lines (67 loc) · 2.27 KB
/
env.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
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
import { assertEquals, assertStrictEquals } from "@std/assert";
import { describe, it } from "@std/testing/bdd";
import {
isBrowser,
isDevelopment,
isProduction,
isServer,
isTest,
} from "./env.ts";
import { startBrowser, startEnvironment } from "./test-utils.ts";
const isBrowserTests = describe("isBrowser");
it(isBrowserTests, "false in server", () => {
assertEquals(isBrowser(), false);
});
it(isBrowserTests, "true in browser", () => {
using _browser = startBrowser();
assertEquals(isBrowser(), true);
});
const isServerTests = describe("isServer");
it(isServerTests, "true in server", () => {
assertEquals(isServer(), true);
});
it(isServerTests, "false in browser", () => {
using _browser = startBrowser();
assertEquals(isServer(), false);
});
const isTestTests = describe("isTest");
it(isTestTests, "true in test", () => {
assertStrictEquals(isTest(), true);
});
it(isTestTests, "false in other environments", () => {
function checkEnvironment(appEnvironment: string) {
using _environment = startEnvironment(appEnvironment);
assertStrictEquals(isTest(), false);
}
checkEnvironment("development");
checkEnvironment("production");
checkEnvironment("fake");
});
const isDevelopmentTests = describe("isDevelopment");
it(isDevelopmentTests, "true in development", () => {
using _environment = startEnvironment("development");
assertStrictEquals(isDevelopment(), true);
});
it(isDevelopmentTests, "false in other environments", () => {
assertStrictEquals(isDevelopment(), false);
function checkEnvironment(appEnvironment: string) {
using _environment = startEnvironment(appEnvironment);
assertStrictEquals(isDevelopment(), false);
}
checkEnvironment("production");
checkEnvironment("fake");
});
const isProductionTests = describe("isProduction");
it(isProductionTests, "true in production", () => {
using _environment = startEnvironment("production");
assertStrictEquals(isProduction(), true);
});
it(isProductionTests, "false in other environments", () => {
assertStrictEquals(isProduction(), false);
function checkEnvironment(appEnvironment: string) {
using _environment = startEnvironment(appEnvironment);
assertStrictEquals(isProduction(), false);
}
checkEnvironment("development");
checkEnvironment("fake");
});