Initial commit
[yaffs-website] / node_modules / globule / node_modules / graceful-fs / test / open.js
1 var test = require('tap').test
2 var fs = require('../graceful-fs.js')
3
4 test('graceful fs is not fs', function (t) {
5   t.notEqual(fs, require('fs'))
6   t.end()
7 })
8
9 test('open an existing file works', function (t) {
10   var start = fs._curOpen
11   var fd = fs.openSync(__filename, 'r')
12   t.equal(fs._curOpen, start + 1)
13   fs.closeSync(fd)
14   t.equal(fs._curOpen, start)
15   fs.open(__filename, 'r', function (er, fd) {
16     if (er) throw er
17     t.equal(fs._curOpen, start + 1)
18     fs.close(fd, function (er) {
19       if (er) throw er
20       t.equal(fs._curOpen, start)
21       t.end()
22     })
23   })
24 })
25
26 test('open a non-existing file throws', function (t) {
27   var start = fs._curOpen
28   var er
29   try {
30     var fd = fs.openSync('this file does not exist', 'r')
31   } catch (x) {
32     er = x
33   }
34   t.ok(er, 'should throw')
35   t.notOk(fd, 'should not get an fd')
36   t.equal(er.code, 'ENOENT')
37   t.equal(fs._curOpen, start)
38
39   fs.open('neither does this file', 'r', function (er, fd) {
40     t.ok(er, 'should throw')
41     t.notOk(fd, 'should not get an fd')
42     t.equal(er.code, 'ENOENT')
43     t.equal(fs._curOpen, start)
44     t.end()
45   })
46 })