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/lib/test/mkdir.spec.js
CHANGED
|
@@ -3,145 +3,88 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const mock_fs_1 = __importDefault(require("mock-fs"));
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
8
|
const chance_1 = __importDefault(require("chance"));
|
|
11
|
-
const
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
12
12
|
describe('mkdir(src [, options])', () => {
|
|
13
|
+
const pfs = new src_1.PoweredFileSystem();
|
|
14
|
+
const chance = new chance_1.default();
|
|
13
15
|
beforeEach(() => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
'flexapp': mock_fs_1.default.symlink({
|
|
21
|
-
path: 'tmpdir/binapp'
|
|
22
|
-
})
|
|
16
|
+
(0, __fmock_1.fmock)({
|
|
17
|
+
'./tmpdir/tings.txt': {
|
|
18
|
+
type: 'file',
|
|
19
|
+
data: chance.string()
|
|
20
|
+
}
|
|
23
21
|
});
|
|
24
22
|
});
|
|
25
|
-
afterEach(
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
25
|
+
});
|
|
26
26
|
it('Positive: Create directories in the working directory', async () => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const exist = await pfs.test(`./tmpdir/${base}`);
|
|
32
|
-
(0, assert_1.default)(exist);
|
|
27
|
+
const guid = chance.guid();
|
|
28
|
+
await pfs.mkdir(`./tmpdir/${guid}`);
|
|
29
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
30
|
+
(0, node_assert_1.default)(exist);
|
|
33
31
|
});
|
|
34
32
|
it(`Positive: Make current directory`, async () => {
|
|
35
|
-
const
|
|
33
|
+
const guid = chance.guid();
|
|
34
|
+
const pfs = new src_1.PoweredFileSystem(`./tmpdir/${guid}`);
|
|
36
35
|
await pfs.mkdir('.');
|
|
37
|
-
const exist =
|
|
38
|
-
(0,
|
|
39
|
-
});
|
|
40
|
-
it(`Positive: Make current directory, when current directory is absolute path`, async () => {
|
|
41
|
-
const pfs = new src_1.default('./tmpdir');
|
|
42
|
-
await pfs.mkdir(process.cwd());
|
|
43
|
-
const exist = await pfs.test('.');
|
|
44
|
-
(0, assert_1.default)(exist);
|
|
36
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
37
|
+
(0, node_assert_1.default)(exist);
|
|
45
38
|
});
|
|
46
39
|
it('Positive: Should work fine with the existing directory', async () => {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (const item of [base, base]) {
|
|
51
|
-
await pfs.mkdir(`./tmpdir/${item}`);
|
|
52
|
-
const exist = await pfs.test(`./tmpdir/${item}`);
|
|
53
|
-
(0, assert_1.default)(exist);
|
|
40
|
+
const guid = chance.guid();
|
|
41
|
+
for (let i = 2; i; i--) {
|
|
42
|
+
await pfs.mkdir(`./tmpdir/${guid}`);
|
|
54
43
|
}
|
|
44
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
45
|
+
(0, node_assert_1.default)(exist);
|
|
55
46
|
});
|
|
56
|
-
it('
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
47
|
+
it('Negative: Throw an exception if trying to create a directory in file', async () => {
|
|
48
|
+
const guid = chance.guid();
|
|
49
|
+
await (0, expect_1.expect)(async () => {
|
|
50
|
+
await pfs.mkdir(`./tmpdir/tings.txt/${guid}`);
|
|
51
|
+
})
|
|
52
|
+
.rejects
|
|
53
|
+
.toThrow();
|
|
54
|
+
});
|
|
55
|
+
it('Positive: Create directories in the working directory', () => {
|
|
56
|
+
const guid = chance.guid();
|
|
57
|
+
pfs.mkdir(`./tmpdir/${guid}`, {
|
|
58
|
+
sync: true
|
|
63
59
|
});
|
|
64
|
-
const exist =
|
|
65
|
-
(0,
|
|
60
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
61
|
+
(0, node_assert_1.default)(exist);
|
|
66
62
|
});
|
|
67
|
-
it('
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
(0, assert_1.default)(err.errno === -20);
|
|
76
|
-
}
|
|
63
|
+
it('[sync] Positive: Make current directory', () => {
|
|
64
|
+
const guid = chance.guid();
|
|
65
|
+
const pfs = new src_1.PoweredFileSystem(`./tmpdir/${guid}`);
|
|
66
|
+
pfs.mkdir('.', {
|
|
67
|
+
sync: true
|
|
68
|
+
});
|
|
69
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
70
|
+
(0, node_assert_1.default)(exist);
|
|
77
71
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const base = chance.guid();
|
|
83
|
-
pfs.mkdir(`./tmpdir/${base}`, {
|
|
72
|
+
it('[sync] Positive: Should work fine with the existing directory', () => {
|
|
73
|
+
const guid = chance.guid();
|
|
74
|
+
for (let i = 2; i; i--) {
|
|
75
|
+
pfs.mkdir(`./tmpdir/${guid}`, {
|
|
84
76
|
sync: true
|
|
85
77
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
}
|
|
79
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
|
|
80
|
+
(0, node_assert_1.default)(exist);
|
|
81
|
+
});
|
|
82
|
+
it('[sync] Negative: Throw an exception if trying to create a directory in file', () => {
|
|
83
|
+
const guid = chance.guid();
|
|
84
|
+
node_assert_1.default.throws(() => {
|
|
85
|
+
pfs.mkdir(`./tmpdir/tings.txt/${guid}`, {
|
|
92
86
|
sync: true
|
|
93
87
|
});
|
|
94
|
-
const exist = await pfs.test('.');
|
|
95
|
-
(0, assert_1.default)(exist);
|
|
96
|
-
});
|
|
97
|
-
it('Positive: Should work fine with the existing directory', async () => {
|
|
98
|
-
const pfs = new src_1.default();
|
|
99
|
-
const chance = new chance_1.default();
|
|
100
|
-
const base = chance.guid();
|
|
101
|
-
for (const item of [base, base]) {
|
|
102
|
-
pfs.mkdir(`./tmpdir/${item}`, {
|
|
103
|
-
sync: true
|
|
104
|
-
});
|
|
105
|
-
const exist = await pfs.test(`./tmpdir/${item}`);
|
|
106
|
-
(0, assert_1.default)(exist);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
it('Positive: Create directories when path is absolute', async () => {
|
|
110
|
-
const pfs = new src_1.default();
|
|
111
|
-
const chance = new chance_1.default();
|
|
112
|
-
const tmpdir = os_1.default.tmpdir();
|
|
113
|
-
const base = chance.guid();
|
|
114
|
-
pfs.mkdir(`${tmpdir}${path_1.sep}${base}`, {
|
|
115
|
-
sync: true,
|
|
116
|
-
resolve: false
|
|
117
|
-
});
|
|
118
|
-
const exist = await pfs.test(`${tmpdir}${path_1.sep}${base}`);
|
|
119
|
-
(0, assert_1.default)(exist);
|
|
120
|
-
});
|
|
121
|
-
it('Positive: Create in current directories when path is absolute', async () => {
|
|
122
|
-
const pfs = new src_1.default();
|
|
123
|
-
const chance = new chance_1.default();
|
|
124
|
-
const cwd = process.cwd();
|
|
125
|
-
const base = chance.guid();
|
|
126
|
-
pfs.mkdir(`${cwd}${path_1.sep}${base}`, {
|
|
127
|
-
sync: true,
|
|
128
|
-
resolve: false
|
|
129
|
-
});
|
|
130
|
-
const exist = await pfs.test(base);
|
|
131
|
-
(0, assert_1.default)(exist);
|
|
132
|
-
});
|
|
133
|
-
it('Negative: Throw an exception if trying to create a directory in file', async () => {
|
|
134
|
-
const pfs = new src_1.default();
|
|
135
|
-
const chance = new chance_1.default();
|
|
136
|
-
const base = chance.guid();
|
|
137
|
-
try {
|
|
138
|
-
pfs.mkdir(`./tmpdir/binapp/${base}`, {
|
|
139
|
-
sync: true
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
(0, assert_1.default)(err.errno === -20);
|
|
144
|
-
}
|
|
145
88
|
});
|
|
146
89
|
});
|
|
147
90
|
});
|
package/lib/test/read.spec.js
CHANGED
|
@@ -3,102 +3,71 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const mock_fs_1 = __importDefault(require("mock-fs"));
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
9
7
|
const chance_1 = __importDefault(require("chance"));
|
|
10
|
-
const
|
|
8
|
+
const expect_1 = require("expect");
|
|
9
|
+
const __fmock_1 = require("./__fmock");
|
|
10
|
+
const src_1 = require("../src");
|
|
11
11
|
describe('read(src [, options])', () => {
|
|
12
|
+
const chance = new chance_1.default();
|
|
13
|
+
let sentences = 0;
|
|
12
14
|
beforeEach(() => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
'
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
path: 'tmpdir/binapp'
|
|
21
|
-
})
|
|
15
|
+
const tingsContent = chance.paragraph();
|
|
16
|
+
sentences = tingsContent.length;
|
|
17
|
+
(0, __fmock_1.fmock)({
|
|
18
|
+
'./tmpdir/tings.txt': {
|
|
19
|
+
type: 'file',
|
|
20
|
+
data: tingsContent
|
|
21
|
+
}
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
|
-
afterEach(
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
26
|
+
});
|
|
25
27
|
it('Positive: Must read content of file; String type by default', async () => {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
(0, assert_1.default)(raw.length > 0);
|
|
28
|
+
const { length } = await src_1.pfs.read('./tmpdir/tings.txt');
|
|
29
|
+
(0, node_assert_1.default)(length === sentences);
|
|
29
30
|
});
|
|
30
31
|
it('Positive: Must read Buffer content of file when encoding is null', async () => {
|
|
31
|
-
const
|
|
32
|
-
const raw = await pfs.read('./tmpdir/binapp', {
|
|
32
|
+
const buffer = await src_1.pfs.read('./tmpdir/tings.txt', {
|
|
33
33
|
encoding: null
|
|
34
34
|
});
|
|
35
|
-
(0,
|
|
36
|
-
});
|
|
37
|
-
it('Positive: Must read content of file, when path is absolute', async () => {
|
|
38
|
-
const pfs = new src_1.default();
|
|
39
|
-
const cwd = process.cwd();
|
|
40
|
-
const raw = await pfs.read(`${cwd}${path_1.sep}tmpdir${path_1.sep}binapp`, {
|
|
41
|
-
resolve: false
|
|
42
|
-
});
|
|
43
|
-
(0, assert_1.default)(raw.length > 0);
|
|
35
|
+
(0, node_assert_1.default)(buffer instanceof Buffer);
|
|
44
36
|
});
|
|
45
37
|
it('Negative: Throw if resource is not file', async () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(0, assert_1.default)(err.errno === -21);
|
|
52
|
-
}
|
|
38
|
+
await (0, expect_1.expect)(async () => {
|
|
39
|
+
await src_1.pfs.read(`./tmpdir`);
|
|
40
|
+
})
|
|
41
|
+
.rejects
|
|
42
|
+
.toThrow();
|
|
53
43
|
});
|
|
54
44
|
it('Negative: Throw if not exists resource', async () => {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
catch (err) {
|
|
62
|
-
(0, assert_1.default)(err.errno === -2);
|
|
63
|
-
}
|
|
45
|
+
const guid = chance.guid();
|
|
46
|
+
await (0, expect_1.expect)(async () => {
|
|
47
|
+
await src_1.pfs.read(`./tmpdir/${guid}`);
|
|
48
|
+
})
|
|
49
|
+
.rejects
|
|
50
|
+
.toThrow();
|
|
64
51
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const { length } = pfs.read('./tmpdir/binapp', {
|
|
69
|
-
sync: true
|
|
70
|
-
});
|
|
71
|
-
(0, assert_1.default)(length > 0);
|
|
52
|
+
it('[sync] Positive: Must read content of file; String type by default', () => {
|
|
53
|
+
const { length } = src_1.pfs.read('./tmpdir/tings.txt', {
|
|
54
|
+
sync: true
|
|
72
55
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
(0, assert_1.default)(raw instanceof Buffer);
|
|
56
|
+
(0, node_assert_1.default)(length === sentences);
|
|
57
|
+
});
|
|
58
|
+
it('[sync] Positive: Must read Buffer content of file when encoding is null', () => {
|
|
59
|
+
const buffer = src_1.pfs.read('./tmpdir/tings.txt', {
|
|
60
|
+
encoding: null,
|
|
61
|
+
sync: true
|
|
80
62
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
(0, node_assert_1.default)(buffer instanceof Buffer);
|
|
64
|
+
});
|
|
65
|
+
it(`[sync] Negative: Throw if not exists resource`, () => {
|
|
66
|
+
const guid = chance.guid();
|
|
67
|
+
node_assert_1.default.throws(() => {
|
|
68
|
+
src_1.pfs.read(`./tmpdir/${guid}`, {
|
|
69
|
+
sync: true
|
|
87
70
|
});
|
|
88
|
-
(0, assert_1.default)(length > 0);
|
|
89
|
-
});
|
|
90
|
-
it(`Negative: Throw if not exists resource`, async () => {
|
|
91
|
-
const pfs = new src_1.default();
|
|
92
|
-
const chance = new chance_1.default();
|
|
93
|
-
const base = chance.guid();
|
|
94
|
-
try {
|
|
95
|
-
pfs.read(`./${base}`, {
|
|
96
|
-
sync: true
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
(0, assert_1.default)(err.errno === -2);
|
|
101
|
-
}
|
|
102
71
|
});
|
|
103
72
|
});
|
|
104
73
|
});
|
package/lib/test/readdir.spec.js
CHANGED
|
@@ -3,110 +3,68 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const mock_fs_1 = __importDefault(require("mock-fs"));
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
9
7
|
const chance_1 = __importDefault(require("chance"));
|
|
10
|
-
const
|
|
8
|
+
const expect_1 = require("expect");
|
|
9
|
+
const __fmock_1 = require("./__fmock");
|
|
10
|
+
const src_1 = require("../src");
|
|
11
11
|
describe('readdir(src[, options])', () => {
|
|
12
|
+
const chance = new chance_1.default();
|
|
13
|
+
let counter = 0;
|
|
12
14
|
beforeEach(() => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
15
|
+
const frame = {
|
|
16
|
+
'./tmpdir/tings.txt': {
|
|
17
|
+
type: 'file',
|
|
18
|
+
data: chance.string()
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
counter = chance.natural({ max: 7 });
|
|
22
|
+
for (let i = 0; i < counter; i++) {
|
|
23
|
+
frame[`./tmpdir/${i}`] = { type: 'directory' };
|
|
24
|
+
}
|
|
25
|
+
(0, __fmock_1.fmock)(frame);
|
|
23
26
|
});
|
|
24
|
-
afterEach(
|
|
25
|
-
|
|
26
|
-
const pfs = new src_1.default();
|
|
27
|
-
const listOfFiles = await pfs.readdir('./tmpdir');
|
|
28
|
-
assert_1.default.deepStrictEqual(listOfFiles, [
|
|
29
|
-
'binapp',
|
|
30
|
-
'libxbase'
|
|
31
|
-
]);
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
32
29
|
});
|
|
33
|
-
it('Positive: Must return a directory listing
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
const listOfFiles = await pfs.readdir(`${cwd}${path_1.sep}tmpdir`, {
|
|
37
|
-
resolve: false
|
|
38
|
-
});
|
|
39
|
-
assert_1.default.deepStrictEqual(listOfFiles, [
|
|
40
|
-
'binapp',
|
|
41
|
-
'libxbase'
|
|
42
|
-
]);
|
|
30
|
+
it('Positive: Must return a directory listing', async () => {
|
|
31
|
+
const { length } = await src_1.pfs.readdir('./tmpdir');
|
|
32
|
+
(0, node_assert_1.default)(counter + 1 === length);
|
|
43
33
|
});
|
|
44
34
|
it('Negative: Throw if resource is not directory', async () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
(0, assert_1.default)(err.errno === -20);
|
|
51
|
-
}
|
|
35
|
+
await (0, expect_1.expect)(async () => {
|
|
36
|
+
await src_1.pfs.readdir(`./tmpdir/tings.txt`);
|
|
37
|
+
})
|
|
38
|
+
.rejects
|
|
39
|
+
.toThrow();
|
|
52
40
|
});
|
|
53
41
|
it('Negative: Throw if not exists resource', async () => {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
catch (err) {
|
|
61
|
-
(0, assert_1.default)(err.errno === -2);
|
|
62
|
-
}
|
|
42
|
+
const guid = chance.guid();
|
|
43
|
+
await (0, expect_1.expect)(async () => {
|
|
44
|
+
await src_1.pfs.readdir(`./tmpdir/${guid}`);
|
|
45
|
+
})
|
|
46
|
+
.rejects
|
|
47
|
+
.toThrow();
|
|
63
48
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
it('[sync] Positive: Must return a directory listing', () => {
|
|
50
|
+
const { length } = src_1.pfs.readdir('./tmpdir', {
|
|
51
|
+
sync: true
|
|
52
|
+
});
|
|
53
|
+
(0, node_assert_1.default)(counter + 1 === length);
|
|
54
|
+
});
|
|
55
|
+
it('Negative: Throw if resource is not directory', () => {
|
|
56
|
+
node_assert_1.default.throws(() => {
|
|
57
|
+
src_1.pfs.readdir(`./tmpdir/tings.txt`, {
|
|
68
58
|
sync: true
|
|
69
59
|
});
|
|
70
|
-
assert_1.default.deepStrictEqual(listOfFiles, [
|
|
71
|
-
'binapp',
|
|
72
|
-
'libxbase'
|
|
73
|
-
]);
|
|
74
60
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
61
|
+
});
|
|
62
|
+
it(`Negative: Throw if not exists resource`, () => {
|
|
63
|
+
const guid = chance.guid();
|
|
64
|
+
node_assert_1.default.throws(() => {
|
|
65
|
+
src_1.pfs.readdir(`./tmpdir/${guid}`, {
|
|
66
|
+
sync: true
|
|
81
67
|
});
|
|
82
|
-
assert_1.default.deepStrictEqual(listOfFiles, [
|
|
83
|
-
'binapp',
|
|
84
|
-
'libxbase'
|
|
85
|
-
]);
|
|
86
|
-
});
|
|
87
|
-
it('Negative: Throw if resource is not directory', async () => {
|
|
88
|
-
const pfs = new src_1.default();
|
|
89
|
-
try {
|
|
90
|
-
pfs.readdir(`./tmpdir/binapp`, {
|
|
91
|
-
sync: true
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
catch (err) {
|
|
95
|
-
(0, assert_1.default)(err.errno === -20);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
it(`Negative: Throw if not exists resource`, async () => {
|
|
99
|
-
const pfs = new src_1.default();
|
|
100
|
-
const chance = new chance_1.default();
|
|
101
|
-
const base = chance.guid();
|
|
102
|
-
try {
|
|
103
|
-
pfs.readdir(`./${base}`, {
|
|
104
|
-
sync: true
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
catch (err) {
|
|
108
|
-
(0, assert_1.default)(err.errno === -2);
|
|
109
|
-
}
|
|
110
68
|
});
|
|
111
69
|
});
|
|
112
70
|
});
|
package/lib/test/remove.spec.js
CHANGED
|
@@ -3,82 +3,61 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const mock_fs_1 = __importDefault(require("mock-fs"));
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
8
|
const chance_1 = __importDefault(require("chance"));
|
|
10
|
-
const
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
11
12
|
describe('remove(src [, options])', () => {
|
|
13
|
+
const chance = new chance_1.default();
|
|
12
14
|
beforeEach(() => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
'tmpdir': {
|
|
16
|
-
'
|
|
17
|
-
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
const frame = {
|
|
17
|
+
'./tmpdir/tings.txt': {
|
|
18
|
+
type: 'file',
|
|
19
|
+
data: chance.string()
|
|
18
20
|
},
|
|
19
|
-
'flexapp':
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
'./tmpdir/flexapp': {
|
|
22
|
+
type: 'symlink',
|
|
23
|
+
target: `${cwd}/tmpdir/tings.txt`
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const counter = chance.natural({ max: 7 });
|
|
27
|
+
for (let i = 0; i < counter; i++) {
|
|
28
|
+
frame[`./tmpdir/${i}`] = { type: 'directory' };
|
|
29
|
+
}
|
|
30
|
+
(0, __fmock_1.fmock)(frame);
|
|
23
31
|
});
|
|
24
|
-
afterEach(
|
|
25
|
-
|
|
26
|
-
const pfs = new src_1.default();
|
|
27
|
-
await pfs.remove('./tmpdir');
|
|
28
|
-
const exist = await pfs.test('./tmpdir');
|
|
29
|
-
(0, assert_1.default)(exist === false);
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
30
34
|
});
|
|
31
|
-
it('Positive: Removal a directory with a file
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
resolve: false
|
|
36
|
-
});
|
|
37
|
-
const exist = await pfs.test('./tmpdir');
|
|
38
|
-
(0, assert_1.default)(exist === false);
|
|
35
|
+
it('Positive: Removal a directory with a file', async () => {
|
|
36
|
+
await src_1.pfs.remove('./tmpdir');
|
|
37
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir`);
|
|
38
|
+
(0, node_assert_1.default)(exist === false);
|
|
39
39
|
});
|
|
40
40
|
it('Negative: Throw if not exists resource', async () => {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
catch (err) {
|
|
48
|
-
(0, assert_1.default)(err.errno === -2);
|
|
49
|
-
}
|
|
41
|
+
const guid = chance.guid();
|
|
42
|
+
await (0, expect_1.expect)(async () => {
|
|
43
|
+
await src_1.pfs.remove(`./${guid}`);
|
|
44
|
+
})
|
|
45
|
+
.rejects
|
|
46
|
+
.toThrow();
|
|
50
47
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
pfs.remove('./tmpdir', {
|
|
55
|
-
sync: true
|
|
56
|
-
});
|
|
57
|
-
const exist = await pfs.test('./tmpdir');
|
|
58
|
-
(0, assert_1.default)(exist === false);
|
|
48
|
+
it('[sync] Positive: Removal a directory with a file', () => {
|
|
49
|
+
src_1.pfs.remove('./tmpdir', {
|
|
50
|
+
sync: true
|
|
59
51
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
const exist = node_fs_1.default.existsSync(`./tmpdir`);
|
|
53
|
+
(0, node_assert_1.default)(exist === false);
|
|
54
|
+
});
|
|
55
|
+
it('[sync] Negative: Throw if not exists resource', () => {
|
|
56
|
+
const guid = chance.guid();
|
|
57
|
+
node_assert_1.default.throws(() => {
|
|
58
|
+
src_1.pfs.remove(`./tmpdir/${guid}`, {
|
|
59
|
+
sync: true
|
|
66
60
|
});
|
|
67
|
-
const exist = await pfs.test('./tmpdir');
|
|
68
|
-
(0, assert_1.default)(exist === false);
|
|
69
|
-
});
|
|
70
|
-
it('Negative: Throw if not exists resource', async () => {
|
|
71
|
-
const pfs = new src_1.default();
|
|
72
|
-
const chance = new chance_1.default();
|
|
73
|
-
const base = chance.guid();
|
|
74
|
-
try {
|
|
75
|
-
pfs.remove(`./${base}`, {
|
|
76
|
-
sync: true
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
(0, assert_1.default)(err.errno === -2);
|
|
81
|
-
}
|
|
82
61
|
});
|
|
83
62
|
});
|
|
84
63
|
});
|