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.
- package/.travis.yml +2 -3
- package/appveyor.yml +2 -4
- package/lib/src/index.d.ts +4 -186
- package/lib/src/index.js +18 -294
- package/lib/src/powered-file-system.d.ts +156 -0
- package/lib/src/powered-file-system.js +264 -0
- package/lib/src/recurse-io-sync.d.ts +10 -5
- package/lib/src/recurse-io-sync.js +74 -69
- package/lib/src/recurse-io.d.ts +14 -6
- package/lib/src/recurse-io.js +164 -160
- package/lib/test/__fmock.d.ts +5 -0
- package/lib/test/__fmock.js +40 -0
- package/lib/test/append.spec.js +36 -77
- package/lib/test/bitmask.spec.js +14 -17
- package/lib/test/chmod.spec.js +42 -84
- package/lib/test/chown.spec.js +45 -71
- package/lib/test/constructor.spec.js +7 -10
- package/lib/test/copy.spec.js +53 -108
- package/lib/test/mkdir.spec.js +62 -119
- package/lib/test/read.spec.js +47 -78
- package/lib/test/readdir.spec.js +48 -90
- package/lib/test/remove.spec.js +44 -65
- package/lib/test/rename.spec.js +43 -75
- package/lib/test/stat.spec.js +50 -78
- package/lib/test/symlink.spec.js +51 -95
- package/lib/test/test.spec.js +37 -66
- package/lib/test/write.spec.js +52 -103
- package/package.json +8 -11
- package/readme.md +10 -21
- package/src/index.ts +4 -623
- package/src/powered-file-system.ts +527 -0
- package/src/recurse-io-sync.ts +77 -71
- package/src/recurse-io.ts +181 -176
- package/test/__fmock.ts +45 -0
- package/test/append.spec.ts +44 -98
- package/test/bitmask.spec.ts +14 -17
- package/test/chmod.spec.ts +45 -95
- package/test/chown.spec.ts +61 -93
- package/test/constructor.spec.ts +4 -7
- package/test/copy.spec.ts +72 -142
- package/test/mkdir.spec.ts +87 -153
- package/test/read.spec.ts +64 -103
- package/test/readdir.spec.ts +65 -113
- package/test/remove.spec.ts +58 -82
- package/test/rename.spec.ts +58 -96
- package/test/stat.spec.ts +68 -100
- package/test/symlink.spec.ts +74 -125
- package/test/test.spec.ts +51 -84
- package/test/write.spec.ts +68 -131
- package/tsconfig.json +14 -7
- package/lib/src/index.js.map +0 -1
- package/lib/src/recurse-io-sync.js.map +0 -1
- package/lib/src/recurse-io.js.map +0 -1
- package/lib/test/append.spec.js.map +0 -1
- package/lib/test/bitmask.spec.js.map +0 -1
- package/lib/test/chmod.spec.js.map +0 -1
- package/lib/test/chown.spec.js.map +0 -1
- package/lib/test/constructor.spec.js.map +0 -1
- package/lib/test/copy.spec.js.map +0 -1
- package/lib/test/mkdir.spec.js.map +0 -1
- package/lib/test/read.spec.js.map +0 -1
- package/lib/test/readdir.spec.js.map +0 -1
- package/lib/test/remove.spec.js.map +0 -1
- package/lib/test/rename.spec.js.map +0 -1
- package/lib/test/stat.spec.js.map +0 -1
- package/lib/test/symlink.spec.js.map +0 -1
- package/lib/test/test.spec.js.map +0 -1
- package/lib/test/write.spec.js.map +0 -1
package/test/mkdir.spec.ts
CHANGED
|
@@ -1,187 +1,121 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import
|
|
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
|
|
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
|
-
|
|
10
|
-
|
|
9
|
+
const pfs = new PoweredFileSystem();
|
|
10
|
+
const chance = new Chance();
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
'
|
|
16
|
-
|
|
17
|
-
|
|
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(
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
restore('./tmpdir');
|
|
23
|
+
});
|
|
24
24
|
|
|
25
25
|
it('Positive: Create directories in the working directory', async () => {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
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
|
|
36
|
+
const guid = chance.guid();
|
|
37
|
+
const pfs = new PoweredFileSystem(`./tmpdir/${guid}`);
|
|
38
38
|
|
|
39
39
|
await pfs.mkdir('.');
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
56
|
-
const chance = new Chance();
|
|
57
|
-
|
|
58
|
-
const base = chance.guid();
|
|
47
|
+
const guid = chance.guid();
|
|
59
48
|
|
|
60
|
-
for (
|
|
61
|
-
await pfs.mkdir(`./tmpdir/${
|
|
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
|
-
|
|
69
|
-
|
|
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 =
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
98
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
|
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
|
-
|
|
9
|
-
|
|
8
|
+
const chance = new Chance();
|
|
9
|
+
let sentences = 0;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
'
|
|
17
|
-
|
|
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(
|
|
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
|
|
26
|
-
|
|
27
|
-
const raw = await pfs.read('./tmpdir/binapp');
|
|
28
|
+
const { length } = await pfs.read('./tmpdir/tings.txt');
|
|
28
29
|
|
|
29
|
-
assert(
|
|
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
|
|
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(
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
67
|
-
const chance = new Chance();
|
|
53
|
+
const guid = chance.guid();
|
|
68
54
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
});
|
package/test/readdir.spec.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
9
|
-
|
|
8
|
+
const chance = new Chance();
|
|
9
|
+
let counter = 0;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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(
|
|
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
|
|
36
|
-
const
|
|
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
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
});
|