import { tap, expect } from '@git.zone/tstest/tapbundle'; import * as smartwatch 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'; import * as fs from 'fs'; // the module to test if (process.env.CI) { process.exit(0); } let testSmartwatch: smartwatch.Smartwatch; let testAddObservable: smartrx.rxjs.Observable<[string, fs.Stats]>; let testSubscription: smartrx.rxjs.Subscription; tap.test('should create a new instance', async () => { testSmartwatch = new smartwatch.Smartwatch([]); expect(testSmartwatch).toBeInstanceOf(smartwatch.Smartwatch); }); tap.test('should add some files to watch and start', async () => { testSmartwatch.add(['./test/**/*.txt']); await testSmartwatch.start() testSmartwatch.add(['./test/**/*.md']); }); tap.test('should get an observable for a certain event', async () => { await testSmartwatch.getObservableFor('add').then(async (observableArg) => { testAddObservable = observableArg; }); }); tap.test('should register an add operation', async () => { let testDeferred = smartpromise.defer(); testSubscription = testAddObservable.subscribe(pathArg => { const pathResult = pathArg[0]; console.log(pathResult); testDeferred.resolve(); }); smartfile.memory.toFs('HI', './test/assets/hi.txt'); await testDeferred.promise; }); tap.test('should stop the watch process', async (tools) => { await tools.delayFor(10000); testSmartwatch.stop(); }); export default tap.start();