1 var fstream = require('../fstream.js')
2 var tap = require('tap')
4 var path = require('path')
5 var dir = path.dirname(__dirname)
7 tap.test('reader test', function (t) {
12 var r = fstream.Reader({
15 // return this.parent === r
16 return this.parent === r || this === r
20 r.on('ready', function () {
22 children = fs.readdirSync(dir).length
23 console.error('Setting expected children to ' + children)
24 t.equal(r.type, 'Directory', 'should be a directory')
27 r.on('entry', function (entry) {
30 t.fail('children before ready!')
32 t.equal(entry.dirname, r.path, 'basename is parent dir')
35 r.on('error', function (er) {
41 r.on('end', function () {
42 t.equal(children, 0, 'should have seen all children')
47 r.on('close', function () {
48 t.ok(ended, 'saw end before close')
49 t.notOk(closed, 'close should only happen once')
55 tap.test('reader error test', function (t) {
56 // assumes non-root on a *nix system
57 var r = fstream.Reader({ path: '/etc/shadow' })
59 r.once('error', function (er) {
64 r.on('end', function () {
65 t.fail('reader ended without error')