pwd-fs 2.4.2 → 3.1.4

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 (68) hide show
  1. package/.travis.yml +2 -3
  2. package/appveyor.yml +2 -4
  3. package/lib/src/index.d.ts +4 -186
  4. package/lib/src/index.js +18 -294
  5. package/lib/src/powered-file-system.d.ts +156 -0
  6. package/lib/src/powered-file-system.js +264 -0
  7. package/lib/src/recurse-io-sync.d.ts +10 -5
  8. package/lib/src/recurse-io-sync.js +74 -69
  9. package/lib/src/recurse-io.d.ts +14 -6
  10. package/lib/src/recurse-io.js +164 -160
  11. package/lib/test/__fmock.d.ts +5 -0
  12. package/lib/test/__fmock.js +40 -0
  13. package/lib/test/append.spec.js +36 -77
  14. package/lib/test/bitmask.spec.js +14 -17
  15. package/lib/test/chmod.spec.js +42 -84
  16. package/lib/test/chown.spec.js +45 -71
  17. package/lib/test/constructor.spec.js +7 -10
  18. package/lib/test/copy.spec.js +53 -108
  19. package/lib/test/mkdir.spec.js +62 -119
  20. package/lib/test/read.spec.js +47 -78
  21. package/lib/test/readdir.spec.js +48 -90
  22. package/lib/test/remove.spec.js +44 -65
  23. package/lib/test/rename.spec.js +43 -75
  24. package/lib/test/stat.spec.js +50 -78
  25. package/lib/test/symlink.spec.js +51 -95
  26. package/lib/test/test.spec.js +37 -66
  27. package/lib/test/write.spec.js +52 -103
  28. package/package.json +8 -11
  29. package/readme.md +10 -21
  30. package/src/index.ts +4 -623
  31. package/src/powered-file-system.ts +527 -0
  32. package/src/recurse-io-sync.ts +77 -71
  33. package/src/recurse-io.ts +181 -176
  34. package/test/__fmock.ts +45 -0
  35. package/test/append.spec.ts +44 -98
  36. package/test/bitmask.spec.ts +14 -17
  37. package/test/chmod.spec.ts +45 -95
  38. package/test/chown.spec.ts +61 -93
  39. package/test/constructor.spec.ts +4 -7
  40. package/test/copy.spec.ts +72 -142
  41. package/test/mkdir.spec.ts +87 -153
  42. package/test/read.spec.ts +64 -103
  43. package/test/readdir.spec.ts +65 -113
  44. package/test/remove.spec.ts +58 -82
  45. package/test/rename.spec.ts +58 -96
  46. package/test/stat.spec.ts +68 -100
  47. package/test/symlink.spec.ts +74 -125
  48. package/test/test.spec.ts +51 -84
  49. package/test/write.spec.ts +68 -131
  50. package/tsconfig.json +14 -7
  51. package/lib/src/index.js.map +0 -1
  52. package/lib/src/recurse-io-sync.js.map +0 -1
  53. package/lib/src/recurse-io.js.map +0 -1
  54. package/lib/test/append.spec.js.map +0 -1
  55. package/lib/test/bitmask.spec.js.map +0 -1
  56. package/lib/test/chmod.spec.js.map +0 -1
  57. package/lib/test/chown.spec.js.map +0 -1
  58. package/lib/test/constructor.spec.js.map +0 -1
  59. package/lib/test/copy.spec.js.map +0 -1
  60. package/lib/test/mkdir.spec.js.map +0 -1
  61. package/lib/test/read.spec.js.map +0 -1
  62. package/lib/test/readdir.spec.js.map +0 -1
  63. package/lib/test/remove.spec.js.map +0 -1
  64. package/lib/test/rename.spec.js.map +0 -1
  65. package/lib/test/stat.spec.js.map +0 -1
  66. package/lib/test/symlink.spec.js.map +0 -1
  67. package/lib/test/test.spec.js.map +0 -1
  68. package/lib/test/write.spec.js.map +0 -1
@@ -1,187 +1,121 @@
1
- import assert from 'assert';
2
- import os from 'os';
3
- import { sep } from 'path';
4
- import mockFs from 'mock-fs';
1
+ import assert from 'node:assert';
2
+ import fs from 'node:fs';
5
3
  import Chance from 'chance';
6
- import PoweredFileSystem from '../src';
4
+ import { expect } from 'expect';
5
+ import { fmock, restore } from './__fmock';
6
+ import { PoweredFileSystem } from '../src';
7
7
 
8
8
  describe('mkdir(src [, options])', () => {
9
- beforeEach(() => {
10
- const chance = new Chance();
9
+ const pfs = new PoweredFileSystem();
10
+ const chance = new Chance();
11
11
 
12
- mockFs({
13
- 'tmpdir': {
14
- 'binapp': chance.string(),
15
- 'libxbase': mockFs.directory()
16
- },
17
- 'flexapp': mockFs.symlink({
18
- path: 'tmpdir/binapp'
19
- })
12
+ beforeEach(() => {
13
+ fmock({
14
+ './tmpdir/tings.txt': {
15
+ type: 'file',
16
+ data: chance.string()
17
+ }
20
18
  });
21
19
  });
22
-
23
- afterEach(mockFs.restore);
20
+
21
+ afterEach(() => {
22
+ restore('./tmpdir');
23
+ });
24
24
 
25
25
  it('Positive: Create directories in the working directory', async () => {
26
- const pfs = new PoweredFileSystem();
27
- const chance = new Chance();
28
-
29
- const base = chance.guid();
30
- await pfs.mkdir(`./tmpdir/${base}`);
31
-
32
- const exist = await pfs.test(`./tmpdir/${base}`);
26
+ const guid = chance.guid();
27
+
28
+ await pfs.mkdir(`./tmpdir/${guid}`);
29
+ const exist = fs.existsSync(`./tmpdir/${guid}`);
30
+
33
31
  assert(exist);
34
32
  });
35
-
33
+
34
+
36
35
  it(`Positive: Make current directory`, async () => {
37
- const pfs = new PoweredFileSystem('./tmpdir');
36
+ const guid = chance.guid();
37
+ const pfs = new PoweredFileSystem(`./tmpdir/${guid}`);
38
38
 
39
39
  await pfs.mkdir('.');
40
-
41
- const exist = await pfs.test('.');
42
- assert(exist);
43
- });
44
-
45
- it(`Positive: Make current directory, when current directory is absolute path`, async () => {
46
- const pfs = new PoweredFileSystem('./tmpdir');
47
-
48
- await pfs.mkdir(process.cwd());
49
-
50
- const exist = await pfs.test('.');
40
+ const exist = fs.existsSync(`./tmpdir/${guid}`);
41
+
51
42
  assert(exist);
52
43
  });
53
-
44
+
45
+
54
46
  it('Positive: Should work fine with the existing directory', async () => {
55
- const pfs = new PoweredFileSystem();
56
- const chance = new Chance();
57
-
58
- const base = chance.guid();
47
+ const guid = chance.guid();
59
48
 
60
- for (const item of [base, base]) {
61
- await pfs.mkdir(`./tmpdir/${item}`);
62
-
63
- const exist = await pfs.test(`./tmpdir/${item}`);
64
- assert(exist);
49
+ for (let i = 2; i; i--) {
50
+ await pfs.mkdir(`./tmpdir/${guid}`);
65
51
  }
52
+
53
+ const exist = fs.existsSync(`./tmpdir/${guid}`);
54
+
55
+ assert(exist);
66
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();
67
72
 
68
- it('Positive: Create directories when path is absolute', async () => {
69
- const pfs = new PoweredFileSystem();
70
- const chance = new Chance();
71
-
72
- const tmpdir = os.tmpdir();
73
- const base = chance.guid();
74
-
75
- await pfs.mkdir(`${tmpdir}${sep}${base}`, {
76
- resolve: false
73
+ pfs.mkdir(`./tmpdir/${guid}`, {
74
+ sync: true
77
75
  });
78
76
 
79
- const exist = await pfs.test(`${tmpdir}${sep}${base}`);
77
+ const exist = fs.existsSync(`./tmpdir/${guid}`);
78
+
80
79
  assert(exist);
81
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
+ });
82
90
 
83
- it('Negative: Throw an exception if trying to create a directory in file', async () => {
84
- const pfs = new PoweredFileSystem();
85
- const chance = new Chance();
86
-
87
- const base = chance.guid();
88
-
89
- try {
90
- await pfs.mkdir(`./tmpdir/binapp/${base}`);
91
- }
92
- catch (err) {
93
- assert(err.errno === -20);
94
- }
91
+ const exist = fs.existsSync(`./tmpdir/${guid}`);
92
+
93
+ assert(exist);
95
94
  });
95
+
96
+
97
+ it('[sync] Positive: Should work fine with the existing directory', () => {
98
+ const guid = chance.guid();
96
99
 
97
- describe('sync mode', () => {
98
- it('Positive: Create directories in the working directory', async () => {
99
- const pfs = new PoweredFileSystem();
100
- const chance = new Chance();
101
-
102
- const base = chance.guid();
103
-
104
- pfs.mkdir(`./tmpdir/${base}`, {
100
+ for (let i = 2; i; i--) {
101
+ pfs.mkdir(`./tmpdir/${guid}`, {
105
102
  sync: true
106
103
  });
107
-
108
- const exist = await pfs.test(`./tmpdir/${base}`);
109
- assert(exist);
110
- });
111
-
112
- it('Positive: Make current directory', async () => {
113
- const pfs = new PoweredFileSystem('./tmpdir');
114
-
115
- pfs.mkdir('.', {
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}`, {
116
117
  sync: true
117
118
  });
118
-
119
- const exist = await pfs.test('.');
120
- assert(exist);
121
- });
122
-
123
- it('Positive: Should work fine with the existing directory', async () => {
124
- const pfs = new PoweredFileSystem();
125
- const chance = new Chance();
126
-
127
- const base = chance.guid();
128
-
129
- for (const item of [base, base]) {
130
- pfs.mkdir(`./tmpdir/${item}`, {
131
- sync: true
132
- });
133
-
134
- const exist = await pfs.test(`./tmpdir/${item}`);
135
- assert(exist);
136
- }
137
- });
138
-
139
- it('Positive: Create directories when path is absolute', async () => {
140
- const pfs = new PoweredFileSystem();
141
- const chance = new Chance();
142
-
143
- const tmpdir = os.tmpdir();
144
- const base = chance.guid();
145
-
146
- pfs.mkdir(`${tmpdir}${sep}${base}`, {
147
- sync: true,
148
- resolve: false
149
- });
150
-
151
- const exist = await pfs.test(`${tmpdir}${sep}${base}`);
152
- assert(exist);
153
- });
154
-
155
- it('Positive: Create in current directories when path is absolute', async () => {
156
- const pfs = new PoweredFileSystem();
157
- const chance = new Chance();
158
-
159
- const cwd = process.cwd();
160
- const base = chance.guid();
161
-
162
- pfs.mkdir(`${cwd}${sep}${base}`, {
163
- sync: true,
164
- resolve: false
165
- });
166
-
167
- const exist = await pfs.test(base);
168
- assert(exist);
169
- });
170
-
171
- it('Negative: Throw an exception if trying to create a directory in file', async () => {
172
- const pfs = new PoweredFileSystem();
173
- const chance = new Chance();
174
-
175
- const base = chance.guid();
176
-
177
- try {
178
- pfs.mkdir(`./tmpdir/binapp/${base}`, {
179
- sync: true
180
- });
181
- }
182
- catch (err) {
183
- assert(err.errno === -20);
184
- }
185
119
  });
186
120
  });
187
121
  });
package/test/read.spec.ts CHANGED
@@ -1,130 +1,91 @@
1
- import assert from 'assert';
2
- import { sep } from 'path';
3
- import mockFs from 'mock-fs';
1
+ import assert from 'node:assert';
4
2
  import Chance from 'chance';
5
- import PoweredFileSystem from '../src';
3
+ import { expect } from 'expect';
4
+ import { fmock, restore } from './__fmock';
5
+ import { pfs } from '../src';
6
6
 
7
7
  describe('read(src [, options])', () => {
8
- beforeEach(() => {
9
- const chance = new Chance();
8
+ const chance = new Chance();
9
+ let sentences = 0;
10
10
 
11
- mockFs({
12
- 'tmpdir': {
13
- 'binapp': chance.string(),
14
- 'libxbase': mockFs.directory()
15
- },
16
- 'flexapp': mockFs.symlink({
17
- path: 'tmpdir/binapp'
18
- })
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
+ }
19
20
  });
20
21
  });
21
-
22
- afterEach(mockFs.restore);
23
-
22
+
23
+ afterEach(() => {
24
+ restore('./tmpdir');
25
+ });
26
+
24
27
  it('Positive: Must read content of file; String type by default', async () => {
25
- const pfs = new PoweredFileSystem();
26
-
27
- const raw = await pfs.read('./tmpdir/binapp');
28
+ const { length } = await pfs.read('./tmpdir/tings.txt');
28
29
 
29
- assert(raw.length > 0);
30
+ assert(length === sentences);
30
31
  });
31
-
32
+
33
+
32
34
  it('Positive: Must read Buffer content of file when encoding is null', async () => {
33
- const pfs = new PoweredFileSystem();
34
-
35
- const raw = await pfs.read('./tmpdir/binapp', {
35
+ const buffer = await pfs.read('./tmpdir/tings.txt', {
36
36
  encoding: null
37
37
  });
38
38
 
39
- assert(raw instanceof Buffer);
40
- });
41
-
42
- it('Positive: Must read content of file, when path is absolute', async () => {
43
- const pfs = new PoweredFileSystem();
44
-
45
- const cwd = process.cwd();
46
-
47
- const raw = await pfs.read(`${cwd}${sep}tmpdir${sep}binapp`, {
48
- resolve: false
49
- });
50
-
51
- assert(raw.length > 0);
39
+ assert(buffer instanceof Buffer);
52
40
  });
53
-
41
+
42
+
54
43
  it('Negative: Throw if resource is not file', async () => {
55
- const pfs = new PoweredFileSystem();
56
-
57
- try {
58
- await pfs.read(`./tmpdir/libxbase`);
59
- }
60
- catch (err) {
61
- assert(err.errno === -21);
62
- }
44
+ await expect(async () => {
45
+ await pfs.read(`./tmpdir`);
46
+ })
47
+ .rejects
48
+ .toThrow();
63
49
  });
64
-
50
+
51
+
65
52
  it('Negative: Throw if not exists resource', async () => {
66
- const pfs = new PoweredFileSystem();
67
- const chance = new Chance();
53
+ const guid = chance.guid();
68
54
 
69
- const base = chance.guid();
70
-
71
- try {
72
- await pfs.read(`./${base}`);
73
- }
74
- catch (err) {
75
- assert(err.errno === -2);
76
- }
55
+ await expect(async () => {
56
+ await pfs.read(`./tmpdir/${guid}`);
57
+ })
58
+ .rejects
59
+ .toThrow();
77
60
  });
78
-
79
- describe('sync mode', () => {
80
- it('Positive: Must read content of file; String type by default', async () => {
81
- const pfs = new PoweredFileSystem();
82
-
83
- const { length } = pfs.read('./tmpdir/binapp', {
84
- sync: true
85
- });
86
-
87
- assert(length > 0);
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
88
66
  });
89
67
 
90
- it('Positive: Must read Buffer content of file when encoding is null', async () => {
91
- const pfs = new PoweredFileSystem();
92
-
93
- const raw = pfs.read('./tmpdir/binapp', {
94
- encoding: null,
95
- sync: true
96
- });
97
-
98
- assert(raw instanceof Buffer);
68
+ assert(length === sentences);
69
+ });
70
+
71
+
72
+ it('[sync] Positive: Must read Buffer content of file when encoding is null', () => {
73
+ const buffer = pfs.read('./tmpdir/tings.txt', {
74
+ encoding: null,
75
+ sync: true
99
76
  });
100
77
 
101
- it('Positive: Must read content of file, when path is absolute', async () => {
102
- const pfs = new PoweredFileSystem();
103
-
104
- const cwd = process.cwd();
105
-
106
- const { length } = pfs.read(`${cwd}${sep}tmpdir${sep}binapp`, {
107
- sync: true,
108
- resolve: false
78
+ assert(buffer 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
109
88
  });
110
-
111
- assert(length > 0);
112
- });
113
-
114
- it(`Negative: Throw if not exists resource`, async () => {
115
- const pfs = new PoweredFileSystem();
116
- const chance = new Chance();
117
-
118
- const base = chance.guid();
119
-
120
- try {
121
- pfs.read(`./${base}`, {
122
- sync: true
123
- });
124
- }
125
- catch (err) {
126
- assert(err.errno === -2);
127
- }
128
89
  });
129
90
  });
130
91
  });
@@ -1,134 +1,86 @@
1
- import assert from 'assert';
2
- import { sep } from 'path';
3
- import mockFs from 'mock-fs';
1
+ import assert from 'node:assert';
4
2
  import Chance from 'chance';
5
- import PoweredFileSystem from '../src';
3
+ import { expect } from 'expect';
4
+ import { Iframe, fmock, restore } from './__fmock';
5
+ import { pfs } from '../src';
6
6
 
7
7
  describe('readdir(src[, options])', () => {
8
- beforeEach(() => {
9
- const chance = new Chance();
8
+ const chance = new Chance();
9
+ let counter = 0;
10
10
 
11
- mockFs({
12
- 'tmpdir': {
13
- 'binapp': chance.string(),
14
- 'libxbase': mockFs.directory()
15
- },
16
- 'flexapp': mockFs.symlink({
17
- path: 'tmpdir/binapp'
18
- })
19
- });
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);
20
26
  });
21
-
22
- afterEach(mockFs.restore);
23
-
24
- it('Positive: Must return a directory listing', async () => {
25
- const pfs = new PoweredFileSystem();
26
-
27
- const listOfFiles = await pfs.readdir('./tmpdir');
28
-
29
- assert.deepStrictEqual(listOfFiles, [
30
- 'binapp',
31
- 'libxbase'
32
- ]);
27
+
28
+ afterEach(() => {
29
+ restore('./tmpdir');
33
30
  });
34
31
 
35
- it('Positive: Must return a directory listing, when path is absolute', async () => {
36
- const pfs = new PoweredFileSystem();
37
-
38
- const cwd = process.cwd();
39
-
40
- const listOfFiles = await pfs.readdir(`${cwd}${sep}tmpdir`, {
41
- resolve: false
42
- });
32
+ it('Positive: Must return a directory listing', async () => {
33
+ const { length } = await pfs.readdir('./tmpdir');
43
34
 
44
- assert.deepStrictEqual(listOfFiles, [
45
- 'binapp',
46
- 'libxbase'
47
- ]);
35
+ assert(counter + 1 === length);
48
36
  });
49
-
37
+
38
+
50
39
  it('Negative: Throw if resource is not directory', async () => {
51
- const pfs = new PoweredFileSystem();
52
-
53
- try {
54
- await pfs.readdir(`./tmpdir/binapp`);
55
- }
56
- catch (err) {
57
- assert(err.errno === -20);
58
- }
40
+ await expect(async () => {
41
+ await pfs.readdir(`./tmpdir/tings.txt`);
42
+ })
43
+ .rejects
44
+ .toThrow();
59
45
  });
60
-
46
+
47
+
61
48
  it('Negative: Throw if not exists resource', async () => {
62
- const pfs = new PoweredFileSystem();
63
- const chance = new Chance();
64
-
65
- const base = chance.guid();
66
-
67
- try {
68
- await pfs.readdir(`./${base}`);
69
- }
70
- catch (err) {
71
- assert(err.errno === -2);
72
- }
49
+ const guid = chance.guid();
50
+
51
+ await expect(async () => {
52
+ await pfs.readdir(`./tmpdir/${guid}`);
53
+ })
54
+ .rejects
55
+ .toThrow();
73
56
  });
57
+
58
+
59
+ it('[sync] Positive: Must return a directory listing', () => {
60
+ const { length } = pfs.readdir('./tmpdir', {
61
+ sync: true
62
+ });
74
63
 
75
- describe('sync mode', () => {
76
- it('Positive: Must return a directory listing', async () => {
77
- const pfs = new PoweredFileSystem();
78
-
79
- const listOfFiles = pfs.readdir('./tmpdir', {
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`, {
80
71
  sync: true
81
72
  });
82
-
83
- assert.deepStrictEqual(listOfFiles, [
84
- 'binapp',
85
- 'libxbase'
86
- ]);
87
73
  });
88
-
89
- it('Positive: Must return a directory listing, when path is absolute', async () => {
90
- const pfs = new PoweredFileSystem();
91
-
92
- const cwd = process.cwd();
93
-
94
- const listOfFiles = pfs.readdir(`${cwd}${sep}tmpdir`, {
95
- sync: true,
96
- resolve: false
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
97
83
  });
98
-
99
- assert.deepStrictEqual(listOfFiles, [
100
- 'binapp',
101
- 'libxbase'
102
- ]);
103
- });
104
-
105
- it('Negative: Throw if resource is not directory', async () => {
106
- const pfs = new PoweredFileSystem();
107
-
108
- try {
109
- pfs.readdir(`./tmpdir/binapp`, {
110
- sync: true
111
- });
112
- }
113
- catch (err) {
114
- assert(err.errno === -20);
115
- }
116
- });
117
-
118
- it(`Negative: Throw if not exists resource`, async () => {
119
- const pfs = new PoweredFileSystem();
120
- const chance = new Chance();
121
-
122
- const base = chance.guid();
123
-
124
- try {
125
- pfs.readdir(`./${base}`, {
126
- sync: true
127
- });
128
- }
129
- catch (err) {
130
- assert(err.errno === -2);
131
- }
132
84
  });
133
85
  });
134
86
  });