Skip to content

Commit 12499b6

Browse files
committed
ES6 refactor #21
1 parent 50488ed commit 12499b6

File tree

1 file changed

+106
-100
lines changed

1 file changed

+106
-100
lines changed

test.js

+106-100
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var unzip = require('./index.js')
2-
var fs = require('fs')
3-
var assert = require('assert-plus')
4-
var pj = require('path').join;
5-
var minimatch = require('minimatch')
6-
var Vinyl = require('vinyl');
1+
const unzip = require('./index.js'),
2+
fs = require('fs'),
3+
assert = require('assert-plus'),
4+
pj = require('path').join,
5+
minimatch = require('minimatch'),
6+
Vinyl = require('vinyl');
77

88
function createVinyl(filename, contents) {
9-
var base = pj(__dirname, 'fixture');
10-
var filePath = pj(base, filename);
9+
const base = pj(__dirname, 'fixture');
10+
const filePath = pj(base, filename);
1111

1212
return new Vinyl({
1313
cwd: __dirname,
@@ -17,108 +17,114 @@ function createVinyl(filename, contents) {
1717
});
1818
}
1919

20-
describe('gulp-unzip', function(){
21-
it("null file", function(done){
22-
var stream = unzip()
23-
var mock = new Vinyl()
24-
stream.on('data', function(file){
25-
assert.deepEqual(file, mock)
26-
done()
27-
})
28-
stream.write(mock)
29-
stream.end()
30-
})
31-
it("basic", function(done){
32-
var stream = unzip()
33-
var mock = createVinyl('basic/zipped.zip')
34-
stream.on('data', function(file){
35-
var expect = fs.readFileSync('fixture/basic/' + file.path)
36-
assert.deepEqual(expect, file.contents)
37-
}).on('end', function(){
38-
done()
39-
})
40-
stream.write(mock)
41-
stream.end()
42-
})
43-
it("large_file", function(done){
44-
var stream = unzip()
45-
var mock = createVinyl('largefile/zipped.zip')
46-
stream.on('data', function(file){
47-
var expect = fs.readFileSync('fixture/largefile/' + file.path)
48-
assert.deepEqual(expect, file.contents)
49-
}).on('end', function(){
50-
done()
51-
})
52-
stream.write(mock)
53-
stream.end()
54-
})
55-
describe("filter option", function(){
56-
it("false filter", function(done){
57-
var stream = unzip({
58-
filter : function(){return false}
59-
})
60-
var mock = createVinyl('basic/zipped.zip')
61-
stream.on('data', function(file){
62-
throw "entried"
63-
}).on('end', function(){
64-
done()
65-
})
66-
stream.write(mock)
67-
stream.end()
68-
})
20+
describe('gulp-unzip', () => {
21+
22+
describe('basic behaviour', () => {
23+
24+
it("null file", done => {
25+
const stream = unzip();
26+
const mock = new Vinyl();
27+
28+
stream.on('data', file => {
29+
assert.deepEqual(file, mock);
30+
done();
31+
});
32+
stream.write(mock);
33+
stream.end();
34+
});
35+
36+
it("basic", done => {
37+
const stream = unzip();
38+
const mock = createVinyl('basic/zipped.zip');
39+
40+
stream.on('data', file => {
41+
const expect = fs.readFileSync('fixture/basic/' + file.path);
42+
assert.deepEqual(expect, file.contents);
43+
}).on('end', done);
44+
stream.write(mock);
45+
stream.end();
46+
});
47+
48+
it("large_file", done => {
49+
const stream = unzip();
50+
const mock = createVinyl('largefile/zipped.zip');
51+
52+
stream.on('data', file => {
53+
const expect = fs.readFileSync('fixture/largefile/' + file.path);
54+
assert.deepEqual(expect, file.contents);
55+
}).on('end', done);
56+
stream.write(mock);
57+
stream.end();
58+
});
59+
});
60+
61+
describe("filter option", () => {
62+
63+
it("false filter", done => {
64+
const stream = unzip({
65+
filter : () => false
66+
});
67+
const mock = createVinyl('basic/zipped.zip');
68+
69+
stream.on('data', file => {
70+
throw "entried";
71+
}).on('end', done);
72+
stream.write(mock);
73+
stream.end();
74+
});
6975

70-
it("only extract css with filter", function(done){
71-
var stream = unzip({
72-
filter : function(entry){
73-
return minimatch(entry.path, "**/*.min.css")
74-
}
75-
})
76-
var mock = createVinyl('sometypes/bootstrap-3.1.1-dist.zip')
77-
stream.on('data', function(file){
78-
assert.ok(/.*\.min\.css/.test(file.path))
79-
}).on('end', function(){
80-
done()
81-
})
82-
stream.write(mock)
83-
stream.end()
84-
})
85-
})
76+
it("only extract css with filter", done => {
77+
const stream = unzip({
78+
filter: entry => minimatch(entry.path, "**/*.min.css")
79+
});
80+
const mock = createVinyl('sometypes/bootstrap-3.1.1-dist.zip');
81+
82+
stream.on('data', file => {
83+
assert.ok(/.*\.min\.css/.test(file.path));
84+
}).on('end', done);
85+
stream.write(mock);
86+
stream.end();
87+
});
88+
});
8689

87-
describe("keepEmpty option", function(){
88-
it("true", function(done){
89-
var stream = unzip({ keepEmpty: false })
90-
var didSeeEmpty = false
91-
var mock = createVinyl('basic/zipped.zip')
92-
stream.on('data', function(file){
90+
describe("keepEmpty option", () => {
91+
92+
it("true", done => {
93+
const stream = unzip({ keepEmpty: false });
94+
const mock = createVinyl('basic/zipped.zip');
95+
let didSeeEmpty = false;
96+
97+
stream.on('data', file => {
9398
if (file.contents.length === 0) {
9499
didSeeEmpty = true;
95100
}
96-
}).on('end', function(){
101+
}).on('end', () => {
97102
if (didSeeEmpty) {
98-
throw new Error('saw empty')
103+
throw new Error('saw empty');
99104
}
100-
done()
101-
})
102-
stream.write(mock)
103-
stream.end()
104-
})
105+
done();
106+
});
107+
stream.write(mock);
108+
stream.end();
109+
});
110+
111+
it("false", done => {
112+
const stream = unzip({ keepEmpty: true });
113+
const mock = createVinyl('basic/zipped.zip');
114+
let didSeeEmpty = false;
105115

106-
it("false", function(done){
107-
var stream = unzip({ keepEmpty: true })
108-
var didSeeEmpty = false
109-
var mock = createVinyl('basic/zipped.zip')
110-
stream.on('data', function(file){
116+
stream.on('data', file => {
111117
if (file.contents.length === 0) {
112118
didSeeEmpty = true;
113119
}
114-
}).on('end', function(){
120+
}).on('end', () => {
115121
if (!didSeeEmpty) {
116-
throw new Error('did not see empty')
122+
throw new Error('did not see empty');
117123
}
118-
done()
119-
})
120-
stream.write(mock)
121-
stream.end()
122-
})
123-
})
124-
})
124+
done();
125+
});
126+
stream.write(mock);
127+
stream.end();
128+
});
129+
});
130+
});

0 commit comments

Comments
 (0)