Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80668 views
1
var test = require('tap').test
2
var fs = require('../graceful-fs.js')
3
4
test('graceful fs is monkeypatched fs', function (t) {
5
t.equal(fs, require('fs'))
6
t.end()
7
})
8
9
test('open an existing file works', function (t) {
10
var fd = fs.openSync(__filename, 'r')
11
fs.closeSync(fd)
12
fs.open(__filename, 'r', function (er, fd) {
13
if (er) throw er
14
fs.close(fd, function (er) {
15
if (er) throw er
16
t.pass('works')
17
t.end()
18
})
19
})
20
})
21
22
test('open a non-existing file throws', function (t) {
23
var er
24
try {
25
var fd = fs.openSync('this file does not exist', 'r')
26
} catch (x) {
27
er = x
28
}
29
t.ok(er, 'should throw')
30
t.notOk(fd, 'should not get an fd')
31
t.equal(er.code, 'ENOENT')
32
33
fs.open('neither does this file', 'r', function (er, fd) {
34
t.ok(er, 'should throw')
35
t.notOk(fd, 'should not get an fd')
36
t.equal(er.code, 'ENOENT')
37
t.end()
38
})
39
})
40
41