-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
114 lines (106 loc) · 2.56 KB
/
test.js
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
/* global describe,it */
'use strict';
const {strictEqual} = require('assert');
const fs = require('fs');
const concatStream = require('concat-stream');
const Vinyl = require('vinyl');
const gulpRmlines = require('.');
describe('gulpRmlines', () => {
it('pipes correctly when file.contents is a buffer', done => {
const expected = 'abc\njkl\nmno\n';
const stream = gulpRmlines([2, 3]);
stream.on('data', file => {
strictEqual(file.contents.toString(), expected);
done();
});
stream.write(new Vinyl({
cwd: './',
base: '/',
path: '/fixture.txt',
contents: fs.readFileSync('fixture.txt')
}));
stream.end();
});
it('pipes correctly when file.contents is a stream', done => {
const expected = 'abc\njkl\nmno\n';
const stream = gulpRmlines([2, 3]);
stream.on('data', file => {
file.contents.pipe(concatStream(data => {
strictEqual(data.toString(), expected);
done();
}));
});
stream.write(new Vinyl({
cwd: './',
base: '/',
path: '/fixture.txt',
contents: fs.createReadStream('fixture.txt')
}));
stream.end();
});
it('pipes correctly when file.contents is null', done => {
const stream = gulpRmlines([2, 3]);
stream.on('data', file => {
strictEqual(file.contents, null);
done();
});
stream.write(new Vinyl({}));
stream.end();
});
it('pipes correctly when file.contents is something else', done => {
const expected = 'abc';
const stream = gulpRmlines([2, 3]);
stream.on('data', file => {
strictEqual(file.contents.toString(), expected);
done();
});
const v = {
contents: 'abc',
isNull: () => {
return false;
},
isBuffer: () => {
return false;
},
isStream: () => {
return false;
}
};
stream.write(v);
stream.end();
});
it('handles options', done => {
const expected = 'abc\ndef\njkl\nmno\n';
const stream = gulpRmlines(3, {maxLength: 30});
stream.on('data', file => {
file.contents.pipe(concatStream(data => {
strictEqual(data.toString(), expected);
done();
}));
});
stream.write(new Vinyl({
cwd: './',
base: '/',
path: '/fixture.txt',
contents: fs.createReadStream('fixture.txt')
}));
stream.end();
});
it('handles no line numbers', done => {
const expected = 'abc\ndef\nghi\njkl\nmno\n';
const stream = gulpRmlines();
stream.on('data', file => {
file.contents.pipe(concatStream(data => {
strictEqual(data.toString(), expected);
done();
}));
});
stream.write(new Vinyl({
cwd: './',
base: '/',
path: '/fixture.txt',
contents: fs.createReadStream('fixture.txt')
}));
stream.end();
});
});