pwd-fs 3.3.0 → 3.3.2

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.
Files changed (104) hide show
  1. package/dist/bitmask.d.ts +4 -0
  2. package/dist/{src/bitmask.js → bitmask.js} +3 -1
  3. package/dist/bitmask.test.d.ts +1 -0
  4. package/dist/bitmask.test.js +29 -0
  5. package/dist/{src/index.d.ts → index.d.ts} +3 -0
  6. package/dist/{src/index.js → index.js} +3 -1
  7. package/dist/powered-file-system/append.d.ts +9 -0
  8. package/dist/powered-file-system/append.js +10 -0
  9. package/dist/powered-file-system/append.test.d.ts +1 -0
  10. package/dist/powered-file-system/append.test.js +47 -0
  11. package/dist/powered-file-system/chmod.d.ts +7 -0
  12. package/dist/powered-file-system/chmod.js +28 -0
  13. package/dist/powered-file-system/chmod.test.d.ts +1 -0
  14. package/dist/powered-file-system/chmod.test.js +71 -0
  15. package/dist/powered-file-system/chown.d.ts +9 -0
  16. package/dist/powered-file-system/chown.js +45 -0
  17. package/dist/powered-file-system/chown.test.d.ts +1 -0
  18. package/dist/powered-file-system/chown.test.js +82 -0
  19. package/dist/powered-file-system/copy.d.ts +8 -0
  20. package/dist/powered-file-system/copy.js +29 -0
  21. package/dist/powered-file-system/copy.test.d.ts +1 -0
  22. package/dist/powered-file-system/copy.test.js +82 -0
  23. package/dist/powered-file-system/mkdir.d.ts +8 -0
  24. package/dist/powered-file-system/mkdir.js +28 -0
  25. package/dist/powered-file-system/mkdir.test.d.ts +1 -0
  26. package/dist/powered-file-system/mkdir.test.js +116 -0
  27. package/dist/powered-file-system/read.d.ts +9 -0
  28. package/dist/powered-file-system/read.js +29 -0
  29. package/dist/powered-file-system/read.test.d.ts +1 -0
  30. package/dist/powered-file-system/read.test.js +75 -0
  31. package/dist/powered-file-system/readdir.d.ts +8 -0
  32. package/dist/powered-file-system/readdir.js +26 -0
  33. package/dist/powered-file-system/readdir.test.d.ts +1 -0
  34. package/dist/powered-file-system/readdir.test.js +72 -0
  35. package/dist/powered-file-system/remove.d.ts +7 -0
  36. package/dist/powered-file-system/remove.js +36 -0
  37. package/dist/powered-file-system/remove.test.d.ts +1 -0
  38. package/dist/powered-file-system/remove.test.js +78 -0
  39. package/dist/powered-file-system/rename.d.ts +7 -0
  40. package/dist/powered-file-system/rename.js +28 -0
  41. package/dist/powered-file-system/rename.test.d.ts +1 -0
  42. package/dist/powered-file-system/rename.test.js +70 -0
  43. package/dist/powered-file-system/stat.d.ts +7 -0
  44. package/dist/powered-file-system/stat.js +26 -0
  45. package/dist/powered-file-system/stat.test.d.ts +1 -0
  46. package/dist/powered-file-system/stat.test.js +79 -0
  47. package/dist/powered-file-system/symlink.d.ts +4 -0
  48. package/dist/powered-file-system/symlink.js +52 -0
  49. package/dist/powered-file-system/symlink.test.d.ts +1 -0
  50. package/dist/powered-file-system/symlink.test.js +77 -0
  51. package/dist/powered-file-system/test.d.ts +8 -0
  52. package/dist/powered-file-system/test.js +30 -0
  53. package/dist/powered-file-system/test.test.d.ts +1 -0
  54. package/dist/powered-file-system/test.test.js +76 -0
  55. package/dist/powered-file-system/write.d.ts +10 -0
  56. package/dist/powered-file-system/write.js +36 -0
  57. package/dist/powered-file-system/write.test.d.ts +1 -0
  58. package/dist/powered-file-system/write.test.js +97 -0
  59. package/dist/{src/powered-file-system.d.ts → powered-file-system.d.ts} +57 -4
  60. package/dist/powered-file-system.js +144 -0
  61. package/dist/powered-file-system.test.d.ts +1 -0
  62. package/dist/powered-file-system.test.js +21 -0
  63. package/dist/recurse-io-sync.d.ts +20 -0
  64. package/dist/{src/recurse-io-sync.js → recurse-io-sync.js} +25 -23
  65. package/dist/{src/recurse-io.d.ts → recurse-io.d.ts} +15 -0
  66. package/dist/{src/recurse-io.js → recurse-io.js} +30 -28
  67. package/dist/suite.test.d.ts +1 -0
  68. package/dist/suite.test.js +40 -0
  69. package/dist/test-utils.d.ts +18 -0
  70. package/dist/test-utils.js +72 -0
  71. package/package.json +28 -11
  72. package/readme.md +331 -246
  73. package/.travis.yml +0 -12
  74. package/appveyor.yml +0 -16
  75. package/dist/src/bitmask.d.ts +0 -1
  76. package/dist/src/bitmask.js.map +0 -1
  77. package/dist/src/index.js.map +0 -1
  78. package/dist/src/powered-file-system.js +0 -252
  79. package/dist/src/powered-file-system.js.map +0 -1
  80. package/dist/src/recurse-io-sync.d.ts +0 -5
  81. package/dist/src/recurse-io-sync.js.map +0 -1
  82. package/dist/src/recurse-io.js.map +0 -1
  83. package/src/bitmask.ts +0 -13
  84. package/src/index.ts +0 -5
  85. package/src/powered-file-system.ts +0 -369
  86. package/src/recurse-io-sync.ts +0 -105
  87. package/src/recurse-io.ts +0 -221
  88. package/test/__fmock.ts +0 -45
  89. package/test/append.spec.ts +0 -45
  90. package/test/bitmask.spec.ts +0 -23
  91. package/test/chmod.spec.ts +0 -77
  92. package/test/chown.spec.ts +0 -92
  93. package/test/constructor.spec.ts +0 -15
  94. package/test/copy.spec.ts +0 -101
  95. package/test/mkdir.spec.ts +0 -121
  96. package/test/read.spec.ts +0 -91
  97. package/test/readdir.spec.ts +0 -86
  98. package/test/remove.spec.ts +0 -78
  99. package/test/rename.spec.ts +0 -84
  100. package/test/stat.spec.ts +0 -99
  101. package/test/symlink.spec.ts +0 -95
  102. package/test/test.spec.ts +0 -80
  103. package/test/write.spec.ts +0 -104
  104. package/tsconfig.json +0 -17
package/test/__fmock.ts DELETED
@@ -1,45 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- export interface Iframe {
5
- [key: string]: any
6
- }
7
-
8
- export function fmock(frame: Iframe) {
9
- for (const src of Object.keys(frame)) {
10
- const { dir } = path.parse(src);
11
- const value = frame[src];
12
-
13
- fs.mkdirSync(dir, { recursive: true });
14
-
15
- if (value.type === 'directory') {
16
- fs.mkdirSync(src);
17
- }
18
-
19
- if (value.type === 'file') {
20
- fs.writeFileSync(src, value.data);
21
- }
22
-
23
- if (value.type === 'symlink') {
24
- fs.symlinkSync(value.target, src);
25
- }
26
- }
27
- }
28
-
29
- export function restore(tmpDir: string) {
30
- const removeRecursive = (src: string) => {
31
- if (fs.existsSync(src)) {
32
- fs.readdirSync(src).forEach((item) => {
33
- const curl = `${src}/${item}`;
34
-
35
- fs.lstatSync(curl).isDirectory()
36
- ? removeRecursive(curl)
37
- : fs.unlinkSync(curl);
38
- });
39
-
40
- fs.rmdirSync(src);
41
- }
42
- };
43
-
44
- removeRecursive(tmpDir);
45
- }
@@ -1,45 +0,0 @@
1
- import assert from 'node:assert';
2
- import fs from 'node:fs';
3
- import Chance from 'chance';
4
- import { expect } from 'expect';
5
- import { fmock, restore } from './__fmock';
6
- import { pfs } from '../src';
7
-
8
- describe('append(src, data [, options])', () => {
9
- const chance = new Chance();
10
-
11
- beforeEach(() => {
12
- fmock({
13
- './tmpdir/tings.txt': {
14
- type: 'file',
15
- data: 'hoodie'
16
- }
17
- });
18
- });
19
-
20
- afterEach(() => {
21
- restore('./tmpdir');
22
- });
23
-
24
-
25
- it('Positive: Must append content to file', async () => {
26
- const payload = chance.paragraph();
27
-
28
- await pfs.append('./tmpdir/tings.txt', payload);
29
- const { size } = fs.statSync('./tmpdir/tings.txt');
30
-
31
- assert(payload.length + 6 === size);
32
- });
33
-
34
- it(`[sync] Positive: Must append content to file`, () => {
35
- const payload = chance.paragraph();
36
-
37
- pfs.append('./tmpdir/tings.txt', payload, {
38
- sync: true
39
- });
40
-
41
- const { size } = fs.statSync('./tmpdir/tings.txt');
42
-
43
- assert(payload.length + 6 === size);
44
- });
45
- });
@@ -1,23 +0,0 @@
1
- import assert from 'node:assert';
2
- import { bitmask } from '../src';
3
-
4
- describe('static bitmask(mode: number)', () => {
5
- it('Positive: Calculate bitmask', () => {
6
- assert(bitmask(33024) === 0o400); // (r--------)
7
- assert(bitmask(33152) === 0o600); // (rw-------)
8
- assert(bitmask(33216) === 0o700); // (rwx------)
9
- assert(bitmask(32800) === 0o040); // (---r-----)
10
- assert(bitmask(32816) === 0o060); // (---rw----)
11
- assert(bitmask(32824) === 0o070); // (---rwx---)
12
- assert(bitmask(32772) === 0o004); // (------r--)
13
- assert(bitmask(32774) === 0o006); // (------rw-)
14
- assert(bitmask(32775) === 0o007); // (------rwx)
15
- });
16
-
17
- it(`Negative: Throw an exception if the argument is 'null' type`, () => {
18
- assert.throws(() => {
19
- // @ts-ignore
20
- bitmask(null);
21
- });
22
- });
23
- });
@@ -1,77 +0,0 @@
1
- import assert from 'node:assert';
2
- import fs from 'node:fs';
3
- import Chance from 'chance';
4
- import { expect } from 'expect';
5
- import { fmock, restore } from './__fmock';
6
- import { pfs, bitmask } from '../src';
7
-
8
- describe('chmod(src, mode [, options])', () => {
9
- const chance = new Chance();
10
-
11
- beforeEach(() => {
12
- fmock({
13
- './tmpdir/tings.txt': {
14
- type: 'file',
15
- data: chance.string()
16
- }
17
- });
18
- });
19
-
20
- afterEach(() => {
21
- restore('./tmpdir');
22
- });
23
-
24
-
25
- it('Positive: Changes directory and file permissions', async () => {
26
- await pfs.chmod('./tmpdir', 0o744);
27
-
28
- const { mode } = fs.lstatSync('./tmpdir/tings.txt');
29
- const umask = bitmask(mode);
30
-
31
- assert(umask === 0o744);
32
- });
33
-
34
-
35
- it('Negative: Throw if not exists resource', async () => {
36
- await expect(async () => {
37
- await pfs.chmod('./non-existent-source', 0o744);
38
- })
39
- .rejects
40
- .toThrow();
41
- });
42
-
43
-
44
- it(`[sync] Positive: Changes permissions of directory`, () => {
45
- pfs.chmod('./tmpdir', 0o744, {
46
- sync: true
47
- });
48
-
49
- const { mode } = fs.lstatSync('./tmpdir');
50
- const umask = bitmask(mode);
51
-
52
- assert(umask === 0o744);
53
- });
54
-
55
-
56
- it(`[sync] Positive: Changes file permissions`, () => {
57
- pfs.chmod('./tmpdir', 0o744, {
58
- sync: true
59
- });
60
-
61
- const { mode } = fs.lstatSync('./tmpdir/tings.txt');
62
- const umask = bitmask(mode);
63
-
64
- assert(umask === 0o744);
65
- });
66
-
67
-
68
- it('[sync] Negative: Throw if not exists resource', () => {
69
- const guid = chance.guid();
70
-
71
- assert.throws(() => {
72
- pfs.chmod(`./${guid}`, 0o744, {
73
- sync: true
74
- });
75
- });
76
- });
77
- });
@@ -1,92 +0,0 @@
1
- import assert from 'node:assert';
2
- import fs from 'node:fs';
3
- import Chance from 'chance';
4
- import { expect } from 'expect';
5
- import { fmock, restore } from './__fmock';
6
- import { pfs } from '../src';
7
-
8
- describe('chown(src, [, options])', () => {
9
- const chance = new Chance();
10
-
11
- beforeEach(() => {
12
- fmock({
13
- './tmpdir/tings.txt': {
14
- type: 'file',
15
- data: chance.string()
16
- },
17
- './tmpdir/digest/': { type: 'directory' }
18
- });
19
- });
20
-
21
- afterEach(() => {
22
- restore('./tmpdir');
23
- });
24
-
25
-
26
- it('Positive: Changes the permissions of a file', async () => {
27
- const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
28
- await pfs.chown('./tmpdir/tings.txt', { uid, gid });
29
-
30
- assert(uid && gid);
31
- });
32
-
33
-
34
- it('Positive: Changes the permissions of a directory', async () => {
35
- const { uid, gid } = fs.statSync('./tmpdir/digest');
36
- await pfs.chown('./tmpdir/digest', { uid, gid });
37
-
38
- assert(uid && gid);
39
- });
40
-
41
-
42
- it('Negative: To a non-existent resource to return an Error', async () => {
43
- const guid = chance.guid();
44
- const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
45
-
46
- await expect(async () => {
47
- await pfs.chown(`./tmpdir/${guid}`, { uid, gid });
48
- })
49
- .rejects
50
- .toThrow();
51
- });
52
-
53
-
54
- it('[sync] Positive: Changes the permissions of a file', () => {
55
- const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
56
-
57
- pfs.chown('./tmpdir/tings.txt', {
58
- sync: true,
59
- uid,
60
- gid
61
- });
62
-
63
- assert(uid && gid);
64
- });
65
-
66
-
67
- it('[sync] Positive: Changes the permissions of a directory', () => {
68
- const { uid, gid } = fs.statSync('./tmpdir/digest');
69
-
70
- pfs.chown('./tmpdir/digest', {
71
- sync: true,
72
- uid,
73
- gid
74
- });
75
-
76
- assert(uid && gid);
77
- });
78
-
79
-
80
- it('[sync] Negative: To a non-existent resource to return an Error', () => {
81
- const guid = chance.guid();
82
- const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
83
-
84
- assert.throws(() => {
85
- pfs.chown(`./tmpdir/${guid}`, {
86
- sync: true,
87
- uid,
88
- gid
89
- });
90
- });
91
- });
92
- });
@@ -1,15 +0,0 @@
1
- import assert from 'node:assert';
2
- import { PoweredFileSystem } from '../src';
3
-
4
- describe('#constructor: new PoweredFileSystem(pwd?)', () => {
5
- it('Positive: An empty path must match the context of the cwd', () => {
6
- const { pwd } = new PoweredFileSystem();
7
- assert(pwd === process.cwd());
8
- });
9
-
10
-
11
- it('Positive: Absolute path must match the context of the pwd', () => {
12
- const { pwd } = new PoweredFileSystem(__dirname);
13
- assert(pwd === __dirname);
14
- });
15
- });
package/test/copy.spec.ts DELETED
@@ -1,101 +0,0 @@
1
- import assert from 'node:assert';
2
- import fs from 'node:fs';
3
- import Chance from 'chance';
4
- import { expect } from 'expect';
5
- import { fmock, restore } from './__fmock';
6
- import { pfs } from '../src';
7
-
8
- describe('copy(src, dir [, options])', () => {
9
- const chance = new Chance();
10
-
11
- beforeEach(() => {
12
- fmock({
13
- './tmpdir/tings.txt': {
14
- type: 'file',
15
- data: chance.string()
16
- },
17
- './tmpdir/digest/': { type: 'directory' }
18
- });
19
- });
20
-
21
- afterEach(() => {
22
- restore('./tmpdir');
23
- });
24
-
25
- it('Positive: Copying a item file', async () => {
26
- await pfs.copy('./tmpdir/tings.txt', './tmpdir/digest');
27
- const exist = fs.existsSync(`./tmpdir/digest/tings.txt`);
28
-
29
- assert(exist);
30
- });
31
-
32
-
33
- it('Positive: Recursive copying a directory', async () => {
34
- await pfs.copy('./src', './tmpdir');
35
- const exist = fs.existsSync(`./tmpdir/src`);
36
-
37
- assert(exist);
38
- });
39
-
40
-
41
- it('Negative: Throw if not exists resource', async () => {
42
- const guid = chance.guid();
43
-
44
- await expect(async () => {
45
- await pfs.copy(`./${guid}`, '.');
46
- })
47
- .rejects
48
- .toThrow();
49
- });
50
-
51
-
52
- it('Negative: An attempt to copy to an existing resource should return an Error', async () => {
53
- await expect(async () => {
54
- await pfs.copy('./tmpdir', '.');
55
- })
56
- .rejects
57
- .toThrow();
58
- });
59
-
60
-
61
- it('[sync] Positive: Copying a file', () => {
62
- pfs.copy('./tmpdir/tings.txt', './tmpdir/digest', {
63
- sync: true
64
- });
65
-
66
- const exist = fs.existsSync(`./tmpdir/digest/tings.txt`);
67
-
68
- assert(exist);
69
- });
70
-
71
-
72
- it('[sync] Positive: Recursive copying a directory', () => {
73
- pfs.copy('./src', './tmpdir', {
74
- sync: true
75
- });
76
-
77
- const exist = fs.existsSync(`./tmpdir/src`);
78
-
79
- assert(exist);
80
- });
81
-
82
-
83
- it('[sync] Negative: Throw if not exists resource', () => {
84
- const guid = chance.guid();
85
-
86
- assert.throws(() => {
87
- pfs.copy(`./${guid}`, '.', {
88
- sync: true
89
- });
90
- });
91
- });
92
-
93
-
94
- it('[sync] Negative: An attempt to copy to an existing resource should return an Error', () => {
95
- assert.throws(() => {
96
- pfs.copy('./tmpdir', '.', {
97
- sync: true
98
- });
99
- });
100
- });
101
- });
@@ -1,121 +0,0 @@
1
- import assert from 'node:assert';
2
- import fs from 'node:fs';
3
- import Chance from 'chance';
4
- import { expect } from 'expect';
5
- import { fmock, restore } from './__fmock';
6
- import { PoweredFileSystem } from '../src';
7
-
8
- describe('mkdir(src [, options])', () => {
9
- const pfs = new PoweredFileSystem();
10
- const chance = new Chance();
11
-
12
- beforeEach(() => {
13
- fmock({
14
- './tmpdir/tings.txt': {
15
- type: 'file',
16
- data: chance.string()
17
- }
18
- });
19
- });
20
-
21
- afterEach(() => {
22
- restore('./tmpdir');
23
- });
24
-
25
- it('Positive: Create directories in the working directory', async () => {
26
- const guid = chance.guid();
27
-
28
- await pfs.mkdir(`./tmpdir/${guid}`);
29
- const exist = fs.existsSync(`./tmpdir/${guid}`);
30
-
31
- assert(exist);
32
- });
33
-
34
-
35
- it(`Positive: Make current directory`, async () => {
36
- const guid = chance.guid();
37
- const pfs = new PoweredFileSystem(`./tmpdir/${guid}`);
38
-
39
- await pfs.mkdir('.');
40
- const exist = fs.existsSync(`./tmpdir/${guid}`);
41
-
42
- assert(exist);
43
- });
44
-
45
-
46
- it('Positive: Should work fine with the existing directory', async () => {
47
- const guid = chance.guid();
48
-
49
- for (let i = 2; i; i--) {
50
- await pfs.mkdir(`./tmpdir/${guid}`);
51
- }
52
-
53
- const exist = fs.existsSync(`./tmpdir/${guid}`);
54
-
55
- assert(exist);
56
- });
57
-
58
-
59
- it('Negative: Throw an exception if trying to create a directory in file', async () => {
60
- const guid = chance.guid();
61
-
62
- await expect(async () => {
63
- await pfs.mkdir(`./tmpdir/tings.txt/${guid}`);
64
- })
65
- .rejects
66
- .toThrow();
67
- });
68
-
69
-
70
- it('Positive: Create directories in the working directory', () => {
71
- const guid = chance.guid();
72
-
73
- pfs.mkdir(`./tmpdir/${guid}`, {
74
- sync: true
75
- });
76
-
77
- const exist = fs.existsSync(`./tmpdir/${guid}`);
78
-
79
- assert(exist);
80
- });
81
-
82
-
83
- it('[sync] Positive: Make current directory', () => {
84
- const guid = chance.guid();
85
- const pfs = new PoweredFileSystem(`./tmpdir/${guid}`);
86
-
87
- pfs.mkdir('.', {
88
- sync: true
89
- });
90
-
91
- const exist = fs.existsSync(`./tmpdir/${guid}`);
92
-
93
- assert(exist);
94
- });
95
-
96
-
97
- it('[sync] Positive: Should work fine with the existing directory', () => {
98
- const guid = chance.guid();
99
-
100
- for (let i = 2; i; i--) {
101
- pfs.mkdir(`./tmpdir/${guid}`, {
102
- sync: true
103
- });
104
- }
105
-
106
- const exist = fs.existsSync(`./tmpdir/${guid}`);
107
-
108
- assert(exist);
109
- });
110
-
111
-
112
- it('[sync] Negative: Throw an exception if trying to create a directory in file', () => {
113
- const guid = chance.guid();
114
-
115
- assert.throws(() => {
116
- pfs.mkdir(`./tmpdir/tings.txt/${guid}`, {
117
- sync: true
118
- });
119
- });
120
- });
121
- });
package/test/read.spec.ts DELETED
@@ -1,91 +0,0 @@
1
- import assert from 'node:assert';
2
- import Chance from 'chance';
3
- import { expect } from 'expect';
4
- import { fmock, restore } from './__fmock';
5
- import { pfs } from '../src';
6
-
7
- describe('read(src [, options])', () => {
8
- const chance = new Chance();
9
- let sentences = 0;
10
-
11
- beforeEach(() => {
12
- const tingsContent = chance.paragraph();
13
- sentences = tingsContent.length;
14
-
15
- fmock({
16
- './tmpdir/tings.txt': {
17
- type: 'file',
18
- data: tingsContent
19
- }
20
- });
21
- });
22
-
23
- afterEach(() => {
24
- restore('./tmpdir');
25
- });
26
-
27
- it('Positive: Must read content of file; String type by default', async () => {
28
- const { length } = await pfs.read('./tmpdir/tings.txt');
29
-
30
- assert(length === sentences);
31
- });
32
-
33
-
34
- it('Positive: Must read Buffer content of file when encoding is null', async () => {
35
- const buffer = await pfs.read('./tmpdir/tings.txt', {
36
- encoding: null
37
- });
38
-
39
- assert(buffer instanceof Buffer);
40
- });
41
-
42
-
43
- it('Negative: Throw if resource is not file', async () => {
44
- await expect(async () => {
45
- await pfs.read(`./tmpdir`);
46
- })
47
- .rejects
48
- .toThrow();
49
- });
50
-
51
-
52
- it('Negative: Throw if not exists resource', async () => {
53
- const guid = chance.guid();
54
-
55
- await expect(async () => {
56
- await pfs.read(`./tmpdir/${guid}`);
57
- })
58
- .rejects
59
- .toThrow();
60
- });
61
-
62
-
63
- it('[sync] Positive: Must read content of file; String type by default', () => {
64
- const { length } = pfs.read('./tmpdir/tings.txt', {
65
- sync: true
66
- });
67
-
68
- assert(length === sentences);
69
- });
70
-
71
-
72
- it('[sync] Positive: Must read Buffer content of file when encoding is null', () => {
73
- const buf = pfs.read('./tmpdir/tings.txt', {
74
- sync: true,
75
- encoding: null
76
- });
77
-
78
- assert(buf instanceof Buffer);
79
- });
80
-
81
-
82
- it(`[sync] Negative: Throw if not exists resource`, () => {
83
- const guid = chance.guid();
84
-
85
- assert.throws(() => {
86
- pfs.read(`./tmpdir/${guid}`, {
87
- sync: true
88
- });
89
- });
90
- });
91
- });
@@ -1,86 +0,0 @@
1
- import assert from 'node:assert';
2
- import Chance from 'chance';
3
- import { expect } from 'expect';
4
- import { Iframe, fmock, restore } from './__fmock';
5
- import { pfs } from '../src';
6
-
7
- describe('readdir(src[, options])', () => {
8
- const chance = new Chance();
9
- let counter = 0;
10
-
11
- beforeEach(() => {
12
- const frame: Iframe = {
13
- './tmpdir/tings.txt': {
14
- type: 'file',
15
- data: chance.string()
16
- }
17
- };
18
-
19
- counter = chance.natural({ max: 7 });
20
-
21
- for (let i = 0; i < counter; i++) {
22
- frame[`./tmpdir/${i}`] = { type: 'directory' };
23
- }
24
-
25
- fmock(frame);
26
- });
27
-
28
- afterEach(() => {
29
- restore('./tmpdir');
30
- });
31
-
32
- it('Positive: Must return a directory listing', async () => {
33
- const { length } = await pfs.readdir('./tmpdir');
34
-
35
- assert(counter + 1 === length);
36
- });
37
-
38
-
39
- it('Negative: Throw if resource is not directory', async () => {
40
- await expect(async () => {
41
- await pfs.readdir(`./tmpdir/tings.txt`);
42
- })
43
- .rejects
44
- .toThrow();
45
- });
46
-
47
-
48
- it('Negative: Throw if not exists resource', async () => {
49
- const guid = chance.guid();
50
-
51
- await expect(async () => {
52
- await pfs.readdir(`./tmpdir/${guid}`);
53
- })
54
- .rejects
55
- .toThrow();
56
- });
57
-
58
-
59
- it('[sync] Positive: Must return a directory listing', () => {
60
- const { length } = pfs.readdir('./tmpdir', {
61
- sync: true
62
- });
63
-
64
- assert(counter + 1 === length);
65
- });
66
-
67
-
68
- it('Negative: Throw if resource is not directory', () => {
69
- assert.throws(() => {
70
- pfs.readdir(`./tmpdir/tings.txt`, {
71
- sync: true
72
- });
73
- });
74
- });
75
-
76
-
77
- it(`Negative: Throw if not exists resource`, () => {
78
- const guid = chance.guid();
79
-
80
- assert.throws(() => {
81
- pfs.readdir(`./tmpdir/${guid}`, {
82
- sync: true
83
- });
84
- });
85
- });
86
- });