Skip to content

Commit 8329375

Browse files
committed
chore: expect.soft
1 parent 76159c1 commit 8329375

23 files changed

+300
-306
lines changed

packages/country-extra/src/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import IpLookup from './index'
55

66
describe('ipLookup', () => {
77
it('should export the IpLookup function', () => {
8-
expect(IpLookup).toBeDefined()
9-
expect(typeof IpLookup).toBe('function')
8+
expect.soft(IpLookup).toBeDefined()
9+
expect.soft(typeof IpLookup).toBe('function')
1010
expectTypeOf(IpLookup).toEqualTypeOf<(ipInput: string) => Promise<{
1111
country: string
1212
country_name: string
@@ -32,8 +32,8 @@ describe('ipLookup', () => {
3232
})
3333
})
3434
const result = await IpLookup('207.97.227.239')
35-
expect(result).not.toBeNull()
36-
expect(result).toEqual({
35+
expect.soft(result).not.toBeNull()
36+
expect.soft(result).toEqual({
3737
country: 'US',
3838
country_name: 'United States',
3939
country_native: 'United States',
@@ -49,8 +49,8 @@ describe('ipLookup', () => {
4949
})
5050

5151
const result2 = await IpLookup('2607:F8B0:4005:801::200E')
52-
expect(result2).not.toBeNull()
53-
expect(result2).toEqual({
52+
expect.soft(result2).not.toBeNull()
53+
expect.soft(result2).toEqual({
5454
country: 'US',
5555
country_name: 'United States',
5656
country_native: 'United States',
@@ -65,6 +65,6 @@ describe('ipLookup', () => {
6565
languages: ['en'],
6666
})
6767

68-
await expect(IpLookup('invalid')).rejects.toThrow('Invalid IPv4 address: invalid')
68+
await expect.soft(IpLookup('invalid')).rejects.toThrow('Invalid IPv4 address: invalid')
6969
})
7070
})

packages/country/src/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import IpLookup from './index'
55

66
describe('ipLookup', () => {
77
it('should export the IpLookup function', () => {
8-
expect(IpLookup).toBeDefined()
9-
expect(typeof IpLookup).toBe('function')
8+
expect.soft(IpLookup).toBeDefined()
9+
expect.soft(typeof IpLookup).toBe('function')
1010
expectTypeOf(IpLookup).toEqualTypeOf<(ipInput: string) => Promise<{ country: string } | null>>()
1111
})
1212

@@ -23,13 +23,13 @@ describe('ipLookup', () => {
2323
})
2424
})
2525
const result = await IpLookup('207.97.227.239')
26-
expect(result).not.toBeNull()
27-
expect(result).toEqual({ country: 'US' })
26+
expect.soft(result).not.toBeNull()
27+
expect.soft(result).toEqual({ country: 'US' })
2828

2929
const result2 = await IpLookup('2607:F8B0:4005:801::200E')
30-
expect(result2).not.toBeNull()
31-
expect(result2).toEqual({ country: 'US' })
30+
expect.soft(result2).not.toBeNull()
31+
expect.soft(result2).toEqual({ country: 'US' })
3232

33-
await expect(IpLookup('invalid')).rejects.toThrow('Invalid IPv4 address: invalid')
33+
await expect.soft(IpLookup('invalid')).rejects.toThrow('Invalid IPv4 address: invalid')
3434
})
3535
})

packages/geocode-extra/src/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import IpLookup from './index'
55

66
describe('ipLookup', () => {
77
it('should export the IpLookup function', () => {
8-
expect(IpLookup).toBeDefined()
9-
expect(typeof IpLookup).toBe('function')
8+
expect.soft(IpLookup).toBeDefined()
9+
expect.soft(typeof IpLookup).toBe('function')
1010
expectTypeOf(IpLookup).toEqualTypeOf<(ipInput: string) => Promise<{
1111
latitude: number
1212
longitude: number
@@ -34,8 +34,8 @@ describe('ipLookup', () => {
3434
})
3535
})
3636
const result = await IpLookup('207.97.227.239')
37-
expect(result).not.toBeNull()
38-
expect(result).toEqual({
37+
expect.soft(result).not.toBeNull()
38+
expect.soft(result).toEqual({
3939
country: 'US',
4040
country_name: 'United States',
4141
country_native: 'United States',
@@ -51,8 +51,8 @@ describe('ipLookup', () => {
5151
})
5252

5353
const result2 = await IpLookup('2607:F8B0:4005:801::200E')
54-
expect(result2).not.toBeNull()
55-
expect(result2).toEqual({
54+
expect.soft(result2).not.toBeNull()
55+
expect.soft(result2).toEqual({
5656
country: 'US',
5757
country_name: 'United States',
5858
country_native: 'United States',
@@ -67,6 +67,6 @@ describe('ipLookup', () => {
6767
languages: ['en'],
6868
})
6969

70-
await expect(IpLookup('invalid')).rejects.toThrow('Invalid IPv4 address: invalid')
70+
await expect.soft(IpLookup('invalid')).rejects.toThrow('Invalid IPv4 address: invalid')
7171
})
7272
})

packages/geocode/src/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import IpLookup from './index'
55

66
describe('ipLookup', () => {
77
it('should export the IpLookup function', () => {
8-
expect(IpLookup).toBeDefined()
9-
expect(typeof IpLookup).toBe('function')
8+
expect.soft(IpLookup).toBeDefined()
9+
expect.soft(typeof IpLookup).toBe('function')
1010
expectTypeOf(IpLookup).toEqualTypeOf<(ipInput: string) => Promise<{
1111
latitude: number
1212
longitude: number
@@ -27,17 +27,17 @@ describe('ipLookup', () => {
2727
})
2828
})
2929
const result = await IpLookup('207.97.227.239')
30-
expect(result).not.toBeNull()
31-
expect(result).toEqual({
30+
expect.soft(result).not.toBeNull()
31+
expect.soft(result).toEqual({
3232
country: 'US',
3333
})
3434

3535
const result2 = await IpLookup('2607:F8B0:4005:801::200E')
36-
expect(result2).not.toBeNull()
37-
expect(result2).toEqual({
36+
expect.soft(result2).not.toBeNull()
37+
expect.soft(result2).toEqual({
3838
country: 'US',
3939
})
4040

41-
await expect(IpLookup('invalid')).rejects.toThrow('Invalid IPv4 address: invalid')
41+
await expect.soft(IpLookup('invalid')).rejects.toThrow('Invalid IPv4 address: invalid')
4242
})
4343
})

packages/ip-location-api/src/index.test.ts

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,31 @@ describe('lookup (country)', () => {
2323
it('should return the country for a valid IP address', async ({ expect }) => {
2424
//* Ipv4
2525
const result = await lookup('8.8.8.8')
26-
expect(result).not.toBeNull()
27-
expect(result).toEqual({ country: 'US' })
26+
expect.soft(result).not.toBeNull()
27+
expect.soft(result).toEqual({ country: 'US' })
2828

2929
const result2 = await lookup('207.97.227.239')
30-
expect(result2).not.toBeNull()
31-
expect(result2).toEqual({ country: 'US' })
30+
expect.soft(result2).not.toBeNull()
31+
expect.soft(result2).toEqual({ country: 'US' })
3232

3333
//* Ipv6
3434
const result3 = await lookup('2607:F8B0:4005:801::200E')
35-
expect(result3).not.toBeNull()
36-
expect(result3).toEqual({ country: 'US' })
35+
expect.soft(result3).not.toBeNull()
36+
expect.soft(result3).toEqual({ country: 'US' })
3737

3838
//* Invalid IP address
39-
await expect(lookup('invalid')).rejects.toThrowError('Invalid IPv4 address: invalid')
39+
await expect.soft(lookup('invalid')).rejects.toThrowError('Invalid IPv4 address: invalid')
4040

4141
//* Too high IP address
42-
expect(await lookup('256.256.256.256')).toBeNull()
42+
await expect.soft(lookup('256.256.256.256')).resolves.toBeNull()
4343

4444
//* Clear data
4545
clear()
4646

4747
//* Ips should return null after data is cleared
48-
const result4 = await lookup('8.8.8.8')
49-
expect(result4).toBeNull()
48+
await expect.soft(lookup('8.8.8.8')).resolves.toBeNull()
5049

51-
const result5 = await lookup('2607:F8B0:4005:801::200E')
52-
expect(result5).toBeNull()
50+
await expect.soft(lookup('2607:F8B0:4005:801::200E')).resolves.toBeNull()
5351
})
5452
})
5553

@@ -74,33 +72,31 @@ describe('lookup (country, smallMemory)', () => {
7472
it('should return the country for a valid IP address', async ({ expect }) => {
7573
//* Ipv4
7674
const result = await lookup('8.8.8.8')
77-
expect(result).not.toBeNull()
78-
expect(result).toEqual({ country: 'US' })
75+
expect.soft(result).not.toBeNull()
76+
expect.soft(result).toEqual({ country: 'US' })
7977

8078
const result2 = await lookup('207.97.227.239')
81-
expect(result2).not.toBeNull()
82-
expect(result2).toEqual({ country: 'US' })
79+
expect.soft(result2).not.toBeNull()
80+
expect.soft(result2).toEqual({ country: 'US' })
8381

8482
//* Ipv6
8583
const result3 = await lookup('2607:F8B0:4005:801::200E')
86-
expect(result3).not.toBeNull()
87-
expect(result3).toEqual({ country: 'US' })
84+
expect.soft(result3).not.toBeNull()
85+
expect.soft(result3).toEqual({ country: 'US' })
8886

8987
//* Invalid IP address
90-
await expect(lookup('invalid')).rejects.toThrowError('Invalid IPv4 address: invalid')
88+
await expect.soft(lookup('invalid')).rejects.toThrowError('Invalid IPv4 address: invalid')
9189

9290
//* Too high IP address
93-
expect(await lookup('256.256.256.256')).toBeNull()
91+
await expect.soft(lookup('256.256.256.256')).resolves.toBeNull()
9492

9593
//* Clear data
9694
clear()
9795

9896
//* Ips should return null after data is cleared
99-
const result4 = await lookup('8.8.8.8')
100-
expect(result4).toBeNull()
97+
await expect.soft(lookup('8.8.8.8')).resolves.toBeNull()
10198

102-
const result5 = await lookup('2607:F8B0:4005:801::200E')
103-
expect(result5).toBeNull()
99+
await expect.soft(lookup('2607:F8B0:4005:801::200E')).resolves.toBeNull()
104100
})
105101
})
106102

@@ -124,13 +120,13 @@ describe('lookup (city)', () => {
124120
it('should return the city and country for a valid IP address', async ({ expect }) => {
125121
//* Ipv4
126122
const result = await lookup('170.171.1.0')
127-
expect(result).not.toBeNull()
128-
expect(result).toEqual({ city: 'New York', country: 'US' })
123+
expect.soft(result).not.toBeNull()
124+
expect.soft(result).toEqual({ city: 'New York', country: 'US' })
129125

130126
//* Ipv6
131127
const result2 = await lookup('2606:2e00:8003::216:3eff:fe82:68ab')
132-
expect(result2).not.toBeNull()
133-
expect(result2).toEqual({ city: 'New York', country: 'US' })
128+
expect.soft(result2).not.toBeNull()
129+
expect.soft(result2).toEqual({ city: 'New York', country: 'US' })
134130
})
135131
})
136132

@@ -156,8 +152,8 @@ describe('lookup (all, smallMemory)', () => {
156152
it('should return all fields for a valid IP address', async ({ expect }) => {
157153
//* Ipv4 (Metro code)
158154
const result1 = await lookup('170.171.1.0')
159-
expect(result1).not.toBeNull()
160-
expect(result1).toEqual({
155+
expect.soft(result1).not.toBeNull()
156+
expect.soft(result1).toEqual({
161157
area: 10,
162158
capital: 'Washington D.C.',
163159
city: 'New York',
@@ -189,8 +185,8 @@ describe('lookup (all, smallMemory)', () => {
189185

190186
//* Ipv4 (Region2)
191187
const result2 = await lookup('213.189.170.238')
192-
expect(result2).not.toBeNull()
193-
expect(result2).toEqual({
188+
expect.soft(result2).not.toBeNull()
189+
expect.soft(result2).toEqual({
194190
area: 50,
195191
capital: 'Brussels',
196192
city: 'Charleroi',
@@ -238,14 +234,14 @@ describe('lookup (all, smallMemory)', () => {
238234

239235
for (const { ip, postcode } of postalCodesTest) {
240236
const result = await lookup(ip)
241-
expect(result).not.toBeNull()
242-
expect(result).toMatchObject({ postcode })
237+
expect.soft(result).not.toBeNull()
238+
expect.soft(result).toMatchObject({ postcode })
243239
}
244240

245241
//* Ipv6
246242
const result4 = await lookup('2607:F8B0:4005:801::200E')
247-
expect(result4).not.toBeNull()
248-
expect(result4).toEqual({
243+
expect.soft(result4).not.toBeNull()
244+
expect.soft(result4).toEqual({
249245
area: 1000,
250246
capital: 'Washington D.C.',
251247
continent: 'NA',
@@ -271,19 +267,17 @@ describe('lookup (all, smallMemory)', () => {
271267
})
272268

273269
//* Invalid IP address
274-
await expect(lookup('invalid')).rejects.toThrowError('Invalid IPv4 address: invalid')
270+
await expect.soft(lookup('invalid')).rejects.toThrowError('Invalid IPv4 address: invalid')
275271

276272
//* Too high IP address
277-
expect(await lookup('256.256.256.256')).toBeNull()
273+
await expect.soft(lookup('256.256.256.256')).resolves.toBeNull()
278274

279275
//* Clear data
280276
clear()
281277

282278
//* Ips should return null after data is cleared
283-
const result5 = await lookup('8.8.8.8')
284-
expect(result5).toBeNull()
279+
await expect.soft(lookup('8.8.8.8')).resolves.toBeNull()
285280

286-
const result6 = await lookup('2607:F8B0:4005:801::200E')
287-
expect(result6).toBeNull()
281+
await expect.soft(lookup('2607:F8B0:4005:801::200E')).resolves.toBeNull()
288282
})
289283
})

packages/util/src/functions/aton4.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ import { aton4 } from './aton4'
33

44
describe('aton4', () => {
55
it('should convert valid IPv4 addresses to 32-bit integers', () => {
6-
expect(aton4('192.168.1.1')).toBe(3232235777)
7-
expect(aton4('10.0.0.1')).toBe(167772161)
8-
expect(aton4('172.16.0.1')).toBe(2886729729)
9-
expect(aton4('255.255.255.255')).toBe(4294967295)
10-
expect(aton4('207.97.227.239')).toBe(3479299055)
11-
expect(aton4('0.0.0.0')).toBe(0)
6+
expect.soft(aton4('192.168.1.1')).toBe(3232235777)
7+
expect.soft(aton4('10.0.0.1')).toBe(167772161)
8+
expect.soft(aton4('172.16.0.1')).toBe(2886729729)
9+
expect.soft(aton4('255.255.255.255')).toBe(4294967295)
10+
expect.soft(aton4('207.97.227.239')).toBe(3479299055)
11+
expect.soft(aton4('0.0.0.0')).toBe(0)
1212
})
1313

1414
it('should handle leading zeros in octets', () => {
15-
expect(aton4('192.168.001.001')).toBe(3232235777)
16-
expect(aton4('010.000.000.001')).toBe(167772161)
15+
expect.soft(aton4('192.168.001.001')).toBe(3232235777)
16+
expect.soft(aton4('010.000.000.001')).toBe(167772161)
1717
})
1818

1919
it('should throw an error for invalid IPv4 addresses', () => {
20-
expect(() => aton4('192.168.1')).toThrow('Invalid IPv4 address: 192.168.1')
21-
expect(() => aton4('192.168.1.1.1')).toThrow('Invalid IPv4 address: 192.168.1.1.1')
22-
expect(() => aton4('')).toThrow('Invalid IPv4 address: ')
20+
expect.soft(() => aton4('192.168.1')).toThrow('Invalid IPv4 address: 192.168.1')
21+
expect.soft(() => aton4('192.168.1.1.1')).toThrow('Invalid IPv4 address: 192.168.1.1.1')
22+
expect.soft(() => aton4('')).toThrow('Invalid IPv4 address: ')
2323
})
2424

2525
it('should handle edge cases', () => {
26-
expect(aton4('127.0.0.1')).toBe(2130706433) // Localhost
27-
expect(aton4('255.255.255.0')).toBe(4294967040) // Subnet mask
28-
expect(aton4('1.2.3.4')).toBe(16909060)
26+
expect.soft(aton4('127.0.0.1')).toBe(2130706433) // Localhost
27+
expect.soft(aton4('255.255.255.0')).toBe(4294967040) // Subnet mask
28+
expect.soft(aton4('1.2.3.4')).toBe(16909060)
2929
})
3030

3131
it('should handle all zeros and all ones', () => {
32-
expect(aton4('0.0.0.0')).toBe(0)
33-
expect(aton4('255.255.255.255')).toBe(4294967295)
32+
expect.soft(aton4('0.0.0.0')).toBe(0)
33+
expect.soft(aton4('255.255.255.255')).toBe(4294967295)
3434
})
3535
})

0 commit comments

Comments
 (0)