smartdata/test/test.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-09-11 14:22:53 +00:00
import 'typings-test'
import * as shelljs from 'shelljs'
import * as should from 'should'
import * as smartdata from '../dist/index'
let mongoChildProcess
let testDbConnection: smartdata.DbConnection
2016-09-11 16:01:46 +00:00
let testDbCollection: smartdata.DbCollection<any>
2016-09-11 14:22:53 +00:00
describe('mongodb',function(){
it('should start mongodb',function(done){
2016-09-11 15:04:56 +00:00
this.timeout(10000)
2016-09-11 14:22:53 +00:00
mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017',{async: true})
2016-09-11 15:04:56 +00:00
setTimeout(() => { done() }, 5000) // give mongodb it some time to complete startup
2016-09-11 14:22:53 +00:00
})
})
describe('smartdata',function(){
it('should establish a connection to mongodb',function(done){
testDbConnection = new smartdata.DbConnection('mongodb://localhost:27017/smartdata')
testDbConnection.connect().then(() => { done() })
})
it('should create a collection',function(){
2016-09-11 16:01:46 +00:00
testDbCollection = new smartdata.DbCollection('something',testDbConnection)
2016-09-11 14:22:53 +00:00
})
it('should close the db Connection',function(){
testDbConnection.close()
})
})
describe('mongodb',function(){
it('should kill mongodb',function(){
2016-09-11 16:01:46 +00:00
this.timeout(10000)
2016-09-11 14:48:08 +00:00
shelljs.exec('mongod --dbpath=./test/data --shutdown')
2016-09-11 14:44:36 +00:00
mongoChildProcess.kill('SIGTERM')
2016-09-11 14:22:53 +00:00
})
})