pwd-fs 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/package.json +4 -4
  2. package/tsconfig.json +2 -2
  3. package/lib/test/__fmock.d.ts +0 -5
  4. package/lib/test/__fmock.js +0 -40
  5. package/lib/test/append.spec.d.ts +0 -1
  6. package/lib/test/append.spec.js +0 -58
  7. package/lib/test/bitmask.spec.d.ts +0 -1
  8. package/lib/test/bitmask.spec.js +0 -26
  9. package/lib/test/chmod.spec.d.ts +0 -1
  10. package/lib/test/chmod.spec.js +0 -62
  11. package/lib/test/chown.spec.d.ts +0 -1
  12. package/lib/test/chown.spec.js +0 -74
  13. package/lib/test/constructor.spec.d.ts +0 -1
  14. package/lib/test/constructor.spec.js +0 -17
  15. package/lib/test/copy.spec.d.ts +0 -1
  16. package/lib/test/copy.spec.js +0 -80
  17. package/lib/test/mkdir.spec.d.ts +0 -1
  18. package/lib/test/mkdir.spec.js +0 -90
  19. package/lib/test/read.spec.d.ts +0 -1
  20. package/lib/test/read.spec.js +0 -73
  21. package/lib/test/readdir.spec.d.ts +0 -1
  22. package/lib/test/readdir.spec.js +0 -70
  23. package/lib/test/remove.spec.d.ts +0 -1
  24. package/lib/test/remove.spec.js +0 -63
  25. package/lib/test/rename.spec.d.ts +0 -1
  26. package/lib/test/rename.spec.js +0 -66
  27. package/lib/test/stat.spec.d.ts +0 -1
  28. package/lib/test/stat.spec.js +0 -76
  29. package/lib/test/symlink.spec.d.ts +0 -1
  30. package/lib/test/symlink.spec.js +0 -74
  31. package/lib/test/test.spec.d.ts +0 -1
  32. package/lib/test/test.spec.js +0 -60
  33. package/lib/test/write.spec.d.ts +0 -1
  34. package/lib/test/write.spec.js +0 -82
  35. /package/{lib → dist}/src/bitmask.d.ts +0 -0
  36. /package/{lib → dist}/src/bitmask.js +0 -0
  37. /package/{lib → dist}/src/index.d.ts +0 -0
  38. /package/{lib → dist}/src/index.js +0 -0
  39. /package/{lib → dist}/src/powered-file-system.d.ts +0 -0
  40. /package/{lib → dist}/src/powered-file-system.js +0 -0
  41. /package/{lib → dist}/src/recurse-io-sync.d.ts +0 -0
  42. /package/{lib → dist}/src/recurse-io-sync.js +0 -0
  43. /package/{lib → dist}/src/recurse-io.d.ts +0 -0
  44. /package/{lib → dist}/src/recurse-io.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pwd-fs",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "Extend the file system the capabilities of declaring the present working directory and recursive execution",
5
5
  "keywords": [
6
6
  "umask",
@@ -29,11 +29,11 @@
29
29
  "engines": {
30
30
  "node": ">=13.2.0"
31
31
  },
32
- "main": "./lib/src/index.js",
33
- "types": "./lib/src/index.d.ts",
32
+ "main": "./dist/src/index.js",
33
+ "types": "./dist/src/index.d.ts",
34
34
  "scripts": {
35
35
  "build": "tsc",
36
- "test": "mocha ./lib/test"
36
+ "test": "mocha ./dist/test"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/chance": "^1.1.6",
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "lib": [
4
4
  "es2022"
5
5
  ],
6
- "module": "CommonJS",
6
+ "module": "commonjs",
7
7
  "target": "es2022",
8
8
  "moduleResolution": "node",
9
9
  "resolveJsonModule": true,
@@ -14,6 +14,6 @@
14
14
  "declaration": true,
15
15
  "noEmitOnError": true,
16
16
  "noUnusedLocals": false,
17
- "outDir": "lib"
17
+ "outDir": "dist"
18
18
  }
19
19
  }
@@ -1,5 +0,0 @@
1
- export interface Iframe {
2
- [key: string]: any;
3
- }
4
- export declare function fmock(frame: Iframe): void;
5
- export declare function restore(tmpDir: string): void;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.restore = exports.fmock = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- function fmock(frame) {
10
- for (const src of Object.keys(frame)) {
11
- const { dir } = node_path_1.default.parse(src);
12
- const value = frame[src];
13
- node_fs_1.default.mkdirSync(dir, { recursive: true });
14
- if (value.type === 'directory') {
15
- node_fs_1.default.mkdirSync(src);
16
- }
17
- if (value.type === 'file') {
18
- node_fs_1.default.writeFileSync(src, value.data);
19
- }
20
- if (value.type === 'symlink') {
21
- node_fs_1.default.symlinkSync(value.target, src);
22
- }
23
- }
24
- }
25
- exports.fmock = fmock;
26
- function restore(tmpDir) {
27
- const removeRecursive = (src) => {
28
- if (node_fs_1.default.existsSync(src)) {
29
- node_fs_1.default.readdirSync(src).forEach((item) => {
30
- const curl = `${src}/${item}`;
31
- node_fs_1.default.lstatSync(curl).isDirectory()
32
- ? removeRecursive(curl)
33
- : node_fs_1.default.unlinkSync(curl);
34
- });
35
- node_fs_1.default.rmdirSync(src);
36
- }
37
- };
38
- removeRecursive(tmpDir);
39
- }
40
- exports.restore = restore;
@@ -1 +0,0 @@
1
- export {};
@@ -1,58 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const chance_1 = __importDefault(require("chance"));
9
- const expect_1 = require("expect");
10
- const __fmock_1 = require("./__fmock");
11
- const src_1 = require("../src");
12
- describe('append(src, data [, options])', () => {
13
- const chance = new chance_1.default();
14
- beforeEach(() => {
15
- (0, __fmock_1.fmock)({
16
- './tmpdir/tings.txt': {
17
- type: 'file',
18
- data: 'hoodie'
19
- }
20
- });
21
- });
22
- afterEach(() => {
23
- (0, __fmock_1.restore)('./tmpdir');
24
- });
25
- it('Positive: Must append content to file', async () => {
26
- const payload = chance.paragraph();
27
- await src_1.pfs.append('./tmpdir/tings.txt', payload);
28
- const { size } = node_fs_1.default.statSync('./tmpdir/tings.txt');
29
- (0, node_assert_1.default)(payload.length + 6 === size);
30
- });
31
- it(`Negative: Unexpected option 'flag' returns Error`, async () => {
32
- const payload = chance.paragraph();
33
- await (0, expect_1.expect)(async () => {
34
- await src_1.pfs.append('./tmpdir/tings.txt', payload, {
35
- flag: 'r'
36
- });
37
- })
38
- .rejects
39
- .toThrow();
40
- });
41
- it(`[sync] Positive: Must append content to file`, () => {
42
- const payload = chance.paragraph();
43
- src_1.pfs.append('./tmpdir/tings.txt', payload, {
44
- sync: true
45
- });
46
- const { size } = node_fs_1.default.statSync('./tmpdir/tings.txt');
47
- (0, node_assert_1.default)(payload.length + 6 === size);
48
- });
49
- it(`[sync] Negative: Unexpected option 'flag' returns Error`, () => {
50
- const payload = chance.paragraph();
51
- node_assert_1.default.throws(() => {
52
- src_1.pfs.append('./tmpdir/tings.txt', payload, {
53
- sync: true,
54
- flag: 'r'
55
- });
56
- });
57
- });
58
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const src_1 = require("../src");
8
- describe('static bitmask(mode: number)', () => {
9
- it('Positive: Calculate bitmask', () => {
10
- (0, node_assert_1.default)((0, src_1.bitmask)(33024) === 0o400); // (r--------)
11
- (0, node_assert_1.default)((0, src_1.bitmask)(33152) === 0o600); // (rw-------)
12
- (0, node_assert_1.default)((0, src_1.bitmask)(33216) === 0o700); // (rwx------)
13
- (0, node_assert_1.default)((0, src_1.bitmask)(32800) === 0o040); // (---r-----)
14
- (0, node_assert_1.default)((0, src_1.bitmask)(32816) === 0o060); // (---rw----)
15
- (0, node_assert_1.default)((0, src_1.bitmask)(32824) === 0o070); // (---rwx---)
16
- (0, node_assert_1.default)((0, src_1.bitmask)(32772) === 0o004); // (------r--)
17
- (0, node_assert_1.default)((0, src_1.bitmask)(32774) === 0o006); // (------rw-)
18
- (0, node_assert_1.default)((0, src_1.bitmask)(32775) === 0o007); // (------rwx)
19
- });
20
- it(`Negative: Throw an exception if the argument is 'null' type`, () => {
21
- node_assert_1.default.throws(() => {
22
- // @ts-ignore
23
- (0, src_1.bitmask)(null);
24
- });
25
- });
26
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const chance_1 = __importDefault(require("chance"));
9
- const expect_1 = require("expect");
10
- const __fmock_1 = require("./__fmock");
11
- const src_1 = require("../src");
12
- describe('chmod(src, mode [, options])', () => {
13
- const chance = new chance_1.default();
14
- beforeEach(() => {
15
- (0, __fmock_1.fmock)({
16
- './tmpdir/tings.txt': {
17
- type: 'file',
18
- data: chance.string()
19
- }
20
- });
21
- });
22
- afterEach(() => {
23
- (0, __fmock_1.restore)('./tmpdir');
24
- });
25
- it('Positive: Changes directory and file permissions', async () => {
26
- await src_1.pfs.chmod('./tmpdir', 0o744);
27
- const { mode } = node_fs_1.default.lstatSync('./tmpdir/tings.txt');
28
- const umask = (0, src_1.bitmask)(mode);
29
- (0, node_assert_1.default)(umask === 0o744);
30
- });
31
- it('Negative: Throw if not exists resource', async () => {
32
- await (0, expect_1.expect)(async () => {
33
- await src_1.pfs.chmod('./non-existent-source', 0o744);
34
- })
35
- .rejects
36
- .toThrow();
37
- });
38
- it(`[sync] Positive: Changes permissions of directory`, () => {
39
- src_1.pfs.chmod('./tmpdir', 0o744, {
40
- sync: true
41
- });
42
- const { mode } = node_fs_1.default.lstatSync('./tmpdir');
43
- const umask = (0, src_1.bitmask)(mode);
44
- (0, node_assert_1.default)(umask === 0o744);
45
- });
46
- it(`[sync] Positive: Changes file permissions`, () => {
47
- src_1.pfs.chmod('./tmpdir', 0o744, {
48
- sync: true
49
- });
50
- const { mode } = node_fs_1.default.lstatSync('./tmpdir/tings.txt');
51
- const umask = (0, src_1.bitmask)(mode);
52
- (0, node_assert_1.default)(umask === 0o744);
53
- });
54
- it('[sync] Negative: Throw if not exists resource', () => {
55
- const guid = chance.guid();
56
- node_assert_1.default.throws(() => {
57
- src_1.pfs.chmod(`./${guid}`, 0o744, {
58
- sync: true
59
- });
60
- });
61
- });
62
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const chance_1 = __importDefault(require("chance"));
9
- const expect_1 = require("expect");
10
- const __fmock_1 = require("./__fmock");
11
- const src_1 = require("../src");
12
- describe('chown(src, [, options])', () => {
13
- const chance = new chance_1.default();
14
- beforeEach(() => {
15
- (0, __fmock_1.fmock)({
16
- './tmpdir/tings.txt': {
17
- type: 'file',
18
- data: chance.string()
19
- },
20
- './tmpdir/digest/': { type: 'directory' }
21
- });
22
- });
23
- afterEach(() => {
24
- (0, __fmock_1.restore)('./tmpdir');
25
- });
26
- it('Positive: Changes the permissions of a file', async () => {
27
- const { uid, gid } = node_fs_1.default.statSync('./tmpdir/tings.txt');
28
- await src_1.pfs.chown('./tmpdir/tings.txt', { uid, gid });
29
- (0, node_assert_1.default)(uid && gid);
30
- });
31
- it('Positive: Changes the permissions of a directory', async () => {
32
- const { uid, gid } = node_fs_1.default.statSync('./tmpdir/digest');
33
- await src_1.pfs.chown('./tmpdir/digest', { uid, gid });
34
- (0, node_assert_1.default)(uid && gid);
35
- });
36
- it('Negative: To a non-existent resource to return an Error', async () => {
37
- const guid = chance.guid();
38
- const { uid, gid } = node_fs_1.default.statSync('./tmpdir/tings.txt');
39
- await (0, expect_1.expect)(async () => {
40
- await src_1.pfs.chown(`./tmpdir/${guid}`, { uid, gid });
41
- })
42
- .rejects
43
- .toThrow();
44
- });
45
- it('[sync] Positive: Changes the permissions of a file', () => {
46
- const { uid, gid } = node_fs_1.default.statSync('./tmpdir/tings.txt');
47
- src_1.pfs.chown('./tmpdir/tings.txt', {
48
- sync: true,
49
- uid,
50
- gid
51
- });
52
- (0, node_assert_1.default)(uid && gid);
53
- });
54
- it('[sync] Positive: Changes the permissions of a directory', () => {
55
- const { uid, gid } = node_fs_1.default.statSync('./tmpdir/digest');
56
- src_1.pfs.chown('./tmpdir/digest', {
57
- sync: true,
58
- uid,
59
- gid
60
- });
61
- (0, node_assert_1.default)(uid && gid);
62
- });
63
- it('[sync] Negative: To a non-existent resource to return an Error', () => {
64
- const guid = chance.guid();
65
- const { uid, gid } = node_fs_1.default.statSync('./tmpdir/tings.txt');
66
- node_assert_1.default.throws(() => {
67
- src_1.pfs.chown(`./tmpdir/${guid}`, {
68
- sync: true,
69
- uid,
70
- gid
71
- });
72
- });
73
- });
74
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const src_1 = require("../src");
8
- describe('#constructor: new PoweredFileSystem(pwd?)', () => {
9
- it('Positive: An empty path must match the context of the cwd', () => {
10
- const { pwd } = new src_1.PoweredFileSystem();
11
- (0, node_assert_1.default)(pwd === process.cwd());
12
- });
13
- it('Positive: Absolute path must match the context of the pwd', () => {
14
- const { pwd } = new src_1.PoweredFileSystem(__dirname);
15
- (0, node_assert_1.default)(pwd === __dirname);
16
- });
17
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const chance_1 = __importDefault(require("chance"));
9
- const expect_1 = require("expect");
10
- const __fmock_1 = require("./__fmock");
11
- const src_1 = require("../src");
12
- describe('copy(src, dir [, options])', () => {
13
- const chance = new chance_1.default();
14
- beforeEach(() => {
15
- (0, __fmock_1.fmock)({
16
- './tmpdir/tings.txt': {
17
- type: 'file',
18
- data: chance.string()
19
- },
20
- './tmpdir/digest/': { type: 'directory' }
21
- });
22
- });
23
- afterEach(() => {
24
- (0, __fmock_1.restore)('./tmpdir');
25
- });
26
- it('Positive: Copying a item file', async () => {
27
- await src_1.pfs.copy('./tmpdir/tings.txt', './tmpdir/digest');
28
- const exist = node_fs_1.default.existsSync(`./tmpdir/digest/tings.txt`);
29
- (0, node_assert_1.default)(exist);
30
- });
31
- it('Positive: Recursive copying a directory', async () => {
32
- await src_1.pfs.copy('./src', './tmpdir');
33
- const exist = node_fs_1.default.existsSync(`./tmpdir/src`);
34
- (0, node_assert_1.default)(exist);
35
- });
36
- it('Negative: Throw if not exists resource', async () => {
37
- const guid = chance.guid();
38
- await (0, expect_1.expect)(async () => {
39
- await src_1.pfs.copy(`./${guid}`, '.');
40
- })
41
- .rejects
42
- .toThrow();
43
- });
44
- it('Negative: An attempt to copy to an existing resource should return an Error', async () => {
45
- await (0, expect_1.expect)(async () => {
46
- await src_1.pfs.copy('./tmpdir', '.');
47
- })
48
- .rejects
49
- .toThrow();
50
- });
51
- it('[sync] Positive: Copying a file', () => {
52
- src_1.pfs.copy('./tmpdir/tings.txt', './tmpdir/digest', {
53
- sync: true
54
- });
55
- const exist = node_fs_1.default.existsSync(`./tmpdir/digest/tings.txt`);
56
- (0, node_assert_1.default)(exist);
57
- });
58
- it('[sync] Positive: Recursive copying a directory', () => {
59
- src_1.pfs.copy('./src', './tmpdir', {
60
- sync: true
61
- });
62
- const exist = node_fs_1.default.existsSync(`./tmpdir/src`);
63
- (0, node_assert_1.default)(exist);
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.copy(`./${guid}`, '.', {
69
- sync: true
70
- });
71
- });
72
- });
73
- it('[sync] Negative: An attempt to copy to an existing resource should return an Error', () => {
74
- node_assert_1.default.throws(() => {
75
- src_1.pfs.copy('./tmpdir', '.', {
76
- sync: true
77
- });
78
- });
79
- });
80
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,90 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const chance_1 = __importDefault(require("chance"));
9
- const expect_1 = require("expect");
10
- const __fmock_1 = require("./__fmock");
11
- const src_1 = require("../src");
12
- describe('mkdir(src [, options])', () => {
13
- const pfs = new src_1.PoweredFileSystem();
14
- const chance = new chance_1.default();
15
- beforeEach(() => {
16
- (0, __fmock_1.fmock)({
17
- './tmpdir/tings.txt': {
18
- type: 'file',
19
- data: chance.string()
20
- }
21
- });
22
- });
23
- afterEach(() => {
24
- (0, __fmock_1.restore)('./tmpdir');
25
- });
26
- it('Positive: Create directories in the working directory', async () => {
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);
31
- });
32
- it(`Positive: Make current directory`, async () => {
33
- const guid = chance.guid();
34
- const pfs = new src_1.PoweredFileSystem(`./tmpdir/${guid}`);
35
- await pfs.mkdir('.');
36
- const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
37
- (0, node_assert_1.default)(exist);
38
- });
39
- it('Positive: Should work fine with the existing directory', async () => {
40
- const guid = chance.guid();
41
- for (let i = 2; i; i--) {
42
- await pfs.mkdir(`./tmpdir/${guid}`);
43
- }
44
- const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
45
- (0, node_assert_1.default)(exist);
46
- });
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
59
- });
60
- const exist = node_fs_1.default.existsSync(`./tmpdir/${guid}`);
61
- (0, node_assert_1.default)(exist);
62
- });
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);
71
- });
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}`, {
76
- sync: true
77
- });
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}`, {
86
- sync: true
87
- });
88
- });
89
- });
90
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const chance_1 = __importDefault(require("chance"));
8
- const expect_1 = require("expect");
9
- const __fmock_1 = require("./__fmock");
10
- const src_1 = require("../src");
11
- describe('read(src [, options])', () => {
12
- const chance = new chance_1.default();
13
- let sentences = 0;
14
- beforeEach(() => {
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
- });
23
- });
24
- afterEach(() => {
25
- (0, __fmock_1.restore)('./tmpdir');
26
- });
27
- it('Positive: Must read content of file; String type by default', async () => {
28
- const { length } = await src_1.pfs.read('./tmpdir/tings.txt');
29
- (0, node_assert_1.default)(length === sentences);
30
- });
31
- it('Positive: Must read Buffer content of file when encoding is null', async () => {
32
- const buffer = await src_1.pfs.read('./tmpdir/tings.txt', {
33
- encoding: null
34
- });
35
- (0, node_assert_1.default)(buffer instanceof Buffer);
36
- });
37
- it('Negative: Throw if resource is not file', async () => {
38
- await (0, expect_1.expect)(async () => {
39
- await src_1.pfs.read(`./tmpdir`);
40
- })
41
- .rejects
42
- .toThrow();
43
- });
44
- it('Negative: Throw if not exists resource', async () => {
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();
51
- });
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
55
- });
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
62
- });
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
70
- });
71
- });
72
- });
73
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,70 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const chance_1 = __importDefault(require("chance"));
8
- const expect_1 = require("expect");
9
- const __fmock_1 = require("./__fmock");
10
- const src_1 = require("../src");
11
- describe('readdir(src[, options])', () => {
12
- const chance = new chance_1.default();
13
- let counter = 0;
14
- beforeEach(() => {
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);
26
- });
27
- afterEach(() => {
28
- (0, __fmock_1.restore)('./tmpdir');
29
- });
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);
33
- });
34
- it('Negative: Throw if resource is not directory', async () => {
35
- await (0, expect_1.expect)(async () => {
36
- await src_1.pfs.readdir(`./tmpdir/tings.txt`);
37
- })
38
- .rejects
39
- .toThrow();
40
- });
41
- it('Negative: Throw if not exists resource', async () => {
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();
48
- });
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`, {
58
- sync: true
59
- });
60
- });
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
67
- });
68
- });
69
- });
70
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const chance_1 = __importDefault(require("chance"));
9
- const expect_1 = require("expect");
10
- const __fmock_1 = require("./__fmock");
11
- const src_1 = require("../src");
12
- describe('remove(src [, options])', () => {
13
- const chance = new chance_1.default();
14
- beforeEach(() => {
15
- const cwd = process.cwd();
16
- const frame = {
17
- './tmpdir/tings.txt': {
18
- type: 'file',
19
- data: chance.string()
20
- },
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);
31
- });
32
- afterEach(() => {
33
- (0, __fmock_1.restore)('./tmpdir');
34
- });
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
- });
40
- it('Negative: Throw if not exists resource', async () => {
41
- const guid = chance.guid();
42
- await (0, expect_1.expect)(async () => {
43
- await src_1.pfs.remove(`./${guid}`);
44
- })
45
- .rejects
46
- .toThrow();
47
- });
48
- it('[sync] Positive: Removal a directory with a file', () => {
49
- src_1.pfs.remove('./tmpdir', {
50
- sync: true
51
- });
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
60
- });
61
- });
62
- });
63
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const chance_1 = __importDefault(require("chance"));
9
- const expect_1 = require("expect");
10
- const __fmock_1 = require("./__fmock");
11
- const src_1 = require("../src");
12
- describe('rename(src, use [, options])', () => {
13
- const chance = new chance_1.default();
14
- beforeEach(() => {
15
- (0, __fmock_1.fmock)({
16
- './tmpdir/tings.txt': {
17
- type: 'file',
18
- data: chance.string()
19
- },
20
- './tmpdir/digest/': { type: 'directory' }
21
- });
22
- });
23
- afterEach(() => {
24
- (0, __fmock_1.restore)('./tmpdir');
25
- });
26
- it('Positive: Must be recursive rename file', async () => {
27
- await src_1.pfs.rename('./tmpdir/tings.txt', './tmpdir/newapp.txt');
28
- const exist = node_fs_1.default.existsSync(`./tmpdir/newapp.txt`);
29
- (0, node_assert_1.default)(exist);
30
- });
31
- it('Positive: Must be recursive rename directory', async () => {
32
- await src_1.pfs.rename('./tmpdir/digest', './tmpdir/newxbase');
33
- const exist = node_fs_1.default.existsSync(`./tmpdir/newxbase`);
34
- (0, node_assert_1.default)(exist);
35
- });
36
- it('Negative: Throw if not exists resource', async () => {
37
- const guid = chance.guid();
38
- await (0, expect_1.expect)(async () => {
39
- await src_1.pfs.rename(`./tmpdir/${guid}`, './tmpdir/newxbase');
40
- })
41
- .rejects
42
- .toThrow();
43
- });
44
- it('[sync] Positive: Must be recursive rename file', () => {
45
- src_1.pfs.rename('./tmpdir/tings.txt', './tmpdir/newapp.txt', {
46
- sync: true
47
- });
48
- const exist = node_fs_1.default.existsSync(`./tmpdir/newapp.txt`);
49
- (0, node_assert_1.default)(exist);
50
- });
51
- it('[sync] Positive: Must be recursive rename directory', () => {
52
- src_1.pfs.rename('./tmpdir/digest', './tmpdir/newxbase', {
53
- sync: true
54
- });
55
- const exist = node_fs_1.default.existsSync(`./tmpdir/newxbase`);
56
- (0, node_assert_1.default)(exist);
57
- });
58
- it('[sync] Negative: Throw if not exists resource', () => {
59
- const guid = chance.guid();
60
- node_assert_1.default.throws(() => {
61
- src_1.pfs.rename(`./tmpdir/${guid}`, './tmpdir/newxbase', {
62
- sync: true
63
- });
64
- });
65
- });
66
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const chance_1 = __importDefault(require("chance"));
8
- const expect_1 = require("expect");
9
- const __fmock_1 = require("./__fmock");
10
- const src_1 = require("../src");
11
- describe('stat(src [, options])', () => {
12
- const chance = new chance_1.default();
13
- beforeEach(() => {
14
- const cwd = process.cwd();
15
- (0, __fmock_1.fmock)({
16
- './tmpdir/tings.txt': {
17
- type: 'file',
18
- data: chance.string()
19
- },
20
- './tmpdir/digest/': { type: 'directory' },
21
- './tmpdir/flexapp': {
22
- type: 'symlink',
23
- target: `${cwd}/tmpdir/tings.txt`
24
- }
25
- });
26
- });
27
- afterEach(() => {
28
- (0, __fmock_1.restore)('./tmpdir');
29
- });
30
- it('Positive: Must return information a file', async () => {
31
- const stats = await src_1.pfs.stat('./tmpdir/tings.txt');
32
- (0, node_assert_1.default)(stats.isFile());
33
- });
34
- it('Positive: Must return information a directory', async () => {
35
- const stats = await src_1.pfs.stat('./tmpdir/digest');
36
- (0, node_assert_1.default)(stats.isDirectory());
37
- });
38
- it('Positive: Must return information a symlink', async () => {
39
- const stats = await src_1.pfs.stat('./tmpdir/flexapp');
40
- (0, node_assert_1.default)(stats.isSymbolicLink());
41
- });
42
- it('Negative: Throw if not exists resource', async () => {
43
- const guid = chance.guid();
44
- await (0, expect_1.expect)(async () => {
45
- await src_1.pfs.stat(`./tmpdir/${guid}`);
46
- })
47
- .rejects
48
- .toThrow();
49
- });
50
- it('[sync] Positive: Must return information a file', () => {
51
- const stats = src_1.pfs.stat('./tmpdir/tings.txt', {
52
- sync: true
53
- });
54
- (0, node_assert_1.default)(stats.isFile());
55
- });
56
- it('[sync] Positive: Must return information a directory in ', () => {
57
- const stats = src_1.pfs.stat('./tmpdir/digest', {
58
- sync: true
59
- });
60
- (0, node_assert_1.default)(stats.isDirectory());
61
- });
62
- it('[sync] Positive: Must return information a symlink', () => {
63
- const stats = src_1.pfs.stat('./tmpdir/flexapp', {
64
- sync: true
65
- });
66
- (0, node_assert_1.default)(stats.isSymbolicLink());
67
- });
68
- it('[sync] Negative: Throw if not exists resource', () => {
69
- const guid = chance.guid();
70
- node_assert_1.default.throws(() => {
71
- src_1.pfs.stat(`./tmpdir/${guid}`, {
72
- sync: true
73
- });
74
- });
75
- });
76
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const chance_1 = __importDefault(require("chance"));
9
- const expect_1 = require("expect");
10
- const __fmock_1 = require("./__fmock");
11
- const src_1 = require("../src");
12
- describe('symlink(src, use [, options])', () => {
13
- const chance = new chance_1.default();
14
- beforeEach(() => {
15
- const cwd = process.cwd();
16
- const frame = {
17
- './tmpdir/tings.txt': {
18
- type: 'file',
19
- data: chance.string()
20
- },
21
- './tmpdir/digest/': { type: 'directory' },
22
- './tmpdir/flexapp': {
23
- type: 'symlink',
24
- target: `${cwd}/tmpdir/tings.txt`
25
- }
26
- };
27
- const counter = chance.natural({ max: 7 });
28
- for (let i = 0; i < counter; i++) {
29
- frame[`./tmpdir/${i}`] = { type: 'directory' };
30
- }
31
- (0, __fmock_1.fmock)(frame);
32
- });
33
- afterEach(() => {
34
- (0, __fmock_1.restore)('./tmpdir');
35
- });
36
- it('Positive: Must be created a symbolic link', async () => {
37
- await src_1.pfs.symlink('./tmpdir/tings.txt', './tmpdir/linkapp');
38
- const stat = node_fs_1.default.lstatSync('./tmpdir/linkapp');
39
- (0, node_assert_1.default)(stat.isSymbolicLink());
40
- });
41
- it('Positive: Must be created a symbolic link for directory', async () => {
42
- await src_1.pfs.symlink('./tmpdir/digest', './tmpdir/linkapp');
43
- const stat = node_fs_1.default.lstatSync('./tmpdir/linkapp');
44
- (0, node_assert_1.default)(stat.isSymbolicLink());
45
- });
46
- it('Negative: Throw if destination already exists', async () => {
47
- await (0, expect_1.expect)(async () => {
48
- await src_1.pfs.symlink('./tmpdir/tings.txt', './tmpdir/flexapp');
49
- })
50
- .rejects
51
- .toThrow();
52
- });
53
- it('[sync] Positive: Must be created a symbolic link', () => {
54
- src_1.pfs.symlink('./tmpdir/tings.txt', './tmpdir/linkapp', {
55
- sync: true
56
- });
57
- const stat = node_fs_1.default.lstatSync('./tmpdir/linkapp');
58
- (0, node_assert_1.default)(stat.isSymbolicLink());
59
- });
60
- it('[sync] Positive: Must be created a symbolic link for directory', () => {
61
- src_1.pfs.symlink('./tmpdir/digest', './tmpdir/linkapp', {
62
- sync: true
63
- });
64
- const stat = node_fs_1.default.lstatSync('./tmpdir/linkapp');
65
- (0, node_assert_1.default)(stat.isSymbolicLink());
66
- });
67
- it('[sync] Negative: Throw if destination already exists', () => {
68
- node_assert_1.default.throws(() => {
69
- src_1.pfs.symlink('./tmpdir/tings.txt', './tmpdir/flexapp', {
70
- sync: true
71
- });
72
- });
73
- });
74
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const chance_1 = __importDefault(require("chance"));
8
- const __fmock_1 = require("./__fmock");
9
- const src_1 = require("../src");
10
- describe('test(src[, options])', () => {
11
- const chance = new chance_1.default();
12
- beforeEach(() => {
13
- (0, __fmock_1.fmock)({
14
- './tmpdir/tings.txt': {
15
- type: 'file',
16
- data: chance.string()
17
- },
18
- './tmpdir/digest/': { type: 'directory' }
19
- });
20
- });
21
- afterEach(() => {
22
- (0, __fmock_1.restore)('./tmpdir');
23
- });
24
- it(`Positive: Should return 'true' for current working directory`, async () => {
25
- const exist = await src_1.pfs.test('.');
26
- (0, node_assert_1.default)(exist);
27
- });
28
- it(`Positive: For existing file should return 'true'`, async () => {
29
- const exist = await src_1.pfs.test('./tmpdir/tings.txt');
30
- (0, node_assert_1.default)(exist);
31
- });
32
- it(`Positive: For existing directory should return 'true'`, async () => {
33
- const exist = await src_1.pfs.test('./tmpdir/digest');
34
- (0, node_assert_1.default)(exist);
35
- });
36
- it(`Positive: A non-existent file must return 'false'`, async () => {
37
- const guid = chance.guid();
38
- const exist = await src_1.pfs.test(`./tmpdir/${guid}`);
39
- (0, node_assert_1.default)(exist === false);
40
- });
41
- it(`Positive: For existing file should return 'true'`, () => {
42
- const exist = src_1.pfs.test('./tmpdir/tings.txt', {
43
- sync: true
44
- });
45
- (0, node_assert_1.default)(exist);
46
- });
47
- it(`[sync] Positive: For existing directory should return 'true'`, () => {
48
- const exist = src_1.pfs.test('./tmpdir/digest', {
49
- sync: true
50
- });
51
- (0, node_assert_1.default)(exist);
52
- });
53
- it(`[sync] Positive: A non-existent file must return 'false'`, () => {
54
- const guid = chance.guid();
55
- const exist = src_1.pfs.test(`./tmpdir/${guid}`, {
56
- sync: true
57
- });
58
- (0, node_assert_1.default)(exist === false);
59
- });
60
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,82 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_assert_1 = __importDefault(require("node:assert"));
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const chance_1 = __importDefault(require("chance"));
9
- const expect_1 = require("expect");
10
- const __fmock_1 = require("./__fmock");
11
- const src_1 = require("../src");
12
- describe('write(src, data[, options])', () => {
13
- const chance = new chance_1.default();
14
- beforeEach(() => {
15
- (0, __fmock_1.fmock)({
16
- './tmpdir/tings.txt': {
17
- type: 'file',
18
- data: chance.string()
19
- }
20
- });
21
- });
22
- afterEach(() => {
23
- (0, __fmock_1.restore)('./tmpdir');
24
- });
25
- it('Positive: Must write content to file', async () => {
26
- const payload = chance.paragraph();
27
- const guid = chance.guid();
28
- await src_1.pfs.write(`./tmpdir/${guid}.txt`, payload);
29
- const { size } = node_fs_1.default.lstatSync(`./tmpdir/${guid}.txt`);
30
- (0, node_assert_1.default)(payload.length === size);
31
- });
32
- it('Positive: Must rewrite content if file already exists', async () => {
33
- const payload = chance.paragraph();
34
- await src_1.pfs.write('./tmpdir/tings.txt', payload);
35
- const { size } = node_fs_1.default.lstatSync('./tmpdir/tings.txt');
36
- (0, node_assert_1.default)(payload.length === size);
37
- });
38
- it('Negative: Throw if resource is directory', async () => {
39
- const payload = chance.paragraph();
40
- await (0, expect_1.expect)(async () => {
41
- await src_1.pfs.write('./tmpdir', payload);
42
- })
43
- .rejects
44
- .toThrow();
45
- });
46
- it(`Negative: Unexpected option 'flag' returns Error`, async () => {
47
- const payload = chance.paragraph();
48
- await (0, expect_1.expect)(async () => {
49
- await src_1.pfs.write('./tmpdir/tings.txt', payload, {
50
- flag: 'r'
51
- });
52
- })
53
- .rejects
54
- .toThrow();
55
- });
56
- it('[sync] Positive: Write contents even to a non-existent file', () => {
57
- const payload = chance.paragraph();
58
- const guid = chance.guid();
59
- src_1.pfs.write(`./tmpdir/${guid}.txt`, payload, {
60
- sync: true
61
- });
62
- const content = node_fs_1.default.readFileSync(`./tmpdir/${guid}.txt`, 'utf8');
63
- (0, node_assert_1.default)(payload === content);
64
- });
65
- it('[sync] Negative: Throw if resource is directory', () => {
66
- const payload = chance.paragraph();
67
- node_assert_1.default.throws(() => {
68
- src_1.pfs.write('./tmpdir', payload, {
69
- sync: true
70
- });
71
- });
72
- });
73
- it(`[sync] Negative: Unexpected option 'flag' returns Error`, () => {
74
- const payload = chance.paragraph();
75
- node_assert_1.default.throws(() => {
76
- src_1.pfs.write('./tmpdir/tings.txt', payload, {
77
- sync: true,
78
- flag: 'r'
79
- });
80
- });
81
- });
82
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes