forked from gulpjs/gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdest.js
132 lines (114 loc) · 4.49 KB
/
dest.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
'use strict';
var gulp = require('../');
var should = require('should');
var join = require('path').join;
var rimraf = require('rimraf');
var fs = require('graceful-fs');
require('mocha');
var outpath = join(__dirname, './out-fixtures');
describe('gulp output stream', function() {
describe('dest()', function() {
beforeEach(rimraf.bind(null, outpath));
afterEach(rimraf.bind(null, outpath));
it('should return a stream', function(done) {
var stream = gulp.dest(join(__dirname, './fixtures/'));
should.exist(stream);
should.exist(stream.on);
done();
});
it('should return a output stream that writes files', function(done) {
var instream = gulp.src(join(__dirname, './fixtures/**/*.txt'));
var outstream = gulp.dest(outpath);
instream.pipe(outstream);
outstream.on('error', done);
outstream.on('data', function(file) {
// Data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
join(file.path, '').should.equal(join(outpath, './copy/example.txt'));
String(file.contents).should.equal('this is a test');
});
outstream.on('end', function() {
fs.readFile(join(outpath, 'copy', 'example.txt'), function(err, contents) {
should.not.exist(err);
should.exist(contents);
String(contents).should.equal('this is a test');
done();
});
});
});
it('should return a output stream that does not write non-read files', function(done) {
var instream = gulp.src(join(__dirname, './fixtures/**/*.txt'), {read: false});
var outstream = gulp.dest(outpath);
instream.pipe(outstream);
outstream.on('error', done);
outstream.on('data', function(file) {
// Data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.not.exist(file.contents);
join(file.path, '').should.equal(join(outpath, './copy/example.txt'));
});
outstream.on('end', function() {
fs.readFile(join(outpath, 'copy', 'example.txt'), function(err, contents) {
should.exist(err);
should.not.exist(contents);
done();
});
});
});
it('should return a output stream that writes streaming files', function(done) {
var instream = gulp.src(join(__dirname, './fixtures/**/*.txt'), {buffer: false});
var outstream = instream.pipe(gulp.dest(outpath));
outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
join(file.path, '').should.equal(join(outpath, './copy/example.txt'));
});
outstream.on('end', function() {
fs.readFile(join(outpath, 'copy', 'example.txt'), function(err, contents) {
should.not.exist(err);
should.exist(contents);
String(contents).should.equal('this is a test');
done();
});
});
});
it('should return a output stream that writes streaming files into new directories', function(done) {
testWriteDir({}, done);
});
it('should return a output stream that writes streaming files into new directories (buffer: false)', function(done) {
testWriteDir({buffer: false}, done);
});
it('should return a output stream that writes streaming files into new directories (read: false)', function(done) {
testWriteDir({read: false}, done);
});
it('should return a output stream that writes streaming files into new directories (read: false, buffer: false)', function(done) {
testWriteDir({buffer: false, read: false}, done);
});
function testWriteDir(srcOptions, done) {
var instream = gulp.src(join(__dirname, './fixtures/stuff'), srcOptions);
var outstream = instream.pipe(gulp.dest(outpath));
outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
join(file.path, '').should.equal(join(outpath, './stuff'));
});
outstream.on('end', function() {
fs.exists(join(outpath, 'stuff'), function(exists) {
/* Stinks that ok is an expression instead of a function call */
/* jshint expr: true */
should(exists).be.ok;
/* jshint expr: false */
done();
});
});
}
});
});