Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

プリロードのテスト等修正 #141

Merged
merged 4 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix test
  • Loading branch information
kamataryo committed Jan 19, 2022
commit aac6fd719030e23dfe7a6706c193f48d59f04472
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ yarn-error.log*

// Use npm
yarn.lock

test/*.zip
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "npm run test:main && npm run test:addresses && npm run test:preload",
"test:main": "jest test/main.test.ts",
"test:addresses": "jest test/addresses.test.ts",
"test:preload": "jest test/preload.test.ts",
"test:preload": "curl -sL https://github.com/geolonia/japanese-addresses/archive/refs/heads/master.zip > ./test/japanese-addresses-master.zip && jest test/preload.test.ts",
"test:generate-test-data": "npx ts-node -O '{\"module\":\"commonjs\"}' test/build-test-data.ts > test/addresses.csv",
"lint": "eslint \"src/**/*.ts\" --fix",
"build": "rm -rf ./dist && rollup -c ./rollup.config.ts"
Expand Down
20 changes: 13 additions & 7 deletions test/preload.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import { normalize, preload } from '../src/main-node'
import { normalize, config, preload } from '../src/main-node'
import { cachedTownRegexes } from '../src/lib/cacheRegexes'

import path from 'path'
import { performance } from 'perf_hooks'
import unfetch from 'isomorphic-unfetch'
jest.mock('isomorphic-unfetch') // disable request for testing

jest.setTimeout(3 * 60 * 1000)
beforeAll(async () => {
config.preloadCache = true
config.japaneseAddressesApi =
'file:/' + path.resolve(__dirname, 'japanese-addresses-master.zip')
console.time('preload')
await preload()
console.timeEnd('preload')
jest.setTimeout(5000)
})

test('should preload cache', () => {
expect(cachedTownRegexes.length).toBeGreaterThan(1800)
}, 5000)
})

test('normalize should take less than 200ms to complete', async () => {
test('normalize should complete in the local environment', async () => {
const started = performance.now()
await normalize('京都府京田辺市同志社山手4丁目1-43')
const finished = performance.now()
console.log(finished - started)
expect(finished - started).toBeLessThan(200)
}, 5000)
console.log('performance(ms): ', finished - started)
expect(unfetch).not.toBeCalled()
})