files.spec.js
1.54 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
/* eslint no-unused-vars:off */
var fs = require('fs')
var path = require('path')
var stream = require('readable-stream')
var expect = require('chai').expect
var parse = require('../index')
describe('File parsing', function () {
it('should parse the file by path', function (done) {
parse.file(path.resolve(__dirname, 'fixtures/sample.js'), function (err, parsed) {
if (err) { done(err) }
expect(parsed)
.to.be.an('array')
expect(parsed.length)
.to.eq(4)
expect(parsed[0].description)
.to.eq('File description')
expect(parsed[1].tags[0].tag)
.to.eq('class')
expect(parsed[2].tags[0].tag)
.to.eq('property')
expect(parsed[3].tags[0].tag)
.to.eq('method')
done()
})
})
it('should path the error if file dows not exist', function (done) {
parse.file('does/not/exists', function (err, parsed) {
expect(err)
.to.be.instanceof(Error)
done()
})
})
it('should return `Transform` stream', function (done) {
var count = 0
var readable = fs.createReadStream(path.resolve(__dirname, 'fixtures/sample.js'), {encoding: 'utf8'})
var writable = new stream.Writable({objectMode: true})
writable._write = function (data, encoding, done) {
count++
done()
}
readable
.on('error', done)
.pipe(parse.stream())
.on('error', done)
.pipe(writable)
.on('error', done)
.on('finish', function () {
expect(count)
.to.eq(4)
done()
})
})
})