|
| 1 | +import {test} from 'node:test'; |
| 2 | +import assert from 'node:assert'; |
1 | 3 | import process from 'node:process'; |
2 | | -import test from 'ava'; |
3 | | -import isIp from 'is-ip'; |
| 4 | +import {isIP, isIPv4} from 'is-ip'; |
4 | 5 | import ipify from './index.js'; |
5 | 6 |
|
6 | 7 | // GitHub Actions doesn't support IPv6: https://github.com/actions/virtual-environments/issues/668 |
7 | 8 | if (!process.env.CI) { |
8 | | - test('main', async t => { |
9 | | - t.true(isIp(await ipify())); |
| 9 | + test('main', async () => { |
| 10 | + assert.ok(isIP(await ipify())); |
10 | 11 | }); |
11 | 12 | } |
12 | 13 |
|
13 | | -test('useIPv6:false', async t => { |
14 | | - t.true(isIp.v4(await ipify({useIPv6: false}))); |
| 14 | +test('useIPv6:false', async () => { |
| 15 | + assert.ok(isIPv4(await ipify({useIPv6: false}))); |
15 | 16 | }); |
16 | 17 |
|
17 | | -test('endpoint:custom', async t => { |
18 | | - t.true(isIp.v4(await ipify({endpoint: 'https://api.ipify.org'}))); |
| 18 | +test('endpoint:custom', async () => { |
| 19 | + assert.ok(isIPv4(await ipify({endpoint: 'https://api.ipify.org'}))); |
19 | 20 | }); |
20 | 21 |
|
21 | | -test('endpoint:array', async t => { |
| 22 | +test('endpoint:array', async () => { |
22 | 23 | const result = await ipify({ |
23 | 24 | endpoint: [ |
24 | 25 | 'https://api.ipify.org', |
25 | 26 | 'https://api6.ipify.org', |
26 | 27 | ], |
27 | 28 | }); |
28 | | - t.true(isIp(result)); |
| 29 | + assert.ok(isIP(result)); |
29 | 30 | }); |
30 | 31 |
|
31 | | -test('endpoint:empty array throws', async t => { |
32 | | - await t.throwsAsync( |
| 32 | +test('endpoint:empty array throws', async () => { |
| 33 | + await assert.rejects( |
33 | 34 | ipify({endpoint: []}), |
34 | | - {instanceOf: TypeError, message: 'Endpoint array cannot be empty'}, |
| 35 | + {name: 'TypeError', message: 'Endpoint array cannot be empty'}, |
35 | 36 | ); |
36 | 37 | }); |
37 | 38 |
|
38 | | -test('endpoint:single-item array', async t => { |
| 39 | +test('endpoint:single-item array', async () => { |
39 | 40 | const result = await ipify({ |
40 | 41 | endpoint: ['https://api.ipify.org'], |
41 | 42 | }); |
42 | | - t.true(isIp.v4(result)); |
| 43 | + assert.ok(isIPv4(result)); |
43 | 44 | }); |
44 | 45 |
|
45 | | -test('endpoint overrides useIPv6', async t => { |
| 46 | +test('endpoint overrides useIPv6', async () => { |
46 | 47 | const result = await ipify({ |
47 | 48 | useIPv6: true, |
48 | 49 | endpoint: 'https://api.ipify.org', |
49 | 50 | }); |
50 | | - t.true(isIp.v4(result)); |
| 51 | + assert.ok(isIPv4(result)); |
51 | 52 | }); |
52 | 53 |
|
53 | | -test('endpoint:array with duplicates', async t => { |
| 54 | +test('endpoint:array with duplicates', async () => { |
54 | 55 | const result = await ipify({ |
55 | 56 | endpoint: [ |
56 | 57 | 'https://api.ipify.org', |
57 | 58 | 'https://api.ipify.org', |
58 | 59 | ], |
59 | 60 | }); |
60 | | - t.true(isIp.v4(result)); |
| 61 | + assert.ok(isIPv4(result)); |
61 | 62 | }); |
0 commit comments