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,102 +1,78 @@
1
- import assert from 'assert';
2
- import { sep } from 'path';
3
- import mockFs from 'mock-fs';
1
+ import assert from 'node:assert';
2
+ import fs from 'node:fs';
4
3
  import Chance from 'chance';
5
- import PoweredFileSystem from '../src';
4
+ import { expect } from 'expect';
5
+ import { Iframe, fmock, restore } from './__fmock';
6
+ import { pfs } from '../src';
6
7
 
7
8
  describe('remove(src [, options])', () => {
9
+ const chance = new Chance();
10
+
8
11
  beforeEach(() => {
9
- const chance = new Chance();
10
-
11
- mockFs({
12
- 'tmpdir': {
13
- 'binapp': chance.string(),
14
- 'libxbase': mockFs.directory()
12
+ const cwd = process.cwd();
13
+
14
+ const frame: Iframe = {
15
+ './tmpdir/tings.txt': {
16
+ type: 'file',
17
+ data: chance.string()
15
18
  },
16
- 'flexapp': mockFs.symlink({
17
- path: 'tmpdir/binapp'
18
- })
19
- });
19
+ './tmpdir/flexapp': {
20
+ type: 'symlink',
21
+ target: `${cwd}/tmpdir/tings.txt`
22
+ }
23
+ };
24
+
25
+ const counter = chance.natural({ max: 7 });
26
+
27
+ for (let i = 0; i < counter; i++) {
28
+ frame[`./tmpdir/${i}`] = { type: 'directory' };
29
+ }
30
+
31
+ fmock(frame);
20
32
  });
21
-
22
- afterEach(mockFs.restore);
23
-
33
+
34
+ afterEach(() => {
35
+ restore('./tmpdir');
36
+ });
37
+
38
+
24
39
  it('Positive: Removal a directory with a file', async () => {
25
- const pfs = new PoweredFileSystem();
26
-
27
40
  await pfs.remove('./tmpdir');
28
-
29
- const exist = await pfs.test('./tmpdir');
41
+ const exist = fs.existsSync(`./tmpdir`);
42
+
30
43
  assert(exist === false);
31
44
  });
32
-
33
- it('Positive: Removal a directory with a file, when path is absolute', async () => {
34
- const pfs = new PoweredFileSystem();
35
-
36
- const cwd = process.cwd();
37
-
38
- await pfs.remove(`${cwd}${sep}tmpdir`, {
39
- resolve: false
45
+
46
+
47
+ it('Negative: Throw if not exists resource', async () => {
48
+ const guid = chance.guid();
49
+
50
+ await expect(async () => {
51
+ await pfs.remove(`./${guid}`);
52
+ })
53
+ .rejects
54
+ .toThrow();
55
+ });
56
+
57
+
58
+ it('[sync] Positive: Removal a directory with a file', () => {
59
+ pfs.remove('./tmpdir', {
60
+ sync: true
40
61
  });
41
62
 
42
- const exist = await pfs.test('./tmpdir');
63
+ const exist = fs.existsSync(`./tmpdir`);
64
+
43
65
  assert(exist === false);
44
66
  });
67
+
68
+
69
+ it('[sync] Negative: Throw if not exists resource', () => {
70
+ const guid = chance.guid();
45
71
 
46
- it('Negative: Throw if not exists resource', async () => {
47
- const pfs = new PoweredFileSystem();
48
- const chance = new Chance();
49
-
50
- const base = chance.guid();
51
-
52
- try {
53
- await pfs.remove(`./${base}`);
54
- }
55
- catch (err) {
56
- assert(err.errno === -2);
57
- }
58
- });
59
-
60
- describe('sync mode', () => {
61
- it('Positive: Removal a directory with a file', async () => {
62
- const pfs = new PoweredFileSystem();
63
-
64
- pfs.remove('./tmpdir', {
72
+ assert.throws(() => {
73
+ pfs.remove(`./tmpdir/${guid}`, {
65
74
  sync: true
66
75
  });
67
-
68
- const exist = await pfs.test('./tmpdir');
69
- assert(exist === false);
70
- });
71
-
72
- it('Positive: Removal a directory with a file, when path is absolute', async () => {
73
- const pfs = new PoweredFileSystem();
74
-
75
- const cwd = process.cwd();
76
-
77
- pfs.remove(`${cwd}${sep}tmpdir`, {
78
- sync: true,
79
- resolve: false
80
- });
81
-
82
- const exist = await pfs.test('./tmpdir');
83
- assert(exist === false);
84
- });
85
-
86
- it('Negative: Throw if not exists resource', async () => {
87
- const pfs = new PoweredFileSystem();
88
- const chance = new Chance();
89
-
90
- const base = chance.guid();
91
-
92
- try {
93
- pfs.remove(`./${base}`, {
94
- sync: true
95
- });
96
- }
97
- catch (err) {
98
- assert(err.errno === -2);
99
- }
100
76
  });
101
77
  });
102
78
  });
@@ -1,122 +1,84 @@
1
- import assert from 'assert';
2
- import { sep } from 'path';
3
- import mockFs from 'mock-fs';
1
+ import assert from 'node:assert';
2
+ import fs from 'node:fs';
4
3
  import Chance from 'chance';
5
- import PoweredFileSystem from '../src';
4
+ import { expect } from 'expect';
5
+ import { fmock, restore } from './__fmock';
6
+ import {pfs } from '../src';
6
7
 
7
8
  describe('rename(src, use [, options])', () => {
8
- beforeEach(() => {
9
- const chance = new Chance();
9
+ const chance = new Chance();
10
10
 
11
- mockFs({
12
- 'tmpdir': {
13
- 'binapp': chance.string(),
14
- 'libxbase': mockFs.directory()
11
+ beforeEach(() => {
12
+ fmock({
13
+ './tmpdir/tings.txt': {
14
+ type: 'file',
15
+ data: chance.string()
15
16
  },
16
- 'flexapp': mockFs.symlink({
17
- path: 'tmpdir/binapp'
18
- })
17
+ './tmpdir/digest/': { type: 'directory' }
19
18
  });
20
19
  });
20
+
21
+ afterEach(() => {
22
+ restore('./tmpdir');
23
+ });
21
24
 
22
- afterEach(mockFs.restore);
23
25
 
24
26
  it('Positive: Must be recursive rename file', async () => {
25
- const pfs = new PoweredFileSystem();
26
-
27
- await pfs.rename('./tmpdir/binapp', './tmpdir/newapp');
28
- const exist = await pfs.test('./tmpdir/newapp');
29
-
27
+ await pfs.rename('./tmpdir/tings.txt', './tmpdir/newapp.txt');
28
+ const exist = fs.existsSync(`./tmpdir/newapp.txt`);
29
+
30
30
  assert(exist);
31
31
  });
32
-
32
+
33
+
33
34
  it('Positive: Must be recursive rename directory', async () => {
34
- const pfs = new PoweredFileSystem();
35
-
36
- await pfs.rename('./tmpdir/libxbase', './tmpdir/newxbase');
37
- const exist = await pfs.test('./tmpdir/newxbase');
38
-
35
+ await pfs.rename('./tmpdir/digest', './tmpdir/newxbase');
36
+ const exist = fs.existsSync(`./tmpdir/newxbase`);
37
+
39
38
  assert(exist);
40
39
  });
41
-
42
- it('Positive: Must be recursive rename directory, when path is absolute', async () => {
43
- const pfs = new PoweredFileSystem();
44
-
45
- const cwd = process.cwd();
46
-
47
- await pfs.rename(`${cwd}${sep}tmpdir`, `${cwd}${sep}newxbase`, {
48
- resolve: false
40
+
41
+
42
+ it('Negative: Throw if not exists resource', async () => {
43
+ const guid = chance.guid();
44
+
45
+ await expect(async () => {
46
+ await pfs.rename(`./tmpdir/${guid}`, './tmpdir/newxbase');
47
+ })
48
+ .rejects
49
+ .toThrow();
50
+ });
51
+
52
+
53
+ it('[sync] Positive: Must be recursive rename file', () => {
54
+ pfs.rename('./tmpdir/tings.txt', './tmpdir/newapp.txt', {
55
+ sync: true
49
56
  });
50
57
 
51
- const exist = await pfs.test('./newxbase');
58
+ const exist = fs.existsSync(`./tmpdir/newapp.txt`);
59
+
52
60
  assert(exist);
53
61
  });
54
-
55
- it('Negative: Throw if not exists resource', async () => {
56
- const pfs = new PoweredFileSystem();
57
- const chance = new Chance();
58
-
59
- const base = chance.guid();
60
-
61
- try {
62
- await pfs.rename(`./${base}`, './tmpdir/newapp');
63
- }
64
- catch (err) {
65
- assert(err.errno === -2);
66
- }
67
- });
68
-
69
- describe('sync mode', () => {
70
- it('Positive: Must be recursive rename file', async () => {
71
- const pfs = new PoweredFileSystem();
72
-
73
- pfs.rename('./tmpdir/binapp', './tmpdir/newapp', {
74
- sync: true
75
- });
76
-
77
- const exist = await pfs.test('./tmpdir/newapp');
78
- assert(exist);
62
+
63
+
64
+ it('[sync] Positive: Must be recursive rename directory', () => {
65
+ pfs.rename('./tmpdir/digest', './tmpdir/newxbase', {
66
+ sync: true
79
67
  });
80
68
 
81
- it('Positive: Must be recursive rename directory', async () => {
82
- const pfs = new PoweredFileSystem();
83
-
84
- pfs.rename('./tmpdir/libxbase', './tmpdir/newxbase', {
69
+ const exist = fs.existsSync(`./tmpdir/newxbase`);
70
+
71
+ assert(exist);
72
+ });
73
+
74
+
75
+ it('[sync] Negative: Throw if not exists resource', () => {
76
+ const guid = chance.guid();
77
+
78
+ assert.throws(() => {
79
+ pfs.rename(`./tmpdir/${guid}`, './tmpdir/newxbase', {
85
80
  sync: true
86
81
  });
87
-
88
- const exist = await pfs.test('./tmpdir/newxbase');
89
- assert(exist);
90
- });
91
-
92
- it('Positive: Must be recursive rename directory, when path is absolute', async () => {
93
- const pfs = new PoweredFileSystem();
94
-
95
- const cwd = process.cwd();
96
-
97
- pfs.rename(`${cwd}${sep}tmpdir`, `${cwd}${sep}newxbase`, {
98
- sync: true,
99
- resolve: false
100
- });
101
-
102
- const exist = await pfs.test('./newxbase');
103
- assert(exist);
104
- });
105
-
106
- it('Negative: Throw if not exists resource', async () => {
107
- const pfs = new PoweredFileSystem();
108
- const chance = new Chance();
109
-
110
- const base = chance.guid();
111
-
112
- try {
113
- pfs.rename(`./${base}`, './tmpdir/newapp', {
114
- sync: true
115
- });
116
- }
117
- catch (err) {
118
- assert(err.errno === -2);
119
- }
120
82
  });
121
83
  });
122
84
  });
package/test/stat.spec.ts CHANGED
@@ -1,131 +1,99 @@
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('stat(src [, options])', () => {
8
- beforeEach(() => {
9
- const chance = new Chance();
8
+ const chance = new Chance();
10
9
 
11
- mockFs({
12
- 'tmpdir': {
13
- 'binapp': chance.string(),
14
- 'libxbase': mockFs.directory()
10
+ beforeEach(() => {
11
+ const cwd = process.cwd();
12
+
13
+ fmock({
14
+ './tmpdir/tings.txt': {
15
+ type: 'file',
16
+ data: chance.string()
15
17
  },
16
- 'flexapp': mockFs.symlink({
17
- path: 'tmpdir/binapp'
18
- })
18
+ './tmpdir/digest/': { type: 'directory' },
19
+ './tmpdir/flexapp': {
20
+ type: 'symlink',
21
+ target: `${cwd}/tmpdir/tings.txt`
22
+ }
19
23
  });
20
24
  });
25
+
26
+ afterEach(() => {
27
+ restore('./tmpdir');
28
+ });
21
29
 
22
- afterEach(mockFs.restore);
23
30
 
24
31
  it('Positive: Must return information a file', async () => {
25
- const pfs = new PoweredFileSystem();
26
-
27
- const stats = await pfs.stat('./tmpdir/binapp');
32
+ const stats = await pfs.stat('./tmpdir/tings.txt');
33
+
28
34
  assert(stats.isFile());
29
35
  });
30
-
36
+
37
+
31
38
  it('Positive: Must return information a directory', async () => {
32
- const pfs = new PoweredFileSystem();
33
-
34
- const stats = await pfs.stat('./tmpdir/libxbase');
39
+ const stats = await pfs.stat('./tmpdir/digest');
40
+
35
41
  assert(stats.isDirectory());
36
42
  });
37
-
43
+
44
+
38
45
  it('Positive: Must return information a symlink', async () => {
39
- const pfs = new PoweredFileSystem();
40
-
41
- const stats = await pfs.stat('./flexapp');
46
+ const stats = await pfs.stat('./tmpdir/flexapp');
47
+
42
48
  assert(stats.isSymbolicLink());
43
49
  });
44
-
45
- it('Positive: Must return stats information, when path is absolute', async () => {
46
- const pfs = new PoweredFileSystem();
47
-
48
- const cwd = process.cwd();
49
-
50
- const stats = await pfs.stat(`${cwd}${sep}tmpdir`, {
51
- resolve: false
52
- });
53
-
54
- assert(stats.isDirectory());
55
- });
56
-
50
+
51
+
57
52
  it('Negative: Throw if not exists resource', async () => {
58
- const pfs = new PoweredFileSystem();
59
- const chance = new Chance();
53
+ const guid = chance.guid();
60
54
 
61
- const base = chance.guid();
62
-
63
- try {
64
- await pfs.stat(`./${base}`);
65
- }
66
- catch (err) {
67
- assert(err.errno === -2);
68
- }
55
+ await expect(async () => {
56
+ await pfs.stat(`./tmpdir/${guid}`);
57
+ })
58
+ .rejects
59
+ .toThrow();
69
60
  });
70
-
71
- describe('sync mode', () => {
72
- it('Positive: Must return information a file', async () => {
73
- const pfs = new PoweredFileSystem();
74
-
75
- const stats = pfs.stat('./tmpdir/binapp', {
76
- sync: true
77
- });
78
-
79
- assert(stats.isFile());
61
+
62
+
63
+ it('[sync] Positive: Must return information a file', () => {
64
+ const stats = pfs.stat('./tmpdir/tings.txt', {
65
+ sync: true
80
66
  });
81
67
 
82
- it('Positive: Must return information a directory in ', async () => {
83
- const pfs = new PoweredFileSystem();
84
-
85
- const stats = pfs.stat('./tmpdir/libxbase', {
86
- sync: true
87
- });
88
-
89
- assert(stats.isDirectory());
68
+ assert(stats.isFile());
69
+ });
70
+
71
+
72
+ it('[sync] Positive: Must return information a directory in ', () => {
73
+ const stats = pfs.stat('./tmpdir/digest', {
74
+ sync: true
90
75
  });
91
76
 
92
- it('Positive: Must return information a symlink', async () => {
93
- const pfs = new PoweredFileSystem();
94
-
95
- const stats = pfs.stat('./flexapp', {
96
- sync: true
97
- });
98
-
99
- assert(stats.isSymbolicLink());
77
+ assert(stats.isDirectory());
78
+ });
79
+
80
+
81
+ it('[sync] Positive: Must return information a symlink', () => {
82
+ const stats = pfs.stat('./tmpdir/flexapp', {
83
+ sync: true
100
84
  });
101
85
 
102
- it('Positive: Must return stats information, when path is absolute', async () => {
103
- const pfs = new PoweredFileSystem();
104
-
105
- const cwd = process.cwd();
106
-
107
- const stats = pfs.stat(`${cwd}${sep}tmpdir`, {
108
- sync: true,
109
- resolve: false
86
+ assert(stats.isSymbolicLink());
87
+ });
88
+
89
+
90
+ it('[sync] Negative: Throw if not exists resource', () => {
91
+ const guid = chance.guid();
92
+
93
+ assert.throws(() => {
94
+ pfs.stat(`./tmpdir/${guid}`, {
95
+ sync: true
110
96
  });
111
-
112
- assert(stats.isDirectory());
113
- });
114
-
115
- it('Negative: Throw if not exists resource', async () => {
116
- const pfs = new PoweredFileSystem();
117
- const chance = new Chance();
118
-
119
- const base = chance.guid();
120
-
121
- try {
122
- pfs.stat(`./${base}`, {
123
- sync: true
124
- });
125
- }
126
- catch (err) {
127
- assert(err.errno === -2);
128
- }
129
97
  });
130
98
  });
131
99
  });