node/test/parallel/test-fs-watch-encoding.js
Jeremiah Senkpiel 52bae222a3 test: abstract skip functionality to common
The tap skipping output is so prevalent yet obscure in nature that we
ought to move it into it's own function in test/common.js

PR-URL: https://github.com/nodejs/node/pull/6697
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2016-05-12 16:43:35 -04:00

53 lines
1013 B
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
const path = require('path');
const assert = require('assert');
if (common.isFreeBSD) {
common.skip('Test currently not working on FreeBSD');
return;
}
const fn = '新建文夹件.txt';
const a = path.join(common.tmpDir, fn);
const watcher1 = fs.watch(
common.tmpDir,
{encoding: 'hex'},
(event, filename) => {
if (filename)
assert.equal(filename, 'e696b0e5bbbae69687e5a4b9e4bbb62e747874');
watcher1.close();
}
);
const watcher2 = fs.watch(
common.tmpDir,
(event, filename) => {
if (filename)
assert.equal(filename, fn);
watcher2.close();
}
);
const watcher3 = fs.watch(
common.tmpDir,
{encoding: 'buffer'},
(event, filename) => {
if (filename) {
assert(filename instanceof Buffer);
assert.equal(filename.toString('utf8'), fn);
}
watcher3.close();
}
);
const fd = fs.openSync(a, 'w+');
fs.closeSync(fd);
process.on('exit', () => {
fs.unlink(a);
});