1 |
|
2 |
|
3 |
|
4 |
|
5 | 'use strict'
|
6 |
|
7 | const watchFiles = require('../lib/watch_files.js')
|
8 | const fs = require('fs')
|
9 | const assert = require('assert')
|
10 | const path = require('path')
|
11 | const mkdirp = require('mkdirp')
|
12 |
|
13 | const tmpDir = __dirname + '/../tmp'
|
14 |
|
15 | describe('watch files', () => {
|
16 | before((done) => {
|
17 | mkdirp.sync(tmpDir)
|
18 | done()
|
19 | })
|
20 |
|
21 | after((done) => {
|
22 | done()
|
23 | })
|
24 |
|
25 | it('Watch all.', (done) => {
|
26 | let watching = path.resolve(tmpDir, 'testing-watched-file.txt')
|
27 | fs.writeFileSync(watching, 'foo')
|
28 | let watchers = watchFiles(tmpDir + '/*.*', {}, (event, changed) => {
|
29 | assert.equal(event, 'change')
|
30 | assert.equal(watching, changed)
|
31 | watchers.forEach((watcher) => {
|
32 | assert.ok(watcher)
|
33 | watcher.close()
|
34 | })
|
35 | done()
|
36 | })
|
37 | setTimeout(() => {
|
38 | fs.writeFileSync(watching, 'foo2')
|
39 | }, 100)
|
40 | })
|
41 | })
|
42 |
|
43 |
|