forked from gulpjs/gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
src.js
152 lines (143 loc) · 4.88 KB
/
src.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'use strict';
var gulp = require('../');
var should = require('should');
var join = require('path').join;
require('mocha');
describe('gulp input stream', function() {
describe('src()', function() {
it('should return a stream', function(done) {
var stream = gulp.src(join(__dirname, "./fixtures/*.coffee"));
should.exist(stream);
should.exist(stream.on);
done();
});
it('should return a input stream from a flat glob', function(done) {
var stream = gulp.src(join(__dirname, "./fixtures/*.coffee"));
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/test.coffee"));
String(file.contents).should.equal("this is a test");
});
stream.on('end', function() {
done();
});
});
it('should return a input stream for multiple globs', function(done) {
var globArray = [
join(__dirname, "./fixtures/stuff/run.dmc"),
join(__dirname, "./fixtures/stuff/test.dmc")
];
var stream = gulp.src(globArray);
var files = [];
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
files.push(file);
});
stream.on('end', function() {
files.length.should.equal(2);
files[0].path.should.equal(globArray[0]);
files[1].path.should.equal(globArray[1]);
done();
});
});
it('should return a input stream for multiple globs, with negation', function(done) {
var expectedPath = join(__dirname, "./fixtures/stuff/run.dmc");
var globArray = [
join(__dirname, "./fixtures/stuff/*.dmc"),
'!' + join(__dirname, "./fixtures/stuff/test.dmc"),
];
var stream = gulp.src(globArray);
var files = [];
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
files.push(file);
});
stream.on('end', function() {
files.length.should.equal(1);
files[0].path.should.equal(expectedPath);
done();
});
});
it('should return a input stream with no contents when read is false', function(done) {
var stream = gulp.src(join(__dirname, "./fixtures/*.coffee"), {read: false});
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
should.not.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/test.coffee"));
});
stream.on('end', function() {
done();
});
});
it('should return a input stream with contents as stream when buffer is false', function(done) {
var stream = gulp.src(join(__dirname, "./fixtures/*.coffee"), {buffer: false});
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
var buf = "";
file.contents.on('data', function(d) {
buf += d;
});
file.contents.on('end', function() {
buf.should.equal("this is a test");
done();
});
join(file.path,'').should.equal(join(__dirname, "./fixtures/test.coffee"));
});
});
it('should return a input stream from a deep glob', function(done) {
var stream = gulp.src(join(__dirname, "./fixtures/**/*.jade"));
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/test/run.jade"));
String(file.contents).should.equal("test template");
});
stream.on('end', function() {
done();
});
});
it('should return a input stream from a deeper glob', function(done) {
var stream = gulp.src(join(__dirname, "./fixtures/**/*.dmc"));
var a = 0;
stream.on('error', done);
stream.on('data', function() {
++a;
});
stream.on('end', function() {
a.should.equal(2);
done();
});
});
it('should return a file stream from a flat path', function(done) {
var a = 0;
var stream = gulp.src(join(__dirname, "./fixtures/test.coffee"));
stream.on('error', done);
stream.on('data', function(file) {
++a;
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/test.coffee"));
String(file.contents).should.equal("this is a test");
});
stream.on('end', function() {
a.should.equal(1);
done();
});
});
});
});