-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
Expand file tree
/
Copy pathtest-fs-watch-enoent.js
More file actions
91 lines (80 loc) Β· 2.52 KB
/
test-fs-watch-enoent.js
File metadata and controls
91 lines (80 loc) Β· 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Flags: --expose-internals
'use strict';
// This verifies the error thrown by fs.watch.
const common = require('../common');
if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');
const assert = require('assert');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
const nonexistentFile = tmpdir.resolve('non-existent');
const { internalBinding } = require('internal/test/binding');
const {
UV_ENODEV,
UV_ENOENT
} = internalBinding('uv');
tmpdir.refresh();
{
assert.throws(
() => fs.watch(nonexistentFile, common.mustNotCall()),
(err) => {
assert.strictEqual(err.path, nonexistentFile);
assert.strictEqual(err.filename, nonexistentFile);
assert.ok(err.syscall === 'watch' || err.syscall === 'stat');
if (err.code === 'ENOENT') {
assert.ok(err.message.startsWith('ENOENT: no such file or directory'));
assert.strictEqual(err.errno, UV_ENOENT);
assert.strictEqual(err.code, 'ENOENT');
} else { // AIX
assert.strictEqual(
err.message,
`ENODEV: no such device, watch '${nonexistentFile}'`);
assert.strictEqual(err.errno, UV_ENODEV);
assert.strictEqual(err.code, 'ENODEV');
}
return true;
},
);
}
{
assert.throws(
() => fs.watch(nonexistentFile, { throwIfNoEntry: true }, common.mustNotCall()),
{
path: nonexistentFile,
filename: nonexistentFile,
code: /^(ENOENT|ENODEV)$/,
},
);
}
{
if (common.isAIX) {
assert.throws(
() => fs.watch(nonexistentFile, { throwIfNoEntry: false }, common.mustNotCall()),
{ code: 'ENODEV' },
);
} else {
const watcher = fs.watch(nonexistentFile, { throwIfNoEntry: false }, common.mustNotCall());
watcher.close();
}
}
{
if (common.isMacOS || common.isWindows) {
const file = tmpdir.resolve('file-to-watch');
fs.writeFileSync(file, 'test');
const watcher = fs.watch(file, common.mustNotCall());
watcher.on('error', common.mustCall((err) => {
assert.strictEqual(err.path, nonexistentFile);
assert.strictEqual(err.filename, nonexistentFile);
assert.strictEqual(
err.message,
`ENOENT: no such file or directory, watch '${nonexistentFile}'`);
assert.strictEqual(err.errno, UV_ENOENT);
assert.strictEqual(err.code, 'ENOENT');
assert.strictEqual(err.syscall, 'watch');
fs.unlinkSync(file);
return true;
}));
// Simulate the invocation from the binding
watcher._handle.onchange(UV_ENOENT, 'ENOENT', nonexistentFile);
}
}