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
|
|
|
|
2021-12-01 01:04:21 +00:00
|
|
|
import * as fs from 'fs';
|
|
|
|
|
2017-04-09 14:51:33 +00:00
|
|
|
// the module to test
|
2019-06-04 11:59:54 +00:00
|
|
|
if (process.env.CI) {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
2017-06-30 16:12:00 +00:00
|
|
|
|
2018-10-10 15:06:40 +00:00
|
|
|
let testSmartchok: smartchok.Smartchok;
|
2021-12-01 01:04:21 +00:00
|
|
|
let testAddObservable: smartrx.rxjs.Observable<[string, fs.Stats]>;
|
2019-05-05 18:41:29 +00:00
|
|
|
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']);
|
2021-11-29 19:26:59 +00:00
|
|
|
await testSmartchok.start()
|
|
|
|
testSmartchok.add(['./test/assets/**/*.md']);
|
2018-10-10 15:06:40 +00:00
|
|
|
});
|
2017-04-09 14:51:33 +00:00
|
|
|
|
|
|
|
tap.test('should get an observable for a certain event', async () => {
|
2021-11-29 19:26:59 +00:00
|
|
|
await testSmartchok.getObservableFor('add').then(async (observableArg) => {
|
2018-10-10 15:06:40 +00:00
|
|
|
testAddObservable = observableArg;
|
|
|
|
});
|
|
|
|
});
|
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();
|
2021-12-01 01:04:21 +00:00
|
|
|
testSubscription = testAddObservable.subscribe(pathArg => {
|
|
|
|
const pathResult = pathArg[0];
|
|
|
|
console.log(pathResult);
|
2018-10-10 15:06:40 +00:00
|
|
|
testDeferred.resolve();
|
|
|
|
});
|
|
|
|
smartfile.memory.toFs('HI', './test/assets/hi.txt');
|
2021-11-29 19:26:59 +00:00
|
|
|
await testDeferred.promise;
|
2018-10-10 15:06:40 +00:00
|
|
|
});
|
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();
|