forked from miaulightouch/default-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
50 lines (41 loc) · 1.28 KB
/
Copy pathtest.js
File metadata and controls
50 lines (41 loc) · 1.28 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
"use strict";
const {v4, v6} = require(".");
const {env} = require("process");
const {isIPv4, isIPv6} = require("net");
const os = require("os");
const {test, expect} = global;
// only Darwin has IPv6 on GitHub Actions
const canTestV6 = env.CI ? os.platform() === "darwin" : true;
test("v4 async", async () => {
const result = await v4();
expect(isIPv4(result.gateway)).toBe(true);
expect(typeof result.interface).toBe("string");
});
test("v4 sync", () => {
const result = v4.sync();
expect(isIPv4(result.gateway)).toBe(true);
expect(typeof result.interface).toBe("string");
});
if (canTestV6) {
test("v6 async", async () => {
const result = await v6();
expect(isIPv6(result.gateway)).toBe(true);
expect(typeof result.interface).toBe("string");
});
test("v6 sync", () => {
const result = v6.sync();
expect(isIPv6(result.gateway)).toBe(true);
expect(typeof result.interface).toBe("string");
});
}
test("unsupported", async () => {
const mock = jest.spyOn(os, "platform");
mock.mockImplementation(() => "unsupported");
jest.resetModules();
const {v4, v6} = require(".");
expect(() => v4.sync()).toThrow();
expect(() => v6.sync()).toThrow();
await expect(v4()).rejects.toThrow();
await expect(v6()).rejects.toThrow();
mock.mockRestore();
});