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/.travis.yml
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export interface Iframe {
|
|
5
|
+
[key: string]: any
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function fmock(frame: Iframe) {
|
|
9
|
+
for (const src of Object.keys(frame)) {
|
|
10
|
+
const { dir } = path.parse(src);
|
|
11
|
+
const value = frame[src];
|
|
12
|
+
|
|
13
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
14
|
+
|
|
15
|
+
if (value.type === 'directory') {
|
|
16
|
+
fs.mkdirSync(src);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (value.type === 'file') {
|
|
20
|
+
fs.writeFileSync(src, value.data);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (value.type === 'symlink') {
|
|
24
|
+
fs.symlinkSync(value.target, src);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function restore(tmpDir: string) {
|
|
30
|
+
const removeRecursive = (src: string) => {
|
|
31
|
+
if (fs.existsSync(src)) {
|
|
32
|
+
fs.readdirSync(src).forEach((item) => {
|
|
33
|
+
const curl = `${src}/${item}`;
|
|
34
|
+
|
|
35
|
+
fs.lstatSync(curl).isDirectory()
|
|
36
|
+
? removeRecursive(curl)
|
|
37
|
+
: fs.unlinkSync(curl);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
fs.rmdirSync(src);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
removeRecursive(tmpDir);
|
|
45
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { sep } from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import Chance from 'chance';
|
|
5
|
+
import { fmock, restore } from './__fmock';
|
|
6
|
+
import PoweredFileSystem from '../src';
|
|
7
|
+
|
|
8
|
+
describe('append(src, data [, options])', () => {
|
|
9
|
+
const pfs = new PoweredFileSystem();
|
|
10
|
+
const chance = new Chance();
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
fmock({
|
|
14
|
+
'./tmpdir/tings.txt': {
|
|
15
|
+
type: 'file',
|
|
16
|
+
data: 'hoodie'
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
restore('./tmpdir');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
it('Positive: Must append content to file', async () => {
|
|
27
|
+
const payload = chance.paragraph();
|
|
28
|
+
|
|
29
|
+
await pfs.append('./tmpdir/tings.txt', payload);
|
|
30
|
+
const { size } = fs.statSync('./tmpdir/tings.txt');
|
|
31
|
+
|
|
32
|
+
assert(payload.length + 6 === size);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
it(`Negative: Unexpected option 'flag' returns Error`, async () => {
|
|
37
|
+
const payload = chance.paragraph();
|
|
38
|
+
|
|
39
|
+
await expect(async () => {
|
|
40
|
+
await pfs.append('./tmpdir/tings.txt', payload, {
|
|
41
|
+
flag: 'r'
|
|
42
|
+
});
|
|
43
|
+
})
|
|
44
|
+
.rejects
|
|
45
|
+
.toThrow();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
it(`[sync] Positive: Must append content to file`, () => {
|
|
50
|
+
const payload = chance.paragraph();
|
|
51
|
+
|
|
52
|
+
pfs.append('./tmpdir/tings.txt', payload, {
|
|
53
|
+
sync: true
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const { size } = fs.statSync('./tmpdir/tings.txt');
|
|
57
|
+
|
|
58
|
+
assert(payload.length + 6 === size);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
it(`[sync] Negative: Unexpected option 'flag' returns Error`, () => {
|
|
63
|
+
const payload = chance.paragraph();
|
|
64
|
+
|
|
65
|
+
assert.throws(() => {
|
|
66
|
+
pfs.append('./tmpdir/tings.txt', payload, {
|
|
67
|
+
sync: true,
|
|
68
|
+
flag: 'r'
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { bitmask } from '../src';
|
|
3
|
+
|
|
4
|
+
describe('static bitmask(mode: number)', () => {
|
|
5
|
+
it('Positive: Calculate bitmask', () => {
|
|
6
|
+
assert(bitmask(33024) === 0o400); // (r--------)
|
|
7
|
+
assert(bitmask(33152) === 0o600); // (rw-------)
|
|
8
|
+
assert(bitmask(33216) === 0o700); // (rwx------)
|
|
9
|
+
assert(bitmask(32800) === 0o040); // (---r-----)
|
|
10
|
+
assert(bitmask(32816) === 0o060); // (---rw----)
|
|
11
|
+
assert(bitmask(32824) === 0o070); // (---rwx---)
|
|
12
|
+
assert(bitmask(32772) === 0o004); // (------r--)
|
|
13
|
+
assert(bitmask(32774) === 0o006); // (------rw-)
|
|
14
|
+
assert(bitmask(32775) === 0o007); // (------rwx)
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it(`Negative: Throw an exception if the argument is 'null' type`, () => {
|
|
18
|
+
assert.throws(() => {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
bitmask(null);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { sep } from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import Chance from 'chance';
|
|
5
|
+
import { fmock, restore } from './__fmock';
|
|
6
|
+
import PoweredFileSystem, { bitmask } from '../src';
|
|
7
|
+
|
|
8
|
+
describe('chmod(src, mode [, options])', () => {
|
|
9
|
+
const pfs = new PoweredFileSystem();
|
|
10
|
+
const chance = new Chance();
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
fmock({
|
|
14
|
+
'./tmpdir/tings.txt': {
|
|
15
|
+
type: 'file',
|
|
16
|
+
data: chance.string()
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
restore('./tmpdir');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
it('Positive: Changes directory and file permissions', async () => {
|
|
27
|
+
await pfs.chmod('./tmpdir', 0o744);
|
|
28
|
+
|
|
29
|
+
const { mode } = fs.lstatSync('./tmpdir/tings.txt');
|
|
30
|
+
const umask = bitmask(mode);
|
|
31
|
+
|
|
32
|
+
assert(umask === 0o744);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
it('Negative: Throw if not exists resource', async () => {
|
|
37
|
+
await expect(async () => {
|
|
38
|
+
await pfs.chmod('./non-existent-source', 0o744);
|
|
39
|
+
})
|
|
40
|
+
.rejects
|
|
41
|
+
.toThrow();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
it(`[sync] Positive: Changes permissions of directory`, () => {
|
|
46
|
+
pfs.chmod('./tmpdir', 0o744, {
|
|
47
|
+
sync: true
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const { mode } = fs.lstatSync('./tmpdir');
|
|
51
|
+
const umask = bitmask(mode);
|
|
52
|
+
|
|
53
|
+
assert(umask === 0o744);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
it(`[sync] Positive: Changes file permissions`, () => {
|
|
58
|
+
pfs.chmod('./tmpdir', 0o744, {
|
|
59
|
+
sync: true
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const { mode } = fs.lstatSync('./tmpdir/tings.txt');
|
|
63
|
+
const umask = bitmask(mode);
|
|
64
|
+
|
|
65
|
+
assert(umask === 0o744);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
it('[sync] Negative: Throw if not exists resource', () => {
|
|
70
|
+
const guid = chance.guid();
|
|
71
|
+
|
|
72
|
+
assert.throws(() => {
|
|
73
|
+
pfs.chmod(`./${guid}`, 0o744, {
|
|
74
|
+
sync: true
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import Chance from 'chance';
|
|
4
|
+
import { fmock, restore } from './__fmock';
|
|
5
|
+
import PoweredFileSystem from '../src';
|
|
6
|
+
|
|
7
|
+
describe('chown(src, uid, gid [, options])', () => {
|
|
8
|
+
const pfs = new PoweredFileSystem();
|
|
9
|
+
const chance = new Chance();
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
fmock({
|
|
13
|
+
'./tmpdir/tings.txt': {
|
|
14
|
+
type: 'file',
|
|
15
|
+
data: chance.string()
|
|
16
|
+
},
|
|
17
|
+
'./tmpdir/digest/': { type: 'directory' }
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
restore('./tmpdir');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
it('Positive: Changes the permissions of a file', async () => {
|
|
27
|
+
const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
|
|
28
|
+
|
|
29
|
+
await pfs.chown('./tmpdir/tings.txt', uid, gid);
|
|
30
|
+
|
|
31
|
+
assert(uid && gid);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
it('Positive: Changes the permissions of a directory', async () => {
|
|
36
|
+
const { uid, gid } = fs.statSync('./tmpdir/digest');
|
|
37
|
+
|
|
38
|
+
await pfs.chown('./tmpdir/digest', uid, gid);
|
|
39
|
+
|
|
40
|
+
assert(uid && gid);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
it('Negative: To a non-existent resource to return an Error', async () => {
|
|
45
|
+
const guid = chance.guid();
|
|
46
|
+
const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
|
|
47
|
+
|
|
48
|
+
await expect(async () => {
|
|
49
|
+
await pfs.chown(`./tmpdir/${guid}`, uid, gid);
|
|
50
|
+
})
|
|
51
|
+
.rejects
|
|
52
|
+
.toThrow();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
it('[sync] Positive: Changes the permissions of a file', () => {
|
|
57
|
+
const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
|
|
58
|
+
|
|
59
|
+
pfs.chown('./tmpdir/tings.txt', uid, gid, {
|
|
60
|
+
sync: true
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
assert(uid && gid);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
it('[sync] Positive: Changes the permissions of a directory', () => {
|
|
68
|
+
const { uid, gid } = fs.statSync('./tmpdir/digest');
|
|
69
|
+
|
|
70
|
+
pfs.chown('./tmpdir/digest', uid, gid, {
|
|
71
|
+
sync: true
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
assert(uid && gid);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
it('[sync] Negative: To a non-existent resource to return an Error', () => {
|
|
79
|
+
const guid = chance.guid();
|
|
80
|
+
const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
|
|
81
|
+
|
|
82
|
+
assert.throws(() => {
|
|
83
|
+
pfs.chown(`./tmpdir/${guid}`, uid, gid, {
|
|
84
|
+
sync: true
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
1
|
+
import assert from 'node:assert';
|
|
2
2
|
import PoweredFileSystem from '../src';
|
|
3
3
|
|
|
4
|
-
describe('#constructor: new PoweredFileSystem(
|
|
5
|
-
it('Positive: Must be backwards compatible with #require', () => {
|
|
6
|
-
assert(require('../src') === PoweredFileSystem);
|
|
7
|
-
});
|
|
8
|
-
|
|
4
|
+
describe('#constructor: new PoweredFileSystem(pwd?)', () => {
|
|
9
5
|
it('Positive: An empty path must match the context of the cwd', () => {
|
|
10
6
|
const { pwd } = new PoweredFileSystem();
|
|
11
7
|
assert(pwd === process.cwd());
|
|
12
8
|
});
|
|
13
9
|
|
|
10
|
+
|
|
14
11
|
it('Positive: Absolute path must match the context of the pwd', () => {
|
|
15
12
|
const { pwd } = new PoweredFileSystem(__dirname);
|
|
16
13
|
assert(pwd === __dirname);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { sep } from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import Chance from 'chance';
|
|
5
|
+
import { fmock, restore } from './__fmock';
|
|
6
|
+
import PoweredFileSystem, { bitmask } from '../src';
|
|
7
|
+
|
|
8
|
+
describe('copy(src, dir [, options])', () => {
|
|
9
|
+
const pfs = new PoweredFileSystem();
|
|
10
|
+
const chance = new Chance();
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
fmock({
|
|
14
|
+
'./tmpdir/tings.txt': {
|
|
15
|
+
type: 'file',
|
|
16
|
+
data: chance.string()
|
|
17
|
+
},
|
|
18
|
+
'./tmpdir/digest/': { type: 'directory' }
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
restore('./tmpdir');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('Positive: Copying a item file', async () => {
|
|
27
|
+
await pfs.copy('./tmpdir/tings.txt', './tmpdir/digest');
|
|
28
|
+
const exist = fs.existsSync(`./tmpdir/digest/tings.txt`);
|
|
29
|
+
|
|
30
|
+
assert(exist);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
it('Positive: Recursive copying a directory', async () => {
|
|
35
|
+
await pfs.copy('./src', './tmpdir');
|
|
36
|
+
const exist = fs.existsSync(`./tmpdir/src`);
|
|
37
|
+
|
|
38
|
+
assert(exist);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
it('Negative: Throw if not exists resource', async () => {
|
|
43
|
+
const guid = chance.guid();
|
|
44
|
+
|
|
45
|
+
await expect(async () => {
|
|
46
|
+
await pfs.copy(`./${guid}`, '.');
|
|
47
|
+
})
|
|
48
|
+
.rejects
|
|
49
|
+
.toThrow();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
it('Negative: An attempt to copy to an existing resource should return an Error', async () => {
|
|
54
|
+
await expect(async () => {
|
|
55
|
+
await pfs.copy('./tmpdir', '.');
|
|
56
|
+
})
|
|
57
|
+
.rejects
|
|
58
|
+
.toThrow();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
it('[sync] Positive: Copying a file', () => {
|
|
63
|
+
pfs.copy('./tmpdir/tings.txt', './tmpdir/digest', {
|
|
64
|
+
sync: true
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const exist = fs.existsSync(`./tmpdir/digest/tings.txt`);
|
|
68
|
+
|
|
69
|
+
assert(exist);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
it('[sync] Positive: Recursive copying a directory', () => {
|
|
74
|
+
pfs.copy('./src', './tmpdir', {
|
|
75
|
+
sync: true
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const exist = fs.existsSync(`./tmpdir/src`);
|
|
79
|
+
|
|
80
|
+
assert(exist);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
it('[sync] Negative: Throw if not exists resource', () => {
|
|
85
|
+
const guid = chance.guid();
|
|
86
|
+
|
|
87
|
+
assert.throws(() => {
|
|
88
|
+
pfs.copy(`./${guid}`, '.', {
|
|
89
|
+
sync: true
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
it('[sync] Negative: An attempt to copy to an existing resource should return an Error', () => {
|
|
96
|
+
assert.throws(() => {
|
|
97
|
+
pfs.copy('./tmpdir', '.', {
|
|
98
|
+
sync: true
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import Chance from 'chance';
|
|
4
|
+
import { fmock, restore } from './__fmock';
|
|
5
|
+
import PoweredFileSystem from '../src';
|
|
6
|
+
|
|
7
|
+
describe('mkdir(src [, options])', () => {
|
|
8
|
+
const pfs = new PoweredFileSystem();
|
|
9
|
+
const chance = new Chance();
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
fmock({
|
|
13
|
+
'./tmpdir/tings.txt': {
|
|
14
|
+
type: 'file',
|
|
15
|
+
data: chance.string()
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
restore('./tmpdir');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('Positive: Create directories in the working directory', async () => {
|
|
25
|
+
const guid = chance.guid();
|
|
26
|
+
|
|
27
|
+
await pfs.mkdir(`./tmpdir/${guid}`);
|
|
28
|
+
const exist = fs.existsSync(`./tmpdir/${guid}`);
|
|
29
|
+
|
|
30
|
+
assert(exist);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
it(`Positive: Make current directory`, async () => {
|
|
35
|
+
const guid = chance.guid();
|
|
36
|
+
const pfs = new PoweredFileSystem(`./tmpdir/${guid}`);
|
|
37
|
+
|
|
38
|
+
await pfs.mkdir('.');
|
|
39
|
+
const exist = fs.existsSync(`./tmpdir/${guid}`);
|
|
40
|
+
|
|
41
|
+
assert(exist);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
it('Positive: Should work fine with the existing directory', async () => {
|
|
46
|
+
const guid = chance.guid();
|
|
47
|
+
|
|
48
|
+
for (let i = 2; i; i--) {
|
|
49
|
+
await pfs.mkdir(`./tmpdir/${guid}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const exist = fs.existsSync(`./tmpdir/${guid}`);
|
|
53
|
+
|
|
54
|
+
assert(exist);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
it('Negative: Throw an exception if trying to create a directory in file', async () => {
|
|
59
|
+
const guid = chance.guid();
|
|
60
|
+
|
|
61
|
+
await expect(async () => {
|
|
62
|
+
await pfs.mkdir(`./tmpdir/tings.txt/${guid}`);
|
|
63
|
+
})
|
|
64
|
+
.rejects
|
|
65
|
+
.toThrow();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
it('Positive: Create directories in the working directory', () => {
|
|
70
|
+
const guid = chance.guid();
|
|
71
|
+
|
|
72
|
+
pfs.mkdir(`./tmpdir/${guid}`, {
|
|
73
|
+
sync: true
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const exist = fs.existsSync(`./tmpdir/${guid}`);
|
|
77
|
+
|
|
78
|
+
assert(exist);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
it('[sync] Positive: Make current directory', () => {
|
|
83
|
+
const guid = chance.guid();
|
|
84
|
+
const pfs = new PoweredFileSystem(`./tmpdir/${guid}`);
|
|
85
|
+
|
|
86
|
+
pfs.mkdir('.', {
|
|
87
|
+
sync: true
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const exist = fs.existsSync(`./tmpdir/${guid}`);
|
|
91
|
+
|
|
92
|
+
assert(exist);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
it('[sync] Positive: Should work fine with the existing directory', () => {
|
|
97
|
+
const guid = chance.guid();
|
|
98
|
+
|
|
99
|
+
for (let i = 2; i; i--) {
|
|
100
|
+
pfs.mkdir(`./tmpdir/${guid}`, {
|
|
101
|
+
sync: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const exist = fs.existsSync(`./tmpdir/${guid}`);
|
|
106
|
+
|
|
107
|
+
assert(exist);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
it('[sync] Negative: Throw an exception if trying to create a directory in file', () => {
|
|
112
|
+
const guid = chance.guid();
|
|
113
|
+
|
|
114
|
+
assert.throws(() => {
|
|
115
|
+
pfs.mkdir(`./tmpdir/tings.txt/${guid}`, {
|
|
116
|
+
sync: true
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import Chance from 'chance';
|
|
4
|
+
import { fmock, restore } from './__fmock';
|
|
5
|
+
import PoweredFileSystem from '../src';
|
|
6
|
+
|
|
7
|
+
describe('read(src [, options])', () => {
|
|
8
|
+
const pfs = new PoweredFileSystem();
|
|
9
|
+
const chance = new Chance();
|
|
10
|
+
let sentences = 0;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
const tingsContent = chance.paragraph();
|
|
14
|
+
sentences = tingsContent.length;
|
|
15
|
+
|
|
16
|
+
fmock({
|
|
17
|
+
'./tmpdir/tings.txt': {
|
|
18
|
+
type: 'file',
|
|
19
|
+
data: tingsContent
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
restore('./tmpdir');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('Positive: Must read content of file; String type by default', async () => {
|
|
29
|
+
const { length } = await pfs.read('./tmpdir/tings.txt');
|
|
30
|
+
|
|
31
|
+
assert(length === sentences);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
it('Positive: Must read Buffer content of file when encoding is null', async () => {
|
|
36
|
+
const buffer = await pfs.read('./tmpdir/tings.txt', {
|
|
37
|
+
encoding: null
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
assert(buffer instanceof Buffer);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
it('Negative: Throw if resource is not file', async () => {
|
|
45
|
+
await expect(async () => {
|
|
46
|
+
await pfs.read(`./tmpdir`);
|
|
47
|
+
})
|
|
48
|
+
.rejects
|
|
49
|
+
.toThrow();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
it('Negative: Throw if not exists resource', async () => {
|
|
54
|
+
const guid = chance.guid();
|
|
55
|
+
|
|
56
|
+
await expect(async () => {
|
|
57
|
+
await pfs.read(`./tmpdir/${guid}`);
|
|
58
|
+
})
|
|
59
|
+
.rejects
|
|
60
|
+
.toThrow();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
it('[sync] Positive: Must read content of file; String type by default', () => {
|
|
65
|
+
const { length } = pfs.read('./tmpdir/tings.txt', {
|
|
66
|
+
sync: true
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
assert(length === sentences);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
it('[sync] Positive: Must read Buffer content of file when encoding is null', () => {
|
|
74
|
+
const buffer = pfs.read('./tmpdir/tings.txt', {
|
|
75
|
+
encoding: null,
|
|
76
|
+
sync: true
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
assert(buffer instanceof Buffer);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
it(`[sync] Negative: Throw if not exists resource`, () => {
|
|
84
|
+
const guid = chance.guid();
|
|
85
|
+
|
|
86
|
+
assert.throws(() => {
|
|
87
|
+
pfs.read(`./tmpdir/${guid}`, {
|
|
88
|
+
sync: true
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|