Last active
January 17, 2020 16:06
-
-
Save lukastaegert/c09c8e39cb5e724c8bde52350629c843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "chokidar-issue", | |
"scripts": { | |
"test": "node test.js", | |
"test-docker": "docker run -v `pwd`:/test -w /test rollupcabal/circleci-node-v10:latest node test.js" | |
}, | |
"dependencies": { | |
"chokidar": "^3.3.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const assert = require('assert'); | |
const chokidar = require('chokidar'); | |
const wait = () => new Promise(resolve => setTimeout(resolve, 500)); | |
const file = path.resolve('test.txt'); | |
fs.writeFileSync(file, 'Initial'); | |
const events = []; | |
const watcher = chokidar | |
.watch([], {ignoreInitial: true, disableGlobbing: true}) | |
.on('all', event => events.push(event)) | |
.add(file); | |
return wait() | |
.then(() => { | |
fs.unlinkSync(file); | |
fs.writeFileSync(file, 'First'); | |
}) | |
.then(wait) | |
.then(() => { | |
console.log('Events after first update (should not be empty):', events); | |
assert.strictEqual(events[0], 'change'); | |
events.length = 0; | |
// Unwatching and adding the file again on any change is a workaround | |
// watcher.unwatch(file); | |
// watcher.add(file); | |
}) | |
.then(wait) | |
.then(() => { | |
fs.unlinkSync(file); | |
fs.writeFileSync(file, 'Second'); | |
}) | |
.then(wait) | |
.then(() => { | |
console.log('Events after second update (should not be empty):', events); | |
watcher.close(); | |
if (events[0] !== 'change') { | |
console.error('Did not receive expected "change" event'); | |
process.exit(1); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment