forked from sseixas/gulp-tar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
125 lines (100 loc) · 2.86 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
115
116
117
118
119
120
121
122
123
124
125
'use strict';
var path = require('path');
var Stream = require('stream');
var assert = require('assert');
var gutil = require('gulp-util');
var tarStream = require('tar-stream');
var vinylMap = require('vinyl-map');
var tar = require('./');
var Readable = Stream.Readable;
it('should tar files in buffer mode', function (cb) {
var stream = tar('test.tar');
stream.on('data', function (file) {
assert.equal(file.path, path.join(__dirname, 'fixture', 'test.tar'));
assert.equal(file.relative, 'test.tar');
cb();
});
stream.write(new gutil.File({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture/fixture.txt'),
contents: new Buffer('hello world 1')
}));
stream.write(new gutil.File({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture/fixture.txt'),
contents: new Buffer('hello world 2')
}));
stream.end();
});
it('should tar files in stream mode', function (cb) {
var stream = tar('test.tar');
var stringStream1 = new Stream();
var stringStream2 = new Stream();
stringStream1.pipe = function (dest) {
dest.write('hello world 1');
};
stringStream2.pipe = function (dest) {
dest.write('hello world 2');
};
stream.on('data', function (file) {
assert.equal(file.path, path.join(__dirname, 'fixture', 'test.tar'));
assert.equal(file.relative, 'test.tar');
cb();
});
stream.write(new gutil.File({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture/fixture.txt'),
contents: stringStream1
}));
stream.write(new gutil.File({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture/fixture.txt'),
contents: stringStream2
}));
stream.end();
});
it('should output file.contents as a Stream', function (cb) {
var stream = tar('test.tar');
stream.on('data', function (file) {
assert(file.contents instanceof Stream, 'File contents should be a Stream object');
cb();
});
stream.write(new gutil.File({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture/fixture.txt'),
contents: new Buffer('hello world')
}));
stream.end();
});
it('should include directories', function (cb) {
var stream = tar('test.tar');
var evaluate = vinylMap(function (code, filename) {
var inspect = tarStream.extract();
var rs = new Readable();
inspect.on('entry', function (header, stream, callback) {
stream.on('end', function () {
assert.equal(header.type, 'directory');
assert.equal(header.name, 'fixture2/');
cb();
});
stream.resume();
});
rs._read = function () {
rs.push(code.toString());
};
rs.pipe(inspect);
});
stream.write(new gutil.File({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture/fixture2'),
contents: null
}));
stream.end();
stream.pipe(evaluate);
});