/
api.types.ts
128 lines (102 loc) · 2.82 KB
/
api.types.ts
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import 'should'
import { generate, Options, Generator } from '../lib/index.js'
describe('API Types', () => {
describe('Initialisation', () => {
it('stream', () => {
// With callback
const generator: Generator = generate()
generator.destroy()
generator.should.be.an.Object()
// With callback
generate( (err, records) => err || records ).destroy()
// With options + callback
generate( {length: 1}, (err, records) => err || records )
})
})
describe('Generator', () => {
it('Expose options', () => {
const generator: Generator = generate()
const options: Options = generator.options
const keys: any = Object.keys(options)
keys.sort().should.eql([
'columns', 'delimiter', 'duration', 'encoding', 'end', 'eof',
'fixedSize', 'length', 'maxWordLength',
'rowDelimiter', 'seed', 'sleep'
])
})
it('Receive Callback', (next) => {
generate({length: 3}, function(err: Error | undefined, data: object){
if(err !== undefined){
data.should.be.an.Object()
}
next(err)
})
})
})
describe('Options', () => {
it('columns', () => {
const options: Options = {}
options.columns = 8
options.columns = [
"ascii",
"bool",
"int",
({ options, state }) => options.delimiter + "ok" + state.start_time,
];
})
it('delimiter', () => {
const options: Options = {}
options.delimiter = '|'
})
it('duration', () => {
const options: Options = {}
options.duration = 1000
})
it('encoding', () => {
const options: Options = {}
options.encoding = 'utf8'
})
it('end', () => {
const options: Options = {}
options.end = 1000
options.end = new Date()
})
it('eof', () => {
const options: Options = {}
options.eof = true
options.eof = '\n'
})
it('fixed_size', () => {
const options: Options = {}
options.fixed_size = true
})
it('high_water_mark', () => {
const options: Options = {}
options.high_water_mark = 1024
})
it('length', () => {
const options: Options = {}
options.length = 100
})
it('max_word_length', () => {
const options: Options = {}
options.length = 10
})
it('object_mode', () => {
const options: Options = {}
options.object_mode = true
})
it('row_delimiter', () => {
const options: Options = {}
options.row_delimiter = ';'
})
it('seed', () => {
const options: Options = {}
options.seed = 10
})
it('sleep', () => {
const options: Options = {}
options.sleep = 1000
})
})
})