Skip to content

Commit bed4ff5

Browse files
committed
set up integration and unit tests and runners
1 parent 01e1526 commit bed4ff5

34 files changed

+1751
-311
lines changed

package-lock.json

Lines changed: 1488 additions & 180 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"debug": "npm run tsc && node --inspect build/server.js --DEBUG true",
2121
"tsc": "./node_modules/.bin/tsc",
2222
"tsc:test": "./node_modules/.bin/tsc -p ./tsconfig.test.json",
23-
"test": "npm run tsc:test && ./node_modules/.bin/mocha ./build-test/test"
23+
"test": "npm run tsc:test && node ./build-test/test/runners/unit.js && node ./build-test/test/runners/integration.js",
24+
"test:unit": "npm run tsc:test && node ./build-test/test/runners/unit.js",
25+
"test:integration": "npm run tsc:test && node ./build-test/test/runners/integration.js"
2426
},
2527
"keywords": [
2628
"bitcore-node",
@@ -44,6 +46,7 @@
4446
"chai": "^4.1.2",
4547
"eslint-config-airbnb-base": "^12.1.0",
4648
"eslint-plugin-import": "^2.8.0",
49+
"glob": "^7.1.2",
4750
"mocha": "^5.0.5",
4851
"sinon": "^4.4.8",
4952
"supertest": "^3.0.0",

test/integration/index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/integration/logger.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('logger', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/integration/models/block.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Block Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/integration/models/coin.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Coin Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Transaction Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Wallet Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('WalletAddress Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/integration/rpc.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('rpc', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/integration/server.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('server', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/integration/services/p2p.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('P2P Service', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Storage Service', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Worker Service', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/runners/integration.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import path from 'path';
2+
3+
import glob from 'glob';
4+
import Mocha from 'mocha';
5+
6+
import { StorageService } from '../../src/services/storage';
7+
8+
const TIMEOUT = 5000;
9+
const TEST_DIR = path.join(__dirname, '../integration')
10+
11+
const storageArgs = {
12+
dbHost: 'localhost:27017',
13+
dbName: 'bitcore-unit'
14+
};
15+
16+
function handleError(err){
17+
console.error(err);
18+
console.log(err.stack);
19+
process.exit(1);
20+
}
21+
22+
function startTestDatabase(){
23+
let storage = new StorageService();
24+
return storage.start(storageArgs);
25+
}
26+
27+
function runTests(){
28+
return new Promise(function(resolve, reject){
29+
const testRunner = new Mocha();
30+
testRunner.timeout(TIMEOUT);
31+
testRunner.reporter('spec');
32+
33+
const files = glob.sync(`${TEST_DIR}/**/**.js`);
34+
files.forEach(function(file){
35+
testRunner.addFile(file);
36+
});
37+
try{
38+
testRunner.run(function(failures){
39+
process.exit(failures);
40+
});
41+
} catch(err){
42+
return reject(err);
43+
}
44+
});
45+
}
46+
47+
startTestDatabase()
48+
.then(function(){
49+
return runTests();
50+
})
51+
.then(function(){
52+
process.exit(0);
53+
})
54+
.catch(function(err){
55+
handleError(err);
56+
});

test/runners/unit.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import path from 'path';
2+
3+
import glob from 'glob';
4+
import Mocha from 'mocha';
5+
6+
import { StorageService } from '../../src/services/storage';
7+
8+
const TIMEOUT = 5000;
9+
const TEST_DIR = path.join(__dirname, '../unit');
10+
11+
const storageArgs = {
12+
dbHost: 'localhost:27017',
13+
dbName: 'bitcore-unit'
14+
};
15+
16+
function handleError(err){
17+
console.error(err);
18+
console.log(err.stack);
19+
process.exit(1);
20+
}
21+
22+
function runTests(){
23+
return new Promise(function(resolve, reject){
24+
const testRunner = new Mocha();
25+
testRunner.timeout(TIMEOUT);
26+
testRunner.reporter('spec');
27+
28+
const files = glob.sync(`${TEST_DIR}/**/**.js`);
29+
files.forEach(function(file){
30+
testRunner.addFile(file);
31+
});
32+
try{
33+
testRunner.run(function(failures){
34+
process.exit(failures);
35+
});
36+
} catch(err){
37+
return reject(err);
38+
}
39+
});
40+
}
41+
42+
runTests()
43+
.then(function(failures){
44+
process.exit(0);
45+
})
46+
.catch(function(err){
47+
handleError(err);
48+
});

test/unit/address.unit.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/unit/block.unit.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/unit/index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/unit/logger.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('logger', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/unit/mock.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/unit/models/block.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Block Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/unit/models/coin.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Coin Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/unit/models/transaction.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Transaction Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/unit/models/wallet.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Wallet Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('WalletAddress Model', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/unit/rpc.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('rpc', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/unit/server.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('server', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/unit/services/p2p.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('P2P Service', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/unit/services/storage.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Storage Service', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

test/unit/services/worker.unit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expect} from 'chai';
2+
3+
describe('Worker Service', function(){
4+
it('should have a test which runs', function(){
5+
expect(true).to.equal(true);
6+
});
7+
});

0 commit comments

Comments
 (0)