/
compress_test.js
108 lines (82 loc) · 3.92 KB
/
compress_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
var grunt = require('grunt');
var fs = require('fs');
var getSize = function(filename) {
'use strict';
try {
return fs.statSync(filename).size;
} catch (e) {
return 0;
}
};
exports.compress = {
main: function(test) {
'use strict';
test.expect(11);
// Zip
var actual = getSize('tmp/compress_test_files.zip');
var expected = getSize('test/expected/compress_test_files.zip');
test.equal(expected, actual, 'should compress files into zip');
actual = getSize('tmp/compress_test_v0.1.0.zip');
expected = getSize('test/expected/compress_test_v0.1.0.zip');
test.equal(expected, actual, 'should compress folders and their files into zip (with template support)');
actual = getSize('tmp/compress_test_files_template.zip');
expected = getSize('test/expected/compress_test_files_template.zip');
test.equal(expected, actual, 'should compress files and folders into zip (grunt template in source)');
// Tar
actual = getSize('tmp/compress_test_files.tar');
expected = getSize('test/expected/compress_test_files.tar');
test.equal(expected, actual, 'should add files into tar');
actual = getSize('tmp/compress_test_v0.1.0.tar');
expected = getSize('test/expected/compress_test_v0.1.0.tar');
test.equal(expected, actual, 'should add folders and their files into tar (with template support)');
actual = getSize('tmp/compress_test_files_template.tar');
expected = getSize('test/expected/compress_test_files_template.tar');
test.equal(expected, actual, 'should add files and folders into tar (grunt template in source)');
// Tar (gzip)
actual = getSize('tmp/compress_test_files.tgz') >= 195;
expected = true;
test.equal(expected, actual, 'should compress files into tgz');
actual = getSize('tmp/compress_test_v0.1.0.tgz') >= 315;
expected = true;
test.equal(expected, actual, 'should compress folders and their files into tgz (with template support)');
actual = getSize('tmp/compress_test_files_template.tgz') >= 200;
expected = true;
test.equal(expected, actual, 'should compress files and folders into tgz (grunt template in source)');
// gzip
actual = getSize('tmp/compress_test_file.js.gz');
expected = getSize('test/expected/compress_test_file.js.gz');
test.equal(expected, actual, 'should gzip file');
actual = getSize('tmp/compress_test_file2.js.gz');
expected = getSize('test/expected/compress_test_file2.js.gz');
test.equal(expected, actual, 'should gzip another file (multiple dest:source pairs)');
test.done();
},
flatten: function(test) {
'use strict';
test.expect(3);
var actual = getSize('tmp/compress_test_flatten.zip');
var expected = getSize('test/expected/compress_test_flatten.zip');
test.equal(expected, actual, 'should create a flat internal structure');
actual = getSize('tmp/compress_test_flatten.tar');
expected = getSize('test/expected/compress_test_flatten.tar');
test.equal(expected, actual, 'should create a flat internal structure');
actual = getSize('tmp/compress_test_flatten.tgz') >= 297;
expected = true;
test.equal(expected, actual, 'should create a flat internal structure');
test.done();
},
rootdir: function(test) {
'use strict';
test.expect(3);
var actual = getSize('tmp/compress_test_rootdir.zip');
var expected = getSize('test/expected/compress_test_rootdir.zip');
test.equal(expected, actual, 'should compress folders and their files into zip (with a root dir)');
actual = getSize('tmp/compress_test_rootdir.tar');
expected = getSize('test/expected/compress_test_rootdir.tar');
test.equal(expected, actual, 'should compress folders and their files into tar (with a custom root dir)');
actual = getSize('tmp/compress_test_rootdir.tgz') >= 200;
expected = true;
test.equal(expected, actual, 'should compress folders and their files into tgz (with a custom root dir)');
test.done();
}
};