When fs.watchFile encounters an ENOENT error, it invokes the given callback with some error data. This caused an issue as it was different behaviour than Node v0.10. Instead of changing this behaviour, document it and add a test. Ref: https://github.com/nodejs/io.js/issues/1745 Ref: https://github.com/nodejs/io.js/pull/2028 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> PR-URL: https://github.com/nodejs/io.js/pull/2093
26 lines
760 B
JavaScript
26 lines
760 B
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const assert = require('assert');
|
|
const common = require('../common');
|
|
const fixtures = path.join(__dirname, '..', 'fixtures');
|
|
|
|
// Basic usage tests.
|
|
assert.throws(function() {
|
|
fs.watchFile('./some-file');
|
|
}, /watchFile requires a listener function/);
|
|
|
|
assert.throws(function() {
|
|
fs.watchFile('./another-file', {}, 'bad listener');
|
|
}, /watchFile requires a listener function/);
|
|
|
|
assert.throws(function() {
|
|
fs.watchFile(new Object(), function() {});
|
|
}, /Path must be a string/);
|
|
|
|
// Test ENOENT. Should fire once.
|
|
const enoentFile = path.join(fixtures, 'empty', 'non-existent-file');
|
|
fs.watchFile(enoentFile, common.mustCall(function(curr, prev) {
|
|
fs.unwatchFile(enoentFile);
|
|
}));
|