pwd-fs 2.4.2 → 3.1.3
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/__tests__/__fmock.ts +45 -0
- package/__tests__/append.spec.ts +72 -0
- package/__tests__/bitmask.spec.ts +23 -0
- package/__tests__/chmod.spec.ts +78 -0
- package/__tests__/chown.spec.ts +88 -0
- package/{test → __tests__}/constructor.spec.ts +3 -6
- package/__tests__/copy.spec.ts +102 -0
- package/__tests__/mkdir.spec.ts +120 -0
- package/__tests__/read.spec.ts +92 -0
- package/__tests__/readdir.spec.ts +87 -0
- package/__tests__/remove.spec.ts +78 -0
- package/__tests__/rename.spec.ts +84 -0
- package/__tests__/stat.spec.ts +100 -0
- package/__tests__/symlink.spec.ts +95 -0
- package/__tests__/test.spec.ts +82 -0
- package/__tests__/write.spec.ts +104 -0
- package/appveyor.yml +2 -4
- package/jest.config.ts +14 -0
- package/lib/__tests__/__fmock.d.ts +5 -0
- package/lib/index.js +24 -0
- package/lib/powered-file-system.js +260 -0
- package/lib/recurse-io-sync.js +90 -0
- package/lib/recurse-io.js +194 -0
- package/lib/src/index.d.ts +6 -186
- package/lib/src/powered-file-system.d.ts +155 -0
- package/lib/src/recurse-io-sync.d.ts +10 -5
- package/lib/src/recurse-io.d.ts +14 -6
- package/package.json +18 -14
- package/readme.md +0 -13
- package/rollup.config.js +16 -0
- package/src/index.ts +29 -626
- package/src/powered-file-system.ts +525 -0
- package/src/recurse-io-sync.ts +77 -71
- package/src/recurse-io.ts +181 -176
- package/tsconfig.json +12 -5
- package/lib/src/index.js +0 -297
- package/lib/src/index.js.map +0 -1
- package/lib/src/recurse-io-sync.js +0 -83
- package/lib/src/recurse-io-sync.js.map +0 -1
- package/lib/src/recurse-io.js +0 -188
- package/lib/src/recurse-io.js.map +0 -1
- package/lib/test/append.spec.js +0 -99
- package/lib/test/append.spec.js.map +0 -1
- package/lib/test/bitmask.spec.js +0 -29
- package/lib/test/bitmask.spec.js.map +0 -1
- package/lib/test/chmod.spec.js +0 -104
- package/lib/test/chmod.spec.js.map +0 -1
- package/lib/test/chown.spec.js +0 -94
- package/lib/test/chown.spec.js.map +0 -1
- package/lib/test/constructor.spec.js +0 -20
- package/lib/test/constructor.spec.js.map +0 -1
- package/lib/test/copy.spec.js +0 -135
- package/lib/test/copy.spec.js.map +0 -1
- package/lib/test/mkdir.spec.js +0 -147
- package/lib/test/mkdir.spec.js.map +0 -1
- package/lib/test/read.spec.js +0 -104
- package/lib/test/read.spec.js.map +0 -1
- package/lib/test/readdir.spec.js +0 -112
- package/lib/test/readdir.spec.js.map +0 -1
- package/lib/test/remove.spec.js +0 -84
- package/lib/test/remove.spec.js.map +0 -1
- package/lib/test/rename.spec.js +0 -98
- package/lib/test/rename.spec.js.map +0 -1
- package/lib/test/stat.spec.js +0 -104
- package/lib/test/stat.spec.js.map +0 -1
- package/lib/test/symlink.spec.js +0 -118
- package/lib/test/symlink.spec.js.map +0 -1
- package/lib/test/test.spec.js +0 -89
- package/lib/test/test.spec.js.map +0 -1
- package/lib/test/write.spec.js +0 -133
- package/lib/test/write.spec.js.map +0 -1
- package/test/append.spec.ts +0 -125
- package/test/bitmask.spec.ts +0 -26
- package/test/chmod.spec.ts +0 -127
- package/test/chown.spec.ts +0 -118
- package/test/copy.spec.ts +0 -171
- package/test/mkdir.spec.ts +0 -187
- package/test/read.spec.ts +0 -130
- package/test/readdir.spec.ts +0 -134
- package/test/remove.spec.ts +0 -102
- package/test/rename.spec.ts +0 -122
- package/test/stat.spec.ts +0 -131
- package/test/symlink.spec.ts +0 -146
- package/test/test.spec.ts +0 -113
- package/test/write.spec.ts +0 -167
- /package/lib/{test → __tests__}/append.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/bitmask.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/chmod.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/chown.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/constructor.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/copy.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/mkdir.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/read.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/readdir.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/remove.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/rename.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/stat.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/symlink.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/test.spec.d.ts +0 -0
- /package/lib/{test → __tests__}/write.spec.d.ts +0 -0
package/test/chmod.spec.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import { sep } from 'path';
|
|
3
|
-
import mockFs from 'mock-fs';
|
|
4
|
-
import Chance from 'chance';
|
|
5
|
-
import PoweredFileSystem from '../src';
|
|
6
|
-
|
|
7
|
-
describe('chmod(src, mode [, options])', () => {
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
const chance = new Chance();
|
|
10
|
-
|
|
11
|
-
mockFs({
|
|
12
|
-
'tmpdir': {
|
|
13
|
-
'binapp': chance.string(),
|
|
14
|
-
'libxbase': mockFs.directory()
|
|
15
|
-
},
|
|
16
|
-
'flexapp': mockFs.symlink({
|
|
17
|
-
path: 'tmpdir/binapp'
|
|
18
|
-
})
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterEach(mockFs.restore);
|
|
23
|
-
|
|
24
|
-
it('Positive: Changes directory and file permissions', async () => {
|
|
25
|
-
const pfs = new PoweredFileSystem();
|
|
26
|
-
|
|
27
|
-
await pfs.chmod('./tmpdir', 0o744);
|
|
28
|
-
|
|
29
|
-
const { mode } = await pfs.stat('./tmpdir/binapp');
|
|
30
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
31
|
-
|
|
32
|
-
assert(umask === 0o744);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('Positive: Must be changes directory when path is absolute', async () => {
|
|
36
|
-
const pfs = new PoweredFileSystem();
|
|
37
|
-
|
|
38
|
-
const cwd = process.cwd();
|
|
39
|
-
await pfs.chmod(`${cwd}${sep}tmpdir${sep}libxbase` , 0o744, {
|
|
40
|
-
resolve: false
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const { mode } = await pfs.stat('./tmpdir/libxbase');
|
|
44
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
45
|
-
|
|
46
|
-
assert(umask === 0o744);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('Negative: Search permission is denied on a component of the path prefix', async () => {
|
|
50
|
-
const pfs = new PoweredFileSystem();
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
await pfs.chmod('./tmpdir', 0);
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
assert(err.errno === -9);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('Negative: Throw if not exists resource', async () => {
|
|
61
|
-
const pfs = new PoweredFileSystem();
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
await pfs.chmod('./non-existent-source', 0o744);
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
assert(err.errno === -2);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('sync mode', () => {
|
|
72
|
-
it(`Positive: Changes directory and file permissions`, async () => {
|
|
73
|
-
const pfs = new PoweredFileSystem();
|
|
74
|
-
|
|
75
|
-
pfs.chmod('./tmpdir', 0o744, {
|
|
76
|
-
sync: true
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const { mode } = await pfs.stat('./tmpdir/binapp');
|
|
80
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
81
|
-
|
|
82
|
-
assert(umask === 0o744);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('Positive: Must be changes directory when path is absolute', async () => {
|
|
86
|
-
const pfs = new PoweredFileSystem();
|
|
87
|
-
|
|
88
|
-
const cwd = process.cwd();
|
|
89
|
-
|
|
90
|
-
pfs.chmod(`${cwd}${sep}tmpdir${sep}libxbase` , 0o744, {
|
|
91
|
-
sync: true,
|
|
92
|
-
resolve: false
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const { mode } = await pfs.stat('./tmpdir/libxbase');
|
|
96
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
97
|
-
|
|
98
|
-
assert(umask === 0o744);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('Negative: Search permission is denied on a component of the path prefix', async () => {
|
|
102
|
-
const pfs = new PoweredFileSystem();
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
pfs.chmod('./tmpdir', 0, {
|
|
106
|
-
sync: true
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
assert(err.errno === -9);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('Negative: Throw if not exists resource', async () => {
|
|
115
|
-
const pfs = new PoweredFileSystem();
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
pfs.chmod('./non-existent-source', 0o744, {
|
|
119
|
-
sync: true
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
catch (err) {
|
|
123
|
-
assert(err.errno === -2);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
package/test/chown.spec.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import { sep } from 'path';
|
|
3
|
-
import mockFs from 'mock-fs';
|
|
4
|
-
import Chance from 'chance';
|
|
5
|
-
import PoweredFileSystem from '../src';
|
|
6
|
-
|
|
7
|
-
describe('chown(src, uid, gid [, options])', () => {
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
const chance = new Chance();
|
|
10
|
-
|
|
11
|
-
mockFs({
|
|
12
|
-
'tmpdir': {
|
|
13
|
-
'binapp': chance.string(),
|
|
14
|
-
'libxbase': mockFs.directory()
|
|
15
|
-
},
|
|
16
|
-
'flexapp': mockFs.symlink({
|
|
17
|
-
path: 'tmpdir/binapp'
|
|
18
|
-
})
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterEach(mockFs.restore);
|
|
23
|
-
|
|
24
|
-
it('Positive: Changes the permissions of a file', async () => {
|
|
25
|
-
const pfs = new PoweredFileSystem();
|
|
26
|
-
|
|
27
|
-
await pfs.chown('./tmpdir', 0, 0);
|
|
28
|
-
const { uid, gid } = await pfs.stat('./tmpdir');
|
|
29
|
-
|
|
30
|
-
assert(uid === 0 && gid === 0);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('Positive: Changes the permissions of a directory', async () => {
|
|
34
|
-
const pfs = new PoweredFileSystem();
|
|
35
|
-
|
|
36
|
-
await pfs.chown('./tmpdir/libxbase', 0, 0);
|
|
37
|
-
const { uid, gid } = await pfs.stat('./tmpdir/libxbase');
|
|
38
|
-
|
|
39
|
-
assert(uid === 0 && gid === 0);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('Positive: Changes the permissions of a file, when path is absolute', async () => {
|
|
43
|
-
const pfs = new PoweredFileSystem();
|
|
44
|
-
|
|
45
|
-
const cwd = process.cwd();
|
|
46
|
-
await pfs.chown(`${cwd}${sep}tmpdir${sep}binapp`, 1, 1, {
|
|
47
|
-
resolve: false
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const { uid, gid } = await pfs.stat('./tmpdir/binapp');
|
|
51
|
-
|
|
52
|
-
assert(uid === 1 && gid === 1);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('Negative: To a non-existent resource to return an Error', async () => {
|
|
56
|
-
const pfs = new PoweredFileSystem();
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
await pfs.chown('./non-existent-source', 1, 1);
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
assert(err.errno === -2);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('sync mode', () => {
|
|
67
|
-
it('Positive: Changes the permissions of a file', async () => {
|
|
68
|
-
const pfs = new PoweredFileSystem();
|
|
69
|
-
|
|
70
|
-
pfs.chown('./tmpdir/binapp', 1, 1, {
|
|
71
|
-
sync: true
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const { uid, gid } = await pfs.stat('./tmpdir/binapp');
|
|
75
|
-
|
|
76
|
-
assert(uid === 1 && gid === 1);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('Positive: Changes the permissions of a directory', async () => {
|
|
80
|
-
const pfs = new PoweredFileSystem();
|
|
81
|
-
|
|
82
|
-
pfs.chown('./tmpdir', 1, 1, {
|
|
83
|
-
sync: true
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const { uid, gid } = await pfs.stat('./tmpdir');
|
|
87
|
-
|
|
88
|
-
assert(uid === 1 && gid === 1);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('Positive: Changes the permissions of a file, when path is absolute', async () => {
|
|
92
|
-
const pfs = new PoweredFileSystem();
|
|
93
|
-
|
|
94
|
-
const cwd = process.cwd();
|
|
95
|
-
pfs.chown(`${cwd}${sep}tmpdir${sep}binapp`, 1, 1, {
|
|
96
|
-
sync: true,
|
|
97
|
-
resolve: false
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const { uid, gid } = await pfs.stat('./tmpdir/binapp');
|
|
101
|
-
|
|
102
|
-
assert(uid === 1 && gid === 1);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it(`Negative: To a non-existent resource to return an Error`, async () => {
|
|
106
|
-
const pfs = new PoweredFileSystem();
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
pfs.chown('./non-existent-source', 1, 1, {
|
|
110
|
-
sync: true
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
assert(err.errno === -2);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
package/test/copy.spec.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import { sep } from 'path';
|
|
4
|
-
import mockFs from 'mock-fs';
|
|
5
|
-
import Chance from 'chance';
|
|
6
|
-
import PoweredFileSystem from '../src';
|
|
7
|
-
|
|
8
|
-
describe('copy(src, dir [, options])', () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
const chance = new Chance();
|
|
11
|
-
|
|
12
|
-
mockFs({
|
|
13
|
-
'tmpdir': {
|
|
14
|
-
'binapp': chance.string(),
|
|
15
|
-
'libxbase': mockFs.directory()
|
|
16
|
-
},
|
|
17
|
-
'flexapp': mockFs.symlink({
|
|
18
|
-
path: 'tmpdir/binapp'
|
|
19
|
-
})
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
afterEach(mockFs.restore);
|
|
24
|
-
|
|
25
|
-
it('Positive: Copying a item file', async () => {
|
|
26
|
-
const pfs = new PoweredFileSystem();
|
|
27
|
-
|
|
28
|
-
const dist = os.tmpdir();
|
|
29
|
-
await pfs.copy('./tmpdir/binapp', dist);
|
|
30
|
-
|
|
31
|
-
const { mode } = await pfs.stat(`${dist}/binapp`);
|
|
32
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
33
|
-
|
|
34
|
-
assert(umask === 0o666);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('Positive: Recursive copying a directory', async () => {
|
|
38
|
-
const pfs = new PoweredFileSystem();
|
|
39
|
-
|
|
40
|
-
const dist = os.tmpdir();
|
|
41
|
-
await pfs.copy('./tmpdir', dist);
|
|
42
|
-
|
|
43
|
-
const { mode } = await pfs.stat(`${dist}/tmpdir/libxbase`);
|
|
44
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
45
|
-
|
|
46
|
-
assert(umask === 0o777);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('Positive: Recursive copying a directory. Permission check of file', async () => {
|
|
50
|
-
const pfs = new PoweredFileSystem();
|
|
51
|
-
|
|
52
|
-
const dist = os.tmpdir();
|
|
53
|
-
await pfs.copy('./tmpdir', dist);
|
|
54
|
-
|
|
55
|
-
const { mode } = await pfs.stat(`${dist}/tmpdir/binapp`);
|
|
56
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
57
|
-
|
|
58
|
-
assert(umask === 0o666);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('Positive: Copying a item file when path is absolute', async () => {
|
|
62
|
-
const pfs = new PoweredFileSystem();
|
|
63
|
-
|
|
64
|
-
const cwd = process.cwd();
|
|
65
|
-
const dist = os.tmpdir();
|
|
66
|
-
|
|
67
|
-
await pfs.copy(`${cwd}${sep}tmpdir`, dist, {
|
|
68
|
-
resolve: false
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const { mode } = await pfs.stat(`${dist}/tmpdir/binapp`);
|
|
72
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
73
|
-
|
|
74
|
-
assert(umask === 0o666);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('Negative: Throw if not exists resource', async () => {
|
|
78
|
-
const pfs = new PoweredFileSystem();
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
await pfs.copy('./non-existent', '.');
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
assert(err.errno === -2);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('Negative: An attempt to copy to an existing resource should return an Error', async () => {
|
|
89
|
-
const pfs = new PoweredFileSystem();
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
await pfs.copy('./tmpdir', '.');
|
|
93
|
-
}
|
|
94
|
-
catch (err) {
|
|
95
|
-
assert(err.errno === -17);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe('sync mode', () => {
|
|
100
|
-
it('Positive: Copying a file', async () => {
|
|
101
|
-
const pfs = new PoweredFileSystem();
|
|
102
|
-
const dist = os.tmpdir();
|
|
103
|
-
|
|
104
|
-
pfs.copy('./tmpdir/binapp', dist, {
|
|
105
|
-
sync: true
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const { mode } = await pfs.stat(`${dist}/binapp`);
|
|
109
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
110
|
-
|
|
111
|
-
assert(umask === 0o666);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('Positive: Recursive copying a directory', async () => {
|
|
115
|
-
const pfs = new PoweredFileSystem();
|
|
116
|
-
const dist = os.tmpdir();
|
|
117
|
-
|
|
118
|
-
pfs.copy('./tmpdir', dist, {
|
|
119
|
-
sync: true
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const { mode } = await pfs.stat(`${dist}/tmpdir/libxbase`);
|
|
123
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
124
|
-
|
|
125
|
-
assert(umask === 0o777);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('Positive: Copying a item file when path is absolute', async () => {
|
|
129
|
-
const pfs = new PoweredFileSystem();
|
|
130
|
-
|
|
131
|
-
const cwd = process.cwd();
|
|
132
|
-
const dist = os.tmpdir();
|
|
133
|
-
|
|
134
|
-
pfs.copy(`${cwd}${sep}tmpdir`, dist, {
|
|
135
|
-
sync: true,
|
|
136
|
-
resolve: false
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
const { mode } = await pfs.stat(`${dist}/tmpdir/binapp`);
|
|
140
|
-
const umask = PoweredFileSystem.bitmask(mode);
|
|
141
|
-
|
|
142
|
-
assert(umask === 0o666);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('Negative: Throw if not exists resource', async () => {
|
|
146
|
-
const pfs = new PoweredFileSystem();
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
pfs.copy('./non-existent', '.', {
|
|
150
|
-
sync: true
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
catch (err) {
|
|
154
|
-
assert(err.errno === -2);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('Negative: An attempt to copy to an existing resource should return an Error', async () => {
|
|
159
|
-
const pfs = new PoweredFileSystem();
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
pfs.copy('./tmpdir', '.', {
|
|
163
|
-
sync: true
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
catch (err) {
|
|
167
|
-
assert(err.errno === -17);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|
package/test/mkdir.spec.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import { sep } from 'path';
|
|
4
|
-
import mockFs from 'mock-fs';
|
|
5
|
-
import Chance from 'chance';
|
|
6
|
-
import PoweredFileSystem from '../src';
|
|
7
|
-
|
|
8
|
-
describe('mkdir(src [, options])', () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
const chance = new Chance();
|
|
11
|
-
|
|
12
|
-
mockFs({
|
|
13
|
-
'tmpdir': {
|
|
14
|
-
'binapp': chance.string(),
|
|
15
|
-
'libxbase': mockFs.directory()
|
|
16
|
-
},
|
|
17
|
-
'flexapp': mockFs.symlink({
|
|
18
|
-
path: 'tmpdir/binapp'
|
|
19
|
-
})
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
afterEach(mockFs.restore);
|
|
24
|
-
|
|
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}`);
|
|
33
|
-
assert(exist);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it(`Positive: Make current directory`, async () => {
|
|
37
|
-
const pfs = new PoweredFileSystem('./tmpdir');
|
|
38
|
-
|
|
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('.');
|
|
51
|
-
assert(exist);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
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();
|
|
59
|
-
|
|
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);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
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
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const exist = await pfs.test(`${tmpdir}${sep}${base}`);
|
|
80
|
-
assert(exist);
|
|
81
|
-
});
|
|
82
|
-
|
|
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
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
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}`, {
|
|
105
|
-
sync: true
|
|
106
|
-
});
|
|
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('.', {
|
|
116
|
-
sync: true
|
|
117
|
-
});
|
|
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
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|