Merge pull request #11 from zhuangya/jest

chore: test in jest
This commit is contained in:
lionsoul 2017-04-14 13:11:52 +08:00 committed by GitHub
commit 546be60b0a
7 changed files with 2030 additions and 18 deletions

1
binding/nodejs/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

View File

@ -1,3 +1,3 @@
# nodejs 客户端 # nodejs 客户端
现已实现同步查询,异步查询未实现,用法参考 test.js 现已实现同步查询,异步查询未实现,用法参考 ip2region.spec.js

View File

@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`binarySearch 1`] = `
Object {
"city": 2163,
"region": "中国|华南|广东省|深圳市|阿里云",
}
`;
exports[`binarySearch 2`] = `
Object {
"city": 0,
"region": "未分配或者内网IP|0|0|0|0",
}
`;
exports[`should query 1`] = `
Object {
"city": 2163,
"region": "中国|华南|广东省|深圳市|阿里云",
}
`;
exports[`should query 2`] = `
Object {
"city": 0,
"region": "未分配或者内网IP|0|0|0|0",
}
`;

View File

@ -0,0 +1,15 @@
'use strict';
const ip = require('./ip2region');
const query = ip.create('../../data/ip2region.db');
it('should query', () => {
expect(query.btreeSearchSync('120.24.78.68')).toMatchSnapshot();
expect(query.btreeSearchSync('10.10.10.10')).toMatchSnapshot();
});
it('binarySearch', () => {
expect(query.binarySearchSync('120.24.78.68')).toMatchSnapshot();
expect(query.binarySearchSync('10.10.10.10')).toMatchSnapshot();
});

View File

@ -4,7 +4,7 @@
"description": "ip database ", "description": "ip database ",
"main": "ip2region.js", "main": "ip2region.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "jest"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -20,5 +20,8 @@
"bugs": { "bugs": {
"url": "https://github.com/lionsoul2016/ip2region/issues" "url": "https://github.com/lionsoul2016/ip2region/issues"
}, },
"homepage": "https://github.com/lionsoul2016/ip2region" "homepage": "https://github.com/lionsoul2016/ip2region",
"devDependencies": {
"jest": "^19.0.2"
}
} }

View File

@ -1,15 +0,0 @@
/**
* test program
* */
var Ip2region = require('./ip2region');
// 1. create a ip2region object
var ipObj = Ip2region.create('../../data/ip2region.db');
// 2. use
//console.log(ipObj.binarySearchSync("120.24.78.68"));
console.log(ipObj.btreeSearchSync("120.24.78.68"));
// 3. destroy
Ip2region.destroy(ipObj);

1979
binding/nodejs/yarn.lock Normal file

File diff suppressed because it is too large Load Diff