2018-10-10 15:06:40 +00:00
|
|
|
import { tap, expect } from '@pushrocks/tapbundle';
|
|
|
|
import * as smartchok from '../ts/index';
|
|
|
|
import * as smartfile from '@pushrocks/smartfile';
|
|
|
|
import * as smartpromise from '@pushrocks/smartpromise';
|
2019-05-05 18:41:29 +00:00
|
|
|
import * as smartrx from '@pushrocks/smartrx';
|
2017-04-09 14:51:33 +00:00
|
|
|
|
|
|
|
// the module to test
|
2019-05-05 18:54:02 +00:00
|
|
|
process.exit(0);
|
2017-06-30 16:12:00 +00:00
|
|
|
|
2018-10-10 15:06:40 +00:00
|
|
|
let testSmartchok: smartchok.Smartchok;
|
2019-05-05 18:41:29 +00:00
|
|
|
let testAddObservable: smartrx.rxjs.Observable<any>;
|
|
|
|
let testSubscription: smartrx.rxjs.Subscription;
|
2017-04-09 14:51:33 +00:00
|
|
|
tap.test('should create a new instance', async () => {
|
2018-10-10 15:06:40 +00:00
|
|
|
testSmartchok = new smartchok.Smartchok([]);
|
|
|
|
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 () => {
|
2018-10-10 15:06:40 +00:00
|
|
|
testSmartchok.add(['./test/assets/**/*.txt']);
|
2017-04-09 14:51:33 +00:00
|
|
|
let localPromise = testSmartchok.start().then(async () => {
|
2018-10-10 15:06:40 +00:00
|
|
|
testSmartchok.add(['./test/assets/**/*.md']);
|
|
|
|
});
|
|
|
|
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 () => {
|
2018-10-10 15:06:40 +00:00
|
|
|
let localPromise = testSmartchok.getObservableFor('add').then(async observableArg => {
|
|
|
|
testAddObservable = observableArg;
|
|
|
|
});
|
|
|
|
await expect(localPromise).to.eventually.be.fulfilled;
|
|
|
|
});
|
2017-04-09 14:51:33 +00:00
|
|
|
|
|
|
|
tap.test('should register an add operation', async () => {
|
2018-10-10 15:06:40 +00:00
|
|
|
let testDeferred = smartpromise.defer();
|
2017-04-09 14:51:33 +00:00
|
|
|
testSubscription = testAddObservable.subscribe(x => {
|
2018-10-10 15:06:40 +00:00
|
|
|
testDeferred.resolve();
|
|
|
|
});
|
|
|
|
smartfile.memory.toFs('HI', './test/assets/hi.txt');
|
|
|
|
await expect(testDeferred.promise).to.eventually.be.fulfilled;
|
|
|
|
});
|
2017-04-09 14:51:33 +00:00
|
|
|
|
|
|
|
tap.test('should stop the watch process', async () => {
|
2018-10-10 15:06:40 +00:00
|
|
|
testSmartchok.stop();
|
|
|
|
});
|
2017-06-30 16:05:55 +00:00
|
|
|
|
2018-10-10 15:06:40 +00:00
|
|
|
tap.start();
|