forked from TheTechsTech/node-unar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-unpack-list.js
179 lines (158 loc) · 4.87 KB
/
test-unpack-list.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict';
import chai from 'chai';
import Unar from '../index.js';
import { list, unpack } from '../index.js';
const expect = chai.expect,
archive = 'test/attr.7z',
archiveBlank = 'test/blank.zip',
options = {
targetDir: 'tmp',
indexes: [0],
forceOverwrite: true,
noDirectory: true,
quiet: true
};
describe('Method: `list`', function () {
it('should return an error on lsar error', function (done) {
list('??', { targetDir: 'tmp', quiet: false })
.catch((err) => {
expect(err).to.be.a('string');
done();
});
});
it('should return an error on if missing source file', function (done) {
list(null, options)
.catch((err) => {
expect(err).to.be.a('string');
done();
});
});
it('should return an error on archive have no files', function (done) {
list(archiveBlank, options)
.catch((err) => {
expect(err).to.be.a('string');
done();
});
});
it('should return list of files by index', function (done) {
list(archive, options)
.then((files) => {
expect(files[options.indexes]).to.be.a('string');
done();
});
});
it('should return list of files with a password', function (done) {
list(archive, { password: 123 })
.then((files) => {
expect(files).to.be.a('array');
done();
});
});
it('should return list of files by index `options` null', function (done) {
list(archive, null)
.then((files) => {
expect(files[options.indexes]).to.be.a('string');
done();
});
});
});
describe('Method: `unpack`', function () {
it('should return an error on unar error', function (done) {
unpack('???', options)
.catch((err) => {
expect(err).to.be.a('string');
done();
});
});
it('should return an error on if missing source file', function (done) {
unpack(null, options)
.catch((err) => {
expect(err).to.be.a('string');
done();
});
});
it('should return an error on archive have no files or nothing extracted', function (done) {
unpack(archiveBlank, options)
.catch((err) => {
expect(err).to.be.a('string');
done();
});
});
it('should error on invalid index', function (done) {
unpack(archive, { password: 123, indexes: 1 })
.catch((err) => {
expect(err).to.be.a('string');
done();
});
});
it('should output on progress with `files`, target `directory`, archive `type` extracted on success', function (done) {
unpack(archive, {
targetDir: 'tmp',
forceOverwrite: true,
noDirectory: true,
quiet: false
})
.progress((files) => {
expect(files).to.be.a('string');
})
.then((result) => {
expect(result).to.be.a('object');
expect(result.type).to.be.a('string');
expect(result.files).to.be.a('array');
expect(result.directory).to.be.a('string');
done();
});
});
it('should output `files`, target `directory`, archive `type` extracted `options` null', function (done) {
unpack(archive, null)
.progress((files) => {
expect(files).to.be.a('string');
})
.then((result) => {
expect(result).to.be.a('object');
expect(result.type).to.be.a('string');
expect(result.files).to.be.a('array');
expect(result.directory).to.be.a('string');
done();
})
});
it('should return output to directory', function (done) {
unpack(archive, 'tmp', { password: 123 })
.then((result) => {
expect(result.directory).to.contain('tmp');
done();
});
});
});
describe('Method: `unpack` only', function () {
it('should return output on progress', function (done) {
unpack(archive, 'tmp', 'attr/system file.txt')
.then((result) => {
expect(result.files).to.contain('attr/system file.txt');
expect(result.files).to.not.contain('att/normal file.txt');
done();
});
});
it('should not output any other file than what is supplied successful', function (done) {
unpack(archive, 'tmp', ['attr/normal file.txt', 'attr/read-only file.txt'])
.progress((files) => {
expect(files).to.be.a('string');
}).then((result) => {
expect(result.files).to.not.contain('system file.txt');
expect(result.files).to.contain('attr/read-only file.txt');
expect(result.files).to.contain('attr/normal file.txt');
done();
});
});
});
describe('Function: `Unar`', function () {
it('should instanced itself like a class', function () {
const unar = new Unar();
expect(unar).to.be.an.instanceof(Unar);
});
it('should respond to commands as methods', function () {
expect(Unar).itself.to.respondTo('defaultListFilter');
expect(Unar).itself.to.respondTo('unpack');
expect(Unar).itself.to.respondTo('list');
});
});