mirror of
https://github.com/netfun2000/ip2region.git
synced 2026-02-27 09:44:31 +08:00
集成单元测试&覆盖率报告
This commit is contained in:
29
binding/nodejs/tests/function.test.js
Normal file
29
binding/nodejs/tests/function.test.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const { expect } = require('chai')
|
||||
const path = require('path')
|
||||
const Searcher = require('..')
|
||||
|
||||
const dbPath = path.join(__dirname, '..', '..', '..', 'data', 'ip2region.xdb')
|
||||
const buffer = Searcher.loadContentFromFile(dbPath)
|
||||
const searcher1 = Searcher.newWithBuffer(buffer)
|
||||
|
||||
const vectorIndex = Searcher.loadVectorIndexFromFile(dbPath)
|
||||
const searcher2 = Searcher.newWithVectorIndex(dbPath, vectorIndex)
|
||||
|
||||
const searcher3 = Searcher.newWithFileOnly(dbPath)
|
||||
|
||||
describe('ip2region', () => {
|
||||
it('#newWithFileOnly', async () => {
|
||||
const d = await searcher3.search('218.4.167.70')
|
||||
expect(d).equal('中国|0|江苏省|苏州市|电信')
|
||||
})
|
||||
|
||||
it('#newWithVectorIndex', async () => {
|
||||
const d = await searcher2.search('218.4.167.70')
|
||||
expect(d).equal('中国|0|江苏省|苏州市|电信')
|
||||
})
|
||||
|
||||
it('#newWithBuffer', async () => {
|
||||
const d = await searcher1.search('218.4.167.70')
|
||||
expect(d).equal('中国|0|江苏省|苏州市|电信')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user