smartchok/test/test.ts

51 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-01-28 00:18:39 +00:00
import { tap, expect } from '@push.rocks/tapbundle';
import * as smartchok from '../ts/index.js';
import * as smartfile from '@push.rocks/smartfile';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@push.rocks/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([]);
2024-01-28 00:18:39 +00:00
expect(testSmartchok).toBeInstanceOf(smartchok.Smartchok);
2018-10-10 15:06:40 +00:00
});
2017-04-09 14:51:33 +00:00
tap.test('should add some files to watch and start', async () => {
2024-02-29 13:42:33 +00:00
testSmartchok.add(['./test/**/*.txt']);
2021-11-29 19:26:59 +00:00
await testSmartchok.start()
2024-02-29 13:42:33 +00:00
testSmartchok.add(['./test/**/*.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
2024-02-29 13:42:33 +00:00
tap.test('should stop the watch process', async (tools) => {
await tools.delayFor(10000);
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();