forked from geolonia/normalize-japanese-addresses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.test.ts
47 lines (40 loc) · 1.56 KB
/
fs.test.ts
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
import { normalize, config } from '../src/main-node'
import path from 'path'
import { performance } from 'perf_hooks'
import unfetch from 'isomorphic-unfetch'
jest.mock('isomorphic-unfetch') // disable request for testing
const defaultEndpoint = config.japaneseAddressesApi
describe('file://', () => {
jest.setTimeout(3 * 60 * 1000)
beforeAll(async () => {
config.japaneseAddressesApi =
'file://' +
path.resolve(__dirname, 'japanese-addresses-master', 'api', 'ja')
jest.setTimeout(5000)
})
test('normalize should complete in the local environment', async () => {
const started1 = performance.now()
await normalize('京都府京田辺市同志社山手4丁目1-43')
const finished1 = performance.now()
console.log('nocache performance(ms): ', finished1 - started1)
const started2 = performance.now()
await normalize('京都府京田辺市同志社山手4丁目1-44')
const finished2 = performance.now()
console.log('with-cache performance(ms): ', finished2 - started2)
expect(unfetch).not.toBeCalled()
})
})
describe('http://', () => {
jest.setTimeout(3 * 60 * 1000)
beforeAll(async () => {
config.japaneseAddressesApi = defaultEndpoint
config.geoloniaApiKey = 'MY-KEY'
jest.setTimeout(5000)
})
test('Should request with Geolonia backend', async () => {
await normalize('京都府京田辺市同志社山手4丁目1-44')
expect(unfetch).toBeCalled()
const args = (unfetch as jest.Mock).mock.calls[0]
expect(args[0]).toMatch(/geolonia-api-key=MY-KEY$/)
})
})