UNPKG

@remote.it/core

Version:

Core remote.it JavasScript/TypeScript library

64 lines (52 loc) 1.4 kB
import { File } from './File' import { FileWatcher } from './FileWatcher' import { TempFilePath } from './TempFilePath' describe('FileWatcher', () => { let file: File let watcher: FileWatcher beforeEach(() => { const tmpPath = new TempFilePath().toString() console.log('TMPPATH:', tmpPath) file = new File(tmpPath) watcher = new FileWatcher(file.location) }) afterEach(() => { file.remove() watcher.stop() }) test('should emit "ready" event when watcher is ready', async done => { watcher.on('created', () => { expect(file.exists).toBe(true) done() }) file.write('foo') }) test('should emit "created" event when file is created', async done => { watcher.on('created', () => { expect(file.exists).toBe(true) done() }) file.write('foo') }) test('should emit "updated" event when file is changed', async done => { file.write('foo') setTimeout(() => { watcher.on('updated', () => { expect(file.exists).toBe(true) expect(file.read()).toBe('bar') done() }) file.write('bar') }, 200) }) test('should emit "removed" event when file is deleted', async done => { file.write('foo') setTimeout(() => { watcher.on('removed', () => { expect(file.exists).toBe(false) done() }) file.remove() }, 200) }) })