uci-utils-sync/test/watcher.test.js

72 lines
1.9 KiB
JavaScript

import Sync from '../src/sync'
import Watcher from '../src/watcher'
import to from 'await-to-js'
import { expect } from 'chai'
import { it } from 'mocha'
import debounce from 'debounce-fn'
import logger from '@uci/logger'
// pause = require('@uci/utils').pPause
describe('Watcher Class Testing ',async ()=> {
// let log = logger({})
before(async () => {
// log = logger({ package:'@uci/sync', id: 'sync-test' })
let sync = new Sync()
// await sync.loadJob('local')
// console.log('command to be run',sync.command())
// console.log('===',sync.cwd())
// // sync.execute({cli:true})
await sync.loadJob('local')
sync.live()
let options = await sync.readOptionsFile('local')
let watcher = new Watcher(options)
await watcher.start()
watcher.on('changed',
// debounce(
(change) => {
console.log(`======= file ${change.file} was ${change.type} ==========`)
sync.execute({cli:true})
}
// ,{wait:100, immediate:true})
)
// console.log('command to be run',sync.command())
// sync.live()
// sync.execute({cli:true})
// await sync.configure('./test/config/sync')
// log.info({cmd:sync.command(), msg:'Rsync Command that will Run'})
// log.info(`making connection to ${remote.opts.host}`)
// log.info('ready for testing')
})
// after(async () => {
// remote.close()
// })
it('can sync a directory' , async function () {
// let [err,res] = await to(remote.exec('cd /opt && pwd'))
// if (err) {
// log.info('error running command aborting test', err)
// return
// }
// log.info(`result of remote command ${res.command} => ${res.reply.toString().trim()}`)
expect('test', 'test failed').to.equal('/opt')
})
})
// function hooks(remote) {
//
// // beforeEach(async() => {
// // await someasyncfunctiontodobeforeeachtest()
// // })
//
// // after(async() => {
// // await someasyncfunctiontodoaftereeachtest()
// // })
//
// }