Files
smartwatch/test/test.ts

51 lines
1.5 KiB
TypeScript
Raw Normal View History

import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as smartwatch from '../ts/index.js';
2024-01-28 01:18:39 +01:00
import * as smartfile from '@push.rocks/smartfile';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@push.rocks/smartrx';
2017-04-09 16:51:33 +02:00
2021-12-01 02:04:21 +01:00
import * as fs from 'fs';
2017-04-09 16:51:33 +02:00
// the module to test
2019-06-04 13:59:54 +02:00
if (process.env.CI) {
process.exit(0);
}
2017-06-30 18:12:00 +02:00
let testSmartwatch: smartwatch.Smartwatch;
2021-12-01 02:04:21 +01:00
let testAddObservable: smartrx.rxjs.Observable<[string, fs.Stats]>;
2019-05-05 20:41:29 +02:00
let testSubscription: smartrx.rxjs.Subscription;
2017-04-09 16:51:33 +02:00
tap.test('should create a new instance', async () => {
testSmartwatch = new smartwatch.Smartwatch([]);
expect(testSmartwatch).toBeInstanceOf(smartwatch.Smartwatch);
2018-10-10 17:06:40 +02:00
});
2017-04-09 16:51:33 +02:00
tap.test('should add some files to watch and start', async () => {
testSmartwatch.add(['./test/**/*.txt']);
await testSmartwatch.start()
testSmartwatch.add(['./test/**/*.md']);
2018-10-10 17:06:40 +02:00
});
2017-04-09 16:51:33 +02:00
tap.test('should get an observable for a certain event', async () => {
await testSmartwatch.getObservableFor('add').then(async (observableArg) => {
2018-10-10 17:06:40 +02:00
testAddObservable = observableArg;
});
});
2017-04-09 16:51:33 +02:00
tap.test('should register an add operation', async () => {
2018-10-10 17:06:40 +02:00
let testDeferred = smartpromise.defer();
2021-12-01 02:04:21 +01:00
testSubscription = testAddObservable.subscribe(pathArg => {
const pathResult = pathArg[0];
console.log(pathResult);
2018-10-10 17:06:40 +02:00
testDeferred.resolve();
});
smartfile.memory.toFs('HI', './test/assets/hi.txt');
2021-11-29 20:26:59 +01:00
await testDeferred.promise;
2018-10-10 17:06:40 +02:00
});
2017-04-09 16:51:33 +02:00
2024-02-29 14:42:33 +01:00
tap.test('should stop the watch process', async (tools) => {
await tools.delayFor(10000);
testSmartwatch.stop();
2018-10-10 17:06:40 +02:00
});
2017-06-30 18:05:55 +02:00
export default tap.start();