node/test/pummel/test-fs-watch-non-recursive.js
Myles Borins 60de9f8d7b test: wrap assert.fail when passed to callback
Currently there are many instances where assert.fail is directly passed
to a callback for error handling. Unfortunately this will swallow the
error as it is the third argument of assert.fail that sets the message
not the first.

This commit adds a new function to test/common.js that simply wraps
assert.fail and calls it with the provided message.

Tip of the hat to @trott for pointing me in the direction of this.

PR-URL: https://github.com/nodejs/node/pull/3453
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2015-10-25 21:25:51 -04:00

29 lines
792 B
JavaScript

'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var testDir = common.tmpDir;
var testsubdir = path.join(testDir, 'testsubdir');
var filepath = path.join(testsubdir, 'watch.txt');
function cleanup() {
try { fs.unlinkSync(filepath); } catch (e) { }
try { fs.rmdirSync(testsubdir); } catch (e) { }
}
process.on('exit', cleanup);
cleanup();
try { fs.mkdirSync(testsubdir, 0o700); } catch (e) {}
// Need a grace period, else the mkdirSync() above fires off an event.
setTimeout(function() {
var watcher = fs.watch(testDir, { persistent: true }, common.fail);
setTimeout(function() {
fs.writeFileSync(filepath, 'test');
}, 100);
setTimeout(function() {
watcher.close();
}, 500);
}, 50);