json-to-fs-structure 1.2.13 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,513 +0,0 @@
1
- const assert = require("assert");
2
- const fs = require("fs");
3
-
4
- const {
5
- jsonToFsStructure,
6
- jsonToFsWithLeafFunction,
7
- jsonToFsWithNonLeafFunction,
8
- jsonToFsWithFunction
9
- } = require("../index");
10
-
11
- describe("json-to-fs-structure", () => {
12
- describe("jsonToFsStructure", () => {
13
- it("should produce a simple directory with a first layer object", done => {
14
- const options = {
15
- jsonObject: {
16
- testDirectoryField: {}
17
- },
18
- filePath: ".",
19
- callback: () => {
20
- assert.equal(fs.statSync("testDirectoryField").size, 4096);
21
- fs.rmdirSync("testDirectoryField");
22
- done();
23
- }
24
- };
25
- jsonToFsStructure(options);
26
- });
27
- it("should produce a simple directory with a first layer object with siblings", done => {
28
- const options = {
29
- jsonObject: {
30
- testDirectoryField0: {},
31
- testDirectoryField1: {},
32
- testDirectoryField2: {}
33
- },
34
- filePath: ".",
35
- callback: () => {
36
- assert.equal(fs.statSync("testDirectoryField0").size, 4096);
37
- assert.equal(fs.statSync("testDirectoryField1").size, 4096);
38
- assert.equal(fs.statSync("testDirectoryField2").size, 4096);
39
- fs.rmdirSync("testDirectoryField0");
40
- fs.rmdirSync("testDirectoryField1");
41
- fs.rmdirSync("testDirectoryField2");
42
- done();
43
- }
44
- };
45
- jsonToFsStructure(options);
46
- });
47
- it("should produce a nested directory structure", done => {
48
- const options = {
49
- jsonObject: {
50
- testDirectoryField3: { innerTestField: {} }
51
- },
52
- filePath: ".",
53
- callback: () => {
54
- assert.equal(
55
- fs.statSync("testDirectoryField3/innerTestField").size,
56
- 4096
57
- );
58
- fs.rmdirSync("testDirectoryField3/innerTestField");
59
- fs.rmdirSync("testDirectoryField3");
60
- done();
61
- }
62
- };
63
- jsonToFsStructure(options);
64
- });
65
- it("should produce a nested directory structure when there is an array of strings", done => {
66
- const options = {
67
- jsonObject: {
68
- testArrayField5: [
69
- { somedir: {} },
70
- { anotherdir: {} },
71
- { andanotherdir: {} }
72
- ]
73
- },
74
- filePath: ".",
75
- callback: () => {
76
- assert.equal(fs.statSync("testArrayField5/somedir").size, 4096);
77
- assert.equal(fs.statSync("testArrayField5/anotherdir").size, 4096);
78
- assert.equal(fs.statSync("testArrayField5/andanotherdir").size, 4096);
79
- fs.rmdirSync("testArrayField5/somedir");
80
- fs.rmdirSync("testArrayField5/anotherdir");
81
- fs.rmdirSync("testArrayField5/andanotherdir");
82
- fs.rmdirSync("testArrayField5");
83
- done();
84
- }
85
- };
86
- jsonToFsStructure(options);
87
- });
88
- it("should produce a nested deep complex directory structure", done => {
89
- const options = {
90
- jsonObject: {
91
- testArrayField5: [
92
- { somedir: {} },
93
- { anotherdir: {} },
94
- {
95
- andanotherdir: {
96
- interiorone: {
97
- interiortwo: {
98
- interiorthree: [{ interiorfour: {} }, { interiorfive: {} }]
99
- }
100
- }
101
- }
102
- }
103
- ]
104
- },
105
- filePath: ".",
106
- callback: () => {
107
- assert.equal(fs.statSync("testArrayField5/somedir").size, 4096);
108
- assert.equal(fs.statSync("testArrayField5/anotherdir").size, 4096);
109
- assert.equal(fs.statSync("testArrayField5/andanotherdir").size, 4096);
110
- assert.equal(
111
- fs.statSync("testArrayField5/andanotherdir/interiorone").size,
112
- 4096
113
- );
114
- assert.equal(
115
- fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
116
- .size,
117
- 4096
118
- );
119
- assert.equal(
120
- fs.statSync(
121
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree"
122
- ).size,
123
- 4096
124
- );
125
- assert.equal(
126
- fs.statSync(
127
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour"
128
- ).size,
129
- 4096
130
- );
131
- assert.equal(
132
- fs.statSync(
133
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive"
134
- ).size,
135
- 4096
136
- );
137
- fs.rmdirSync("testArrayField5/somedir");
138
- fs.rmdirSync("testArrayField5/anotherdir");
139
- fs.rmdirSync(
140
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive"
141
- );
142
- fs.rmdirSync(
143
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour"
144
- );
145
- fs.rmdirSync(
146
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree"
147
- );
148
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
149
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
150
- fs.rmdirSync("testArrayField5/andanotherdir");
151
- fs.rmdirSync("testArrayField5");
152
- done();
153
- }
154
- };
155
- jsonToFsStructure(options);
156
- });
157
- });
158
- describe("jsonToFsWithLeafFunction", () => {
159
- it("should produce a nested deep complex directory structure and execute the procedure on leaves", done => {
160
- const endpoints = [];
161
- const options = {
162
- jsonObject: {
163
- testArrayField5: [
164
- { somedir: {} },
165
- { anotherdir: {} },
166
- {
167
- andanotherdir: {
168
- interiorone: {
169
- interiortwo: {
170
- interiorthree: [{ interiorfour: {} }, { interiorfive: {} }]
171
- }
172
- }
173
- }
174
- }
175
- ]
176
- },
177
- filePath: ".",
178
- leafProcedure: (filePath, acc) => {
179
- endpoints.push(filePath);
180
- },
181
- callback: () => {
182
- assert.equal(fs.statSync("testArrayField5/somedir").size, 4096);
183
- assert.equal(fs.statSync("testArrayField5/anotherdir").size, 4096);
184
- assert.equal(fs.statSync("testArrayField5/andanotherdir").size, 4096);
185
- assert.equal(
186
- fs.statSync("testArrayField5/andanotherdir/interiorone").size,
187
- 4096
188
- );
189
- assert.equal(
190
- fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
191
- .size,
192
- 4096
193
- );
194
- assert.equal(
195
- fs.statSync(
196
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree"
197
- ).size,
198
- 4096
199
- );
200
- assert.equal(
201
- fs.statSync(
202
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour"
203
- ).size,
204
- 4096
205
- );
206
- assert.equal(
207
- fs.statSync(
208
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive"
209
- ).size,
210
- 4096
211
- );
212
- fs.rmdirSync("testArrayField5/somedir");
213
- fs.rmdirSync("testArrayField5/anotherdir");
214
- fs.rmdirSync(
215
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive"
216
- );
217
- fs.rmdirSync(
218
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour"
219
- );
220
- fs.rmdirSync(
221
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree"
222
- );
223
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
224
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
225
- fs.rmdirSync("testArrayField5/andanotherdir");
226
- fs.rmdirSync("testArrayField5");
227
- done();
228
- }
229
- };
230
- jsonToFsWithLeafFunction(options);
231
- expect(endpoints).toMatchSnapshot();
232
- });
233
- it("should produce a nested directory not past a stop word with a leaf function", done => {
234
- const endpoints = [];
235
- const options = {
236
- jsonObject: {
237
- testArrayField5: [
238
- { somedir: {} },
239
- { anotherdir: {} },
240
- {
241
- andanotherdir: {
242
- interiorone: {
243
- interiortwo: {
244
- interiorthree: [{ interiorfour: {} }, { interiorfive: {} }]
245
- }
246
- }
247
- }
248
- }
249
- ]
250
- },
251
- leafProcedure: (filePath, acc) => {
252
- endpoints.push(filePath);
253
- },
254
- filePath: ".",
255
- callback: () => {
256
- assert.equal(fs.statSync("testArrayField5/somedir").size, 4096);
257
- assert.equal(fs.statSync("testArrayField5/anotherdir").size, 4096);
258
- assert.equal(fs.statSync("testArrayField5/andanotherdir").size, 4096);
259
- fs.rmdirSync("testArrayField5/somedir");
260
- fs.rmdirSync("testArrayField5/anotherdir");
261
- fs.rmdirSync("testArrayField5/andanotherdir");
262
- fs.rmdirSync("testArrayField5");
263
- done();
264
- },
265
- stopWord: "interiorone"
266
- };
267
- jsonToFsWithLeafFunction(options);
268
- expect(endpoints).toMatchSnapshot();
269
- });
270
- });
271
- describe("jsonToFsWithNonLeafFunction", () => {
272
- it("should produce a nested deep complex directory structure and execute the procedure on non leaves", done => {
273
- const endpoints = [];
274
- const options = {
275
- jsonObject: {
276
- testArrayField5: [
277
- { somedir: {} },
278
- { anotherdir: {} },
279
- {
280
- andanotherdir: {
281
- interiorone: {
282
- interiortwo: {
283
- interiorthree: [{ interiorfour: {} }, { interiorfive: {} }]
284
- }
285
- }
286
- }
287
- }
288
- ]
289
- },
290
- nonLeafProcedure: (filePath, acc) => {
291
- endpoints.push(filePath);
292
- },
293
- filePath: ".",
294
- context: {},
295
- callback: () => {
296
- assert.equal(fs.statSync("testArrayField5/somedir").size, 4096);
297
- assert.equal(fs.statSync("testArrayField5/anotherdir").size, 4096);
298
- assert.equal(fs.statSync("testArrayField5/andanotherdir").size, 4096);
299
- assert.equal(
300
- fs.statSync("testArrayField5/andanotherdir/interiorone").size,
301
- 4096
302
- );
303
- assert.equal(
304
- fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
305
- .size,
306
- 4096
307
- );
308
- assert.equal(
309
- fs.statSync(
310
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree"
311
- ).size,
312
- 4096
313
- );
314
- assert.equal(
315
- fs.statSync(
316
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour"
317
- ).size,
318
- 4096
319
- );
320
- assert.equal(
321
- fs.statSync(
322
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive"
323
- ).size,
324
- 4096
325
- );
326
- fs.rmdirSync("testArrayField5/somedir");
327
- fs.rmdirSync("testArrayField5/anotherdir");
328
- fs.rmdirSync(
329
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive"
330
- );
331
- fs.rmdirSync(
332
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour"
333
- );
334
- fs.rmdirSync(
335
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree"
336
- );
337
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
338
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
339
- fs.rmdirSync("testArrayField5/andanotherdir");
340
- fs.rmdirSync("testArrayField5");
341
- done();
342
- }
343
- };
344
- jsonToFsWithNonLeafFunction(options);
345
- expect(endpoints).toMatchSnapshot();
346
- });
347
- });
348
- describe("jsonToFsWithFunction", () => {
349
- it("should produce a nested deep complex directory structure and execute the procedure on everything", done => {
350
- const endpoints = [];
351
- const options = {
352
- jsonObject: {
353
- testArrayField5: [
354
- { somedir: {} },
355
- { anotherdir: {} },
356
- {
357
- andanotherdir: {
358
- interiorone: {
359
- interiortwo: {
360
- interiorthree: [{ interiorfour: {} }, { interiorfive: {} }]
361
- }
362
- }
363
- }
364
- }
365
- ]
366
- },
367
- procedure: (filePath, acc) => {
368
- endpoints.push(filePath);
369
- },
370
- filePath: ".",
371
- context: {},
372
- callback: () => {
373
- assert.equal(fs.statSync("testArrayField5/somedir").size, 4096);
374
- assert.equal(fs.statSync("testArrayField5/anotherdir").size, 4096);
375
- assert.equal(fs.statSync("testArrayField5/andanotherdir").size, 4096);
376
- assert.equal(
377
- fs.statSync("testArrayField5/andanotherdir/interiorone").size,
378
- 4096
379
- );
380
- assert.equal(
381
- fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
382
- .size,
383
- 4096
384
- );
385
- assert.equal(
386
- fs.statSync(
387
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree"
388
- ).size,
389
- 4096
390
- );
391
- assert.equal(
392
- fs.statSync(
393
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour"
394
- ).size,
395
- 4096
396
- );
397
- assert.equal(
398
- fs.statSync(
399
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive"
400
- ).size,
401
- 4096
402
- );
403
- fs.rmdirSync("testArrayField5/somedir");
404
- fs.rmdirSync("testArrayField5/anotherdir");
405
- fs.rmdirSync(
406
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfive"
407
- );
408
- fs.rmdirSync(
409
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree/interiorfour"
410
- );
411
- fs.rmdirSync(
412
- "testArrayField5/andanotherdir/interiorone/interiortwo/interiorthree"
413
- );
414
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
415
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
416
- fs.rmdirSync("testArrayField5/andanotherdir");
417
- fs.rmdirSync("testArrayField5");
418
- done();
419
- }
420
- };
421
- jsonToFsWithFunction(options);
422
- expect(endpoints).toMatchSnapshot();
423
- });
424
- it("should not go below the stop word andanotherdir provided", done => {
425
- const endpoints = [];
426
- const options = {
427
- jsonObject: {
428
- testArrayField5: [
429
- { somedir: {} },
430
- { anotherdir: {} },
431
- {
432
- andanotherdir: {
433
- interiorone: {
434
- interiortwo: {
435
- interiorthree: [{ interiorfour: {} }, { interiorfive: {} }]
436
- }
437
- }
438
- }
439
- }
440
- ]
441
- },
442
- procedure: (filePath, acc) => {
443
- endpoints.push(filePath);
444
- },
445
- filePath: ".",
446
- context: {},
447
- callback: () => {
448
- assert.equal(fs.statSync("testArrayField5/somedir").size, 4096);
449
- assert.equal(fs.statSync("testArrayField5/anotherdir").size, 4096);
450
- fs.rmdirSync("testArrayField5/somedir");
451
- fs.rmdirSync("testArrayField5/anotherdir");
452
- fs.rmdirSync("testArrayField5");
453
- done();
454
- },
455
- stopWord: "andanotherdir"
456
- };
457
- jsonToFsWithFunction(options);
458
- expect(endpoints).toMatchSnapshot();
459
- });
460
- it("should not do anything with ignored words like meta", done => {
461
- const endpoints = [];
462
- const options = {
463
- jsonObject: {
464
- testArrayField5: [
465
- { somedir: { meta: {}, apple: {} } },
466
- { anotherdir: {} },
467
- {
468
- meta: { somethingweird: {} },
469
- andanotherdir: {
470
- interiorone: {
471
- interiortwo: {
472
- apple: { dontdonothing: {} },
473
- interiorthree: [{ interiorfour: {} }, { interiorfive: {} }]
474
- }
475
- }
476
- }
477
- }
478
- ]
479
- },
480
- procedure: (filePath, acc) => {
481
- endpoints.push(filePath);
482
- },
483
- filePath: ".",
484
- context: {},
485
- callback: () => {
486
- assert.equal(fs.statSync("testArrayField5/somedir").size, 4096);
487
- assert.equal(fs.statSync("testArrayField5/anotherdir").size, 4096);
488
- assert.equal(fs.statSync("testArrayField5/andanotherdir").size, 4096);
489
- assert.equal(
490
- fs.statSync("testArrayField5/andanotherdir/interiorone").size,
491
- 4096
492
- );
493
- assert.equal(
494
- fs.statSync("testArrayField5/andanotherdir/interiorone/interiortwo")
495
- .size,
496
- 4096
497
- );
498
- fs.rmdirSync("testArrayField5/somedir");
499
- fs.rmdirSync("testArrayField5/anotherdir");
500
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone/interiortwo");
501
- fs.rmdirSync("testArrayField5/andanotherdir/interiorone");
502
- fs.rmdirSync("testArrayField5/andanotherdir");
503
- fs.rmdirSync("testArrayField5");
504
- done();
505
- },
506
- ignoredWords: ["meta", "apple"],
507
- stopWord: "interiorthree"
508
- };
509
- jsonToFsWithFunction(options);
510
- expect(endpoints).toMatchSnapshot();
511
- });
512
- });
513
- });