forked from sindresorhus/ipify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
62 lines (54 loc) · 1.41 KB
/
test.js
File metadata and controls
62 lines (54 loc) · 1.41 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
import {test} from 'node:test';
import assert from 'node:assert';
import process from 'node:process';
import {isIP, isIPv4} from 'is-ip';
import ipify from './index.js';
// GitHub Actions doesn't support IPv6: https://github.com/actions/virtual-environments/issues/668
if (!process.env.CI) {
test('main', async () => {
assert.ok(isIP(await ipify()));
});
}
test('useIPv6:false', async () => {
assert.ok(isIPv4(await ipify({useIPv6: false})));
});
test('endpoint:custom', async () => {
assert.ok(isIPv4(await ipify({endpoint: 'https://api.ipify.org'})));
});
test('endpoint:array', async () => {
const result = await ipify({
endpoint: [
'https://api.ipify.org',
'https://api6.ipify.org',
],
});
assert.ok(isIP(result));
});
test('endpoint:empty array throws', async () => {
await assert.rejects(
ipify({endpoint: []}),
{name: 'TypeError', message: 'Endpoint array cannot be empty'},
);
});
test('endpoint:single-item array', async () => {
const result = await ipify({
endpoint: ['https://api.ipify.org'],
});
assert.ok(isIPv4(result));
});
test('endpoint overrides useIPv6', async () => {
const result = await ipify({
useIPv6: true,
endpoint: 'https://api.ipify.org',
});
assert.ok(isIPv4(result));
});
test('endpoint:array with duplicates', async () => {
const result = await ipify({
endpoint: [
'https://api.ipify.org',
'https://api.ipify.org',
],
});
assert.ok(isIPv4(result));
});