|
@ -40,10 +40,13 @@ fs.watchFile(FILENAME, {interval:TIMEOUT - 250}, function(curr, prev) { |
|
|
console.log([curr, prev]); |
|
|
console.log([curr, prev]); |
|
|
switch (++nevents) { |
|
|
switch (++nevents) { |
|
|
case 1: |
|
|
case 1: |
|
|
|
|
|
assert.equal(fs.existsSync(FILENAME), false); |
|
|
|
|
|
break; |
|
|
case 2: |
|
|
case 2: |
|
|
|
|
|
case 3: |
|
|
assert.equal(fs.existsSync(FILENAME), true); |
|
|
assert.equal(fs.existsSync(FILENAME), true); |
|
|
break; |
|
|
break; |
|
|
case 3: |
|
|
case 4: |
|
|
assert.equal(fs.existsSync(FILENAME), false); |
|
|
assert.equal(fs.existsSync(FILENAME), false); |
|
|
fs.unwatchFile(FILENAME); |
|
|
fs.unwatchFile(FILENAME); |
|
|
break; |
|
|
break; |
|
@ -53,21 +56,24 @@ fs.watchFile(FILENAME, {interval:TIMEOUT - 250}, function(curr, prev) { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
process.on('exit', function() { |
|
|
process.on('exit', function() { |
|
|
assert.equal(nevents, 3); |
|
|
assert.equal(nevents, 4); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
setTimeout(createFile, TIMEOUT); |
|
|
setTimeout(createFile, TIMEOUT); |
|
|
|
|
|
|
|
|
function createFile() { |
|
|
function createFile() { |
|
|
|
|
|
console.log('creating file'); |
|
|
fs.writeFileSync(FILENAME, "test"); |
|
|
fs.writeFileSync(FILENAME, "test"); |
|
|
setTimeout(touchFile, TIMEOUT); |
|
|
setTimeout(touchFile, TIMEOUT); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function touchFile() { |
|
|
function touchFile() { |
|
|
|
|
|
console.log('touch file'); |
|
|
fs.writeFileSync(FILENAME, "test"); |
|
|
fs.writeFileSync(FILENAME, "test"); |
|
|
setTimeout(removeFile, TIMEOUT); |
|
|
setTimeout(removeFile, TIMEOUT); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function removeFile() { |
|
|
function removeFile() { |
|
|
|
|
|
console.log('remove file'); |
|
|
fs.unlinkSync(FILENAME); |
|
|
fs.unlinkSync(FILENAME); |
|
|
} |
|
|
} |
|
|