-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patherrors.spec.js
234 lines (232 loc) · 8.58 KB
/
errors.spec.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
"use strict";
const forEachApi = require("../utils/for-each-api");
const { expect } = require("chai");
describe("error handling", () => {
forEachApi([
{
it: "should throw an error if no arguments are passed",
args: [],
assert (error, data) {
expect(error).to.be.an.instanceOf(TypeError);
expect(error.message).to.match(/must be a string|must be one of type string|must be of type string/);
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if the path is not a string",
args: [55555],
assert (error, data) {
expect(error).to.be.an.instanceOf(TypeError);
expect(error.message).to.match(/must be a string|must be one of type string|must be of type string/);
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if options are invalid",
args: ["test/dir", "invalid options"],
assert (error, data) {
expect(error).to.be.an.instanceOf(TypeError);
expect(error.message).to.equal("options must be an object");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if options.deep is invalid",
args: ["test/dir", { deep: { foo: "bar" }}],
assert (error, data) {
expect(error).to.be.an.instanceOf(TypeError);
expect(error.message).to.equal("options.deep must be a boolean, number, function, regular expression, or glob pattern");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if options.deep is negative",
args: ["test/dir", { deep: -5 }],
assert (error, data) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal("options.deep must be a positive number");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if options.deep is NaN",
args: ["test/dir", { deep: NaN }],
assert (error, data) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal("options.deep must be a positive number");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if options.deep is not an integer",
args: ["test/dir", { deep: 5.4 }],
assert (error, data) {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal("options.deep must be an integer");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if options.filter is invalid",
args: ["test/dir", { filter: 12345 }],
assert (error, data) {
expect(error).to.be.an.instanceOf(TypeError);
expect(error.message).to.equal(
"options.filter must be a boolean, function, regular expression, or glob pattern");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if options.sep is invalid",
args: ["test/dir", { sep: 57 }],
assert (error, data) {
expect(error).to.be.an.instanceOf(TypeError);
expect(error.message).to.equal("options.sep must be a string");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if options.basePath is invalid",
args: ["test/dir", { basePath: 57 }],
assert (error, data) {
expect(error).to.be.an.instanceOf(TypeError);
expect(error.message).to.equal("options.basePath must be a string");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if the directory does not exist",
args: ["test/dir/does-not-exist"],
assert (error, data) {
expect(error).to.be.an.instanceOf(Error);
expect(error.code).to.equal("ENOENT");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if the path is not a directory",
args: ["test/dir/file.txt"],
assert (error, data) {
expect(error).to.be.an.instanceOf(Error);
expect(error.code).to.equal("ENOTDIR");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if the path is a broken symlink",
args: ["test/dir/broken-dir-symlink"],
assert (error, data) {
expect(error).to.be.an.instanceOf(Error);
expect(error.code).to.equal("ENOENT");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
{
it: "should throw an error if `options.fs` is invalid",
args: ["test/dir", { fs: "Hello, World" }],
assert (error, data) {
expect(error).to.be.an.instanceOf(TypeError);
expect(error.message).to.equal("options.fs must be an object");
expect(data).to.equal(undefined);
},
streamAssert (errors, data, files, dirs, symlinks) {
expect(errors).to.have.lengthOf(1);
expect(data).to.have.lengthOf(0);
expect(files).to.have.lengthOf(0);
expect(dirs).to.have.lengthOf(0);
expect(symlinks).to.have.lengthOf(0);
},
},
]);
});