mirror of
https://github.com/lionsoul2014/ip2region.git
synced 2025-12-08 19:25:22 +00:00
集成单元测试&覆盖率报告
This commit is contained in:
parent
7f6cac9e09
commit
12aee0894d
@ -4,12 +4,14 @@ module.exports = {
|
||||
commonjs: true,
|
||||
es2021: true
|
||||
},
|
||||
extends: [
|
||||
'standard'
|
||||
],
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest'
|
||||
},
|
||||
rules: {
|
||||
extends: [
|
||||
'standard'
|
||||
],
|
||||
globals: {
|
||||
describe: true,
|
||||
it: true
|
||||
}
|
||||
}
|
||||
|
||||
5
binding/nodejs/.mocharc.json
Normal file
5
binding/nodejs/.mocharc.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"reporter": "spec",
|
||||
"timeout": 60000,
|
||||
"exit": true
|
||||
}
|
||||
5
binding/nodejs/.nycrc.json
Normal file
5
binding/nodejs/.nycrc.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"all": true,
|
||||
"report-dir": "./coverage/",
|
||||
"reporter": ["text", "html"]
|
||||
}
|
||||
@ -8,18 +8,6 @@
|
||||
|
||||
### 缓存整个 `xdb` 数据
|
||||
|
||||
```js
|
||||
const Ip2Region = require('./')
|
||||
|
||||
const ip2region = new Ip2Region()
|
||||
|
||||
// 注意:这边是同步代码,生产环境建议只执行一次初始化, 并且数据是存放在内存中的
|
||||
ip2region.load('../../data/ip2region.xdb')
|
||||
|
||||
const info = ip2region.search('202.97.77.50')
|
||||
|
||||
```
|
||||
|
||||
## 查询测试
|
||||
|
||||
## bench 测试
|
||||
|
||||
1396
binding/nodejs/package-lock.json
generated
1396
binding/nodejs/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,21 +1,28 @@
|
||||
{
|
||||
"name": "ip2region",
|
||||
"version": "1.0.0",
|
||||
"description": "ip2region",
|
||||
"version": "2.0.0",
|
||||
"description": "official nodejs client of ip2region",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "node ./tests/test.js"
|
||||
"lint": "eslint ./index.js",
|
||||
"test": "mocha ./tests/function.test.js",
|
||||
"coverage": "nyc npm run test",
|
||||
"benchmark": "node ./tests/benchmark.js"
|
||||
},
|
||||
"author": "",
|
||||
"author": "Wu Jian Ping",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.3.1",
|
||||
"@types/node": "^18.0.6",
|
||||
"benchmark": "^2.1.4",
|
||||
"chai": "^4.3.6",
|
||||
"eslint": "^8.20.0",
|
||||
"eslint-config-standard": "^17.0.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-n": "^15.2.4",
|
||||
"eslint-plugin-promise": "^6.0.0"
|
||||
"eslint-plugin-promise": "^6.0.0",
|
||||
"mocha": "^10.0.0",
|
||||
"nyc": "^15.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
|
||||
49
binding/nodejs/test.js
Normal file
49
binding/nodejs/test.js
Normal file
@ -0,0 +1,49 @@
|
||||
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)
|
||||
|
||||
;(async () => {
|
||||
const data1 = await Promise
|
||||
.all([
|
||||
searcher1.search('202.97.77.50'),
|
||||
searcher1.search('218.4.167.70'),
|
||||
searcher1.search('112.31.187.151'),
|
||||
searcher1.search('202.98.17.164'),
|
||||
searcher1.search('170.148.132.136'),
|
||||
searcher1.search('194.138.202.210')
|
||||
])
|
||||
|
||||
console.log(data1)
|
||||
|
||||
const data2 = await Promise
|
||||
.all([
|
||||
searcher2.search('202.97.77.50'),
|
||||
searcher2.search('218.4.167.70'),
|
||||
searcher2.search('112.31.187.151'),
|
||||
searcher2.search('202.98.17.164'),
|
||||
searcher2.search('170.148.132.136'),
|
||||
searcher2.search('194.138.202.210')
|
||||
])
|
||||
|
||||
console.log(data2)
|
||||
|
||||
const data3 = await Promise
|
||||
.all([
|
||||
searcher3.search('202.97.77.50'),
|
||||
searcher3.search('218.4.167.70'),
|
||||
searcher3.search('112.31.187.151'),
|
||||
searcher3.search('202.98.17.164'),
|
||||
searcher3.search('170.148.132.136'),
|
||||
searcher3.search('194.138.202.210')
|
||||
])
|
||||
|
||||
console.log(data3)
|
||||
})()
|
||||
@ -1,7 +1,8 @@
|
||||
const Benchmark = require('benchmark')
|
||||
const path = require('path')
|
||||
const Searcher = require('..')
|
||||
|
||||
const dbPath = '../../../data/ip2region.xdb'
|
||||
const dbPath = path.join(__dirname, '..', '..', '..', 'data', 'ip2region.xdb')
|
||||
const buffer = Searcher.loadContentFromFile(dbPath)
|
||||
const seacher = Searcher.newWithBuffer(buffer)
|
||||
|
||||
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|江苏省|苏州市|电信')
|
||||
})
|
||||
})
|
||||
@ -1,49 +0,0 @@
|
||||
const path = require('path')
|
||||
const Searcher = require('..')
|
||||
|
||||
const dbPath = path.join(__dirname, '..', '..', '..', 'data', 'ip2region.xdb')
|
||||
const buffer = Searcher.loadContentFromFile(dbPath)
|
||||
const seacher1 = Searcher.newWithBuffer(buffer)
|
||||
|
||||
const vectorIndex = Searcher.loadVectorIndexFromFile(dbPath)
|
||||
const seacher2 = Searcher.newWithVectorIndex(dbPath, vectorIndex)
|
||||
|
||||
const seacher3 = Searcher.newWithFileOnly(dbPath)
|
||||
|
||||
;(async () => {
|
||||
const data1 = await Promise
|
||||
.all([
|
||||
seacher1.search('202.97.77.50'),
|
||||
seacher1.search('218.4.167.70'),
|
||||
seacher1.search('112.31.187.151'),
|
||||
seacher1.search('202.98.17.164'),
|
||||
seacher1.search('170.148.132.136'),
|
||||
seacher1.search('194.138.202.210')
|
||||
])
|
||||
|
||||
console.log(data1)
|
||||
|
||||
const data2 = await Promise
|
||||
.all([
|
||||
seacher2.search('202.97.77.50'),
|
||||
seacher2.search('218.4.167.70'),
|
||||
seacher2.search('112.31.187.151'),
|
||||
seacher2.search('202.98.17.164'),
|
||||
seacher2.search('170.148.132.136'),
|
||||
seacher2.search('194.138.202.210')
|
||||
])
|
||||
|
||||
console.log(data2)
|
||||
|
||||
const data3 = await Promise
|
||||
.all([
|
||||
seacher3.search('202.97.77.50'),
|
||||
seacher3.search('218.4.167.70'),
|
||||
seacher3.search('112.31.187.151'),
|
||||
seacher3.search('202.98.17.164'),
|
||||
seacher3.search('170.148.132.136'),
|
||||
seacher3.search('194.138.202.210')
|
||||
])
|
||||
|
||||
console.log(data3)
|
||||
})()
|
||||
Loading…
x
Reference in New Issue
Block a user