smartchok/test/test.ts

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-04-09 14:51:33 +00:00
import { tap, expect } from 'tapbundle'
2018-02-28 23:08:08 +00:00
import * as smartchok from '../ts/index'
2016-09-22 14:33:44 +00:00
import * as smartfile from 'smartfile'
2017-04-09 14:51:33 +00:00
import * as smartq from 'smartq'
2017-06-30 16:20:48 +00:00
import * as rx from 'rxjs/Rx'
2017-04-09 14:51:33 +00:00
// the module to test
2017-06-30 16:12:00 +00:00
2017-04-09 14:51:33 +00:00
let testSmartchok: smartchok.Smartchok
let testAddObservable: rx.Observable<any>
let testSubscription: rx.Subscription
tap.test('should create a new instance', async () => {
testSmartchok = new smartchok.Smartchok([])
2018-02-28 23:08:08 +00:00
expect(testSmartchok).to.be.instanceof(smartchok.Smartchok)
})
2017-04-09 14:51:33 +00:00
tap.test('should add some files to watch and start', async () => {
testSmartchok.add([ './test/assets/**/*.txt' ])
let localPromise = testSmartchok.start().then(async () => {
testSmartchok.add([ './test/assets/**/*.md' ])
})
2018-02-28 23:08:08 +00:00
await expect(localPromise).to.eventually.be.fulfilled
})
2017-04-09 14:51:33 +00:00
tap.test('should get an observable for a certain event', async () => {
let localPromise = testSmartchok.getObservableFor('add').then(async (observableArg) => {
testAddObservable = observableArg
})
2018-02-28 23:08:08 +00:00
await expect(localPromise).to.eventually.be.fulfilled
})
2017-04-09 14:51:33 +00:00
tap.test('should register an add operation', async () => {
let testDeferred = smartq.defer()
testSubscription = testAddObservable.subscribe(x => {
testDeferred.resolve()
})
smartfile.memory.toFs('HI', './test/assets/hi.txt')
2018-02-28 23:08:08 +00:00
await expect(testDeferred.promise).to.eventually.be.fulfilled
})
2017-04-09 14:51:33 +00:00
tap.test('should stop the watch process', async () => {
testSmartchok.stop()
2018-02-28 23:08:08 +00:00
})
2017-06-30 16:05:55 +00:00
tap.start()