node/test/parallel/test-fs-watch-encoding.js
Rich Trott cdcfeb7628 test: refresh the tmpdir before using
Test fails if tmp dir does not exist when the test is run. Add
common.refreshTmpDir() so that doesn't happen.

PR-URL: https://github.com/nodejs/node/pull/7327
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-06-21 21:11:53 -07:00

55 lines
1.0 KiB
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;
}
common.refreshTmpDir();
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);
});