read.js
2.65 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
92
93
94
95
96
97
98
99
100
101
102
'use strict'
const assert = require('chai').assert
const proxyquire = require('proxyquire')
const spooks = require('spooks')
const modulePath = '../../src/read'
suite('read:', () => {
test('require does not throw', () => {
assert.doesNotThrow(() => {
require(modulePath)
})
})
test('require returns function', () => {
assert.isFunction(require(modulePath))
})
suite('require:', () => {
let log, results, read
setup(() => {
log = {}
results = {
parse: [ {} ],
createReadStream: [ {} ]
}
read = proxyquire(modulePath, {
fs: {
createReadStream: spooks.fn({
name: 'createReadStream',
log: log,
results: results.createReadStream
})
},
'./parse': spooks.fn({
name: 'parse',
log: log,
results: results.parse
})
})
})
test('read expects two arguments', () => {
assert.lengthOf(read, 2)
})
test('read does not throw', () => {
assert.doesNotThrow(() => {
read()
})
})
test('parse was not called', () => {
assert.strictEqual(log.counts.parse, 0)
})
test('fs.createReadStream was not called', () => {
assert.strictEqual(log.counts.createReadStream, 0)
})
suite('read:', () => {
let path, options, result
setup(() => {
path = {}
options = { foo: 'bar', ndjson: true }
result = read(path, options)
})
test('fs.createReadStream was called once', () => {
assert.strictEqual(log.counts.createReadStream, 1)
})
test('fs.createReadStream was called correctly', () => {
assert.lengthOf(log.args.createReadStream[0], 2)
assert.strictEqual(log.args.createReadStream[0][0], path)
assert.lengthOf(Object.keys(log.args.createReadStream[0][0]), 0)
assert.strictEqual(log.args.createReadStream[0][1], options)
assert.lengthOf(Object.keys(log.args.createReadStream[0][1]), 2)
})
test('parse was called once', () => {
assert.strictEqual(log.counts.parse, 1)
})
test('parse was called correctly', () => {
assert.isUndefined(log.these.parse[0])
assert.lengthOf(log.args.parse[0], 2)
assert.strictEqual(log.args.parse[0][0], results.createReadStream[0])
assert.lengthOf(Object.keys(log.args.parse[0][0]), 0)
assert.notStrictEqual(log.args.parse[0][1], options)
assert.deepEqual(log.args.parse[0][1], { foo: 'bar', ndjson: false })
})
test('parse result was returned', () => {
assert.strictEqual(result, results.parse[0])
})
})
})
})