-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.test.ts
More file actions
73 lines (64 loc) · 2.23 KB
/
index.test.ts
File metadata and controls
73 lines (64 loc) · 2.23 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
import { ChildProcess } from "node:child_process";
import fs from "node:fs";
import { Tunnel, bin, install, service } from "../lib.js";
import { describe, it, expect, beforeAll } from "vitest";
process.env.VERBOSE = "1";
describe(
"install",
{ timeout: 60_000 },
() => {
it("should install binary", async () => {
if (fs.existsSync(bin)) {
fs.unlinkSync(bin);
}
expect(fs.existsSync(bin)).toBe(false);
await install(bin);
expect(fs.existsSync(bin)).toBe(true);
});
},
);
describe(
"tunnel",
{ timeout: 60_000 },
() => {
it("should create a tunnel", async () => {
const tunnel = new Tunnel(["tunnel", "--url", "localhost:8080", "--no-autoupdate"]);
const url = new Promise((resolve) => tunnel.once("url", resolve));
expect(await url).toMatch(/https?:\/\/[^\s]+/);
const conn = new Promise((resolve) => tunnel.once("connected", resolve));
await conn; // quick tunnel only has one connection
expect(tunnel.process).toBeInstanceOf(ChildProcess);
tunnel.stop();
});
},
);
describe("service", { timeout: 60_000 }, () => {
const TOKEN = process.env.TUNNEL_TOKEN;
const should_run =
TOKEN &&
["darwin", "linux"].includes(process.platform) &&
!(process.platform === "linux" && process.getuid?.() !== 0);
if (should_run) {
beforeAll(() => {
if (service.exists()) {
service.uninstall();
}
});
}
it("should work", async (ctx) => {
if (!should_run) {
ctx.skip();
}
expect(service.exists()).toBe(false);
service.install(TOKEN);
await new Promise((r) => setTimeout(r, 15_000));
expect(service.exists()).toBe(true);
const current = service.current();
expect(current.tunnelID.length).toBeGreaterThan(0);
expect(current.connectorID.length).toBeGreaterThan(0);
expect(current.connections.length).toBeGreaterThan(0);
expect(current.metrics.length).toBeGreaterThan(0);
expect(current.config.ingress?.length).toBeGreaterThan(0);
service.uninstall();
});
});