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.
Files changed (68) hide show
  1. package/.travis.yml +2 -3
  2. package/appveyor.yml +2 -4
  3. package/lib/src/index.d.ts +4 -186
  4. package/lib/src/index.js +18 -294
  5. package/lib/src/powered-file-system.d.ts +156 -0
  6. package/lib/src/powered-file-system.js +264 -0
  7. package/lib/src/recurse-io-sync.d.ts +10 -5
  8. package/lib/src/recurse-io-sync.js +74 -69
  9. package/lib/src/recurse-io.d.ts +14 -6
  10. package/lib/src/recurse-io.js +164 -160
  11. package/lib/test/__fmock.d.ts +5 -0
  12. package/lib/test/__fmock.js +40 -0
  13. package/lib/test/append.spec.js +36 -77
  14. package/lib/test/bitmask.spec.js +14 -17
  15. package/lib/test/chmod.spec.js +42 -84
  16. package/lib/test/chown.spec.js +45 -71
  17. package/lib/test/constructor.spec.js +7 -10
  18. package/lib/test/copy.spec.js +53 -108
  19. package/lib/test/mkdir.spec.js +62 -119
  20. package/lib/test/read.spec.js +47 -78
  21. package/lib/test/readdir.spec.js +48 -90
  22. package/lib/test/remove.spec.js +44 -65
  23. package/lib/test/rename.spec.js +43 -75
  24. package/lib/test/stat.spec.js +50 -78
  25. package/lib/test/symlink.spec.js +51 -95
  26. package/lib/test/test.spec.js +37 -66
  27. package/lib/test/write.spec.js +52 -103
  28. package/package.json +8 -11
  29. package/readme.md +10 -21
  30. package/src/index.ts +4 -623
  31. package/src/powered-file-system.ts +527 -0
  32. package/src/recurse-io-sync.ts +77 -71
  33. package/src/recurse-io.ts +181 -176
  34. package/test/__fmock.ts +45 -0
  35. package/test/append.spec.ts +44 -98
  36. package/test/bitmask.spec.ts +14 -17
  37. package/test/chmod.spec.ts +45 -95
  38. package/test/chown.spec.ts +61 -93
  39. package/test/constructor.spec.ts +4 -7
  40. package/test/copy.spec.ts +72 -142
  41. package/test/mkdir.spec.ts +87 -153
  42. package/test/read.spec.ts +64 -103
  43. package/test/readdir.spec.ts +65 -113
  44. package/test/remove.spec.ts +58 -82
  45. package/test/rename.spec.ts +58 -96
  46. package/test/stat.spec.ts +68 -100
  47. package/test/symlink.spec.ts +74 -125
  48. package/test/test.spec.ts +51 -84
  49. package/test/write.spec.ts +68 -131
  50. package/tsconfig.json +14 -7
  51. package/lib/src/index.js.map +0 -1
  52. package/lib/src/recurse-io-sync.js.map +0 -1
  53. package/lib/src/recurse-io.js.map +0 -1
  54. package/lib/test/append.spec.js.map +0 -1
  55. package/lib/test/bitmask.spec.js.map +0 -1
  56. package/lib/test/chmod.spec.js.map +0 -1
  57. package/lib/test/chown.spec.js.map +0 -1
  58. package/lib/test/constructor.spec.js.map +0 -1
  59. package/lib/test/copy.spec.js.map +0 -1
  60. package/lib/test/mkdir.spec.js.map +0 -1
  61. package/lib/test/read.spec.js.map +0 -1
  62. package/lib/test/readdir.spec.js.map +0 -1
  63. package/lib/test/remove.spec.js.map +0 -1
  64. package/lib/test/rename.spec.js.map +0 -1
  65. package/lib/test/stat.spec.js.map +0 -1
  66. package/lib/test/symlink.spec.js.map +0 -1
  67. package/lib/test/test.spec.js.map +0 -1
  68. package/lib/test/write.spec.js.map +0 -1
@@ -3,96 +3,64 @@ 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 assert_1 = __importDefault(require("assert"));
7
- const path_1 = require("path");
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 src_1 = __importDefault(require("../src"));
9
+ const expect_1 = require("expect");
10
+ const __fmock_1 = require("./__fmock");
11
+ const src_1 = require("../src");
11
12
  describe('rename(src, use [, options])', () => {
13
+ const chance = new chance_1.default();
12
14
  beforeEach(() => {
13
- const chance = new chance_1.default();
14
- (0, mock_fs_1.default)({
15
- 'tmpdir': {
16
- 'binapp': chance.string(),
17
- 'libxbase': mock_fs_1.default.directory()
15
+ (0, __fmock_1.fmock)({
16
+ './tmpdir/tings.txt': {
17
+ type: 'file',
18
+ data: chance.string()
18
19
  },
19
- 'flexapp': mock_fs_1.default.symlink({
20
- path: 'tmpdir/binapp'
21
- })
20
+ './tmpdir/digest/': { type: 'directory' }
22
21
  });
23
22
  });
24
- afterEach(mock_fs_1.default.restore);
23
+ afterEach(() => {
24
+ (0, __fmock_1.restore)('./tmpdir');
25
+ });
25
26
  it('Positive: Must be recursive rename file', async () => {
26
- const pfs = new src_1.default();
27
- await pfs.rename('./tmpdir/binapp', './tmpdir/newapp');
28
- const exist = await pfs.test('./tmpdir/newapp');
29
- (0, assert_1.default)(exist);
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
30
  });
31
31
  it('Positive: Must be recursive rename directory', async () => {
32
- const pfs = new src_1.default();
33
- await pfs.rename('./tmpdir/libxbase', './tmpdir/newxbase');
34
- const exist = await pfs.test('./tmpdir/newxbase');
35
- (0, assert_1.default)(exist);
36
- });
37
- it('Positive: Must be recursive rename directory, when path is absolute', async () => {
38
- const pfs = new src_1.default();
39
- const cwd = process.cwd();
40
- await pfs.rename(`${cwd}${path_1.sep}tmpdir`, `${cwd}${path_1.sep}newxbase`, {
41
- resolve: false
42
- });
43
- const exist = await pfs.test('./newxbase');
44
- (0, assert_1.default)(exist);
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);
45
35
  });
46
36
  it('Negative: Throw if not exists resource', async () => {
47
- const pfs = new src_1.default();
48
- const chance = new chance_1.default();
49
- const base = chance.guid();
50
- try {
51
- await pfs.rename(`./${base}`, './tmpdir/newapp');
52
- }
53
- catch (err) {
54
- (0, assert_1.default)(err.errno === -2);
55
- }
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();
56
43
  });
57
- describe('sync mode', () => {
58
- it('Positive: Must be recursive rename file', async () => {
59
- const pfs = new src_1.default();
60
- pfs.rename('./tmpdir/binapp', './tmpdir/newapp', {
61
- sync: true
62
- });
63
- const exist = await pfs.test('./tmpdir/newapp');
64
- (0, assert_1.default)(exist);
44
+ it('[sync] Positive: Must be recursive rename file', () => {
45
+ src_1.pfs.rename('./tmpdir/tings.txt', './tmpdir/newapp.txt', {
46
+ sync: true
65
47
  });
66
- it('Positive: Must be recursive rename directory', async () => {
67
- const pfs = new src_1.default();
68
- pfs.rename('./tmpdir/libxbase', './tmpdir/newxbase', {
69
- sync: true
70
- });
71
- const exist = await pfs.test('./tmpdir/newxbase');
72
- (0, assert_1.default)(exist);
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
73
54
  });
74
- it('Positive: Must be recursive rename directory, when path is absolute', async () => {
75
- const pfs = new src_1.default();
76
- const cwd = process.cwd();
77
- pfs.rename(`${cwd}${path_1.sep}tmpdir`, `${cwd}${path_1.sep}newxbase`, {
78
- sync: true,
79
- resolve: false
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
80
63
  });
81
- const exist = await pfs.test('./newxbase');
82
- (0, assert_1.default)(exist);
83
- });
84
- it('Negative: Throw if not exists resource', async () => {
85
- const pfs = new src_1.default();
86
- const chance = new chance_1.default();
87
- const base = chance.guid();
88
- try {
89
- pfs.rename(`./${base}`, './tmpdir/newapp', {
90
- sync: true
91
- });
92
- }
93
- catch (err) {
94
- (0, assert_1.default)(err.errno === -2);
95
- }
96
64
  });
97
65
  });
98
66
  });
@@ -3,102 +3,74 @@ 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 assert_1 = __importDefault(require("assert"));
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 src_1 = __importDefault(require("../src"));
8
+ const expect_1 = require("expect");
9
+ const __fmock_1 = require("./__fmock");
10
+ const src_1 = require("../src");
11
11
  describe('stat(src [, options])', () => {
12
+ const chance = new chance_1.default();
12
13
  beforeEach(() => {
13
- const chance = new chance_1.default();
14
- (0, mock_fs_1.default)({
15
- 'tmpdir': {
16
- 'binapp': chance.string(),
17
- 'libxbase': mock_fs_1.default.directory()
14
+ const cwd = process.cwd();
15
+ (0, __fmock_1.fmock)({
16
+ './tmpdir/tings.txt': {
17
+ type: 'file',
18
+ data: chance.string()
18
19
  },
19
- 'flexapp': mock_fs_1.default.symlink({
20
- path: 'tmpdir/binapp'
21
- })
20
+ './tmpdir/digest/': { type: 'directory' },
21
+ './tmpdir/flexapp': {
22
+ type: 'symlink',
23
+ target: `${cwd}/tmpdir/tings.txt`
24
+ }
22
25
  });
23
26
  });
24
- afterEach(mock_fs_1.default.restore);
27
+ afterEach(() => {
28
+ (0, __fmock_1.restore)('./tmpdir');
29
+ });
25
30
  it('Positive: Must return information a file', async () => {
26
- const pfs = new src_1.default();
27
- const stats = await pfs.stat('./tmpdir/binapp');
28
- (0, assert_1.default)(stats.isFile());
31
+ const stats = await src_1.pfs.stat('./tmpdir/tings.txt');
32
+ (0, node_assert_1.default)(stats.isFile());
29
33
  });
30
34
  it('Positive: Must return information a directory', async () => {
31
- const pfs = new src_1.default();
32
- const stats = await pfs.stat('./tmpdir/libxbase');
33
- (0, assert_1.default)(stats.isDirectory());
35
+ const stats = await src_1.pfs.stat('./tmpdir/digest');
36
+ (0, node_assert_1.default)(stats.isDirectory());
34
37
  });
35
38
  it('Positive: Must return information a symlink', async () => {
36
- const pfs = new src_1.default();
37
- const stats = await pfs.stat('./flexapp');
38
- (0, assert_1.default)(stats.isSymbolicLink());
39
- });
40
- it('Positive: Must return stats information, when path is absolute', async () => {
41
- const pfs = new src_1.default();
42
- const cwd = process.cwd();
43
- const stats = await pfs.stat(`${cwd}${path_1.sep}tmpdir`, {
44
- resolve: false
45
- });
46
- (0, assert_1.default)(stats.isDirectory());
39
+ const stats = await src_1.pfs.stat('./tmpdir/flexapp');
40
+ (0, node_assert_1.default)(stats.isSymbolicLink());
47
41
  });
48
42
  it('Negative: Throw if not exists resource', async () => {
49
- const pfs = new src_1.default();
50
- const chance = new chance_1.default();
51
- const base = chance.guid();
52
- try {
53
- await pfs.stat(`./${base}`);
54
- }
55
- catch (err) {
56
- (0, assert_1.default)(err.errno === -2);
57
- }
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();
58
49
  });
59
- describe('sync mode', () => {
60
- it('Positive: Must return information a file', async () => {
61
- const pfs = new src_1.default();
62
- const stats = pfs.stat('./tmpdir/binapp', {
63
- sync: true
64
- });
65
- (0, assert_1.default)(stats.isFile());
50
+ it('[sync] Positive: Must return information a file', () => {
51
+ const stats = src_1.pfs.stat('./tmpdir/tings.txt', {
52
+ sync: true
66
53
  });
67
- it('Positive: Must return information a directory in ', async () => {
68
- const pfs = new src_1.default();
69
- const stats = pfs.stat('./tmpdir/libxbase', {
70
- sync: true
71
- });
72
- (0, assert_1.default)(stats.isDirectory());
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
73
59
  });
74
- it('Positive: Must return information a symlink', async () => {
75
- const pfs = new src_1.default();
76
- const stats = pfs.stat('./flexapp', {
77
- sync: true
78
- });
79
- (0, assert_1.default)(stats.isSymbolicLink());
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
80
65
  });
81
- it('Positive: Must return stats information, when path is absolute', async () => {
82
- const pfs = new src_1.default();
83
- const cwd = process.cwd();
84
- const stats = pfs.stat(`${cwd}${path_1.sep}tmpdir`, {
85
- sync: true,
86
- resolve: false
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
87
73
  });
88
- (0, assert_1.default)(stats.isDirectory());
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.stat(`./${base}`, {
96
- sync: true
97
- });
98
- }
99
- catch (err) {
100
- (0, assert_1.default)(err.errno === -2);
101
- }
102
74
  });
103
75
  });
104
76
  });
@@ -3,116 +3,72 @@ 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 assert_1 = __importDefault(require("assert"));
7
- const path_1 = require("path");
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 src_1 = __importDefault(require("../src"));
9
+ const expect_1 = require("expect");
10
+ const __fmock_1 = require("./__fmock");
11
+ const src_1 = require("../src");
11
12
  describe('symlink(src, use [, options])', () => {
13
+ const chance = new chance_1.default();
12
14
  beforeEach(() => {
13
- const chance = new chance_1.default();
14
- (0, mock_fs_1.default)({
15
- 'tmpdir': {
16
- 'binapp': chance.string(),
17
- 'libxbase': mock_fs_1.default.directory()
15
+ const cwd = process.cwd();
16
+ const frame = {
17
+ './tmpdir/tings.txt': {
18
+ type: 'file',
19
+ data: chance.string()
18
20
  },
19
- 'flexapp': mock_fs_1.default.symlink({
20
- path: 'tmpdir/binapp'
21
- })
22
- });
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');
23
35
  });
24
- afterEach(mock_fs_1.default.restore);
25
36
  it('Positive: Must be created a symbolic link', async () => {
26
- const pfs = new src_1.default();
27
- await pfs.symlink('./tmpdir/binapp', './linkapp');
28
- const stats = await pfs.stat('./linkapp');
29
- (0, assert_1.default)(stats.isSymbolicLink());
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());
30
40
  });
31
41
  it('Positive: Must be created a symbolic link for directory', async () => {
32
- const pfs = new src_1.default();
33
- await pfs.symlink(`./tmpdir/libxbase`, './linkapp');
34
- const stats = await pfs.stat('./linkapp');
35
- (0, assert_1.default)(stats.isSymbolicLink());
36
- });
37
- it('Positive: Must be created a symbolic, when path is absolute', async () => {
38
- const pfs = new src_1.default();
39
- const cwd = process.cwd();
40
- await pfs.symlink(`${cwd}${path_1.sep}tmpdir${path_1.sep}libxbase`, `${cwd}${path_1.sep}linkapp`, {
41
- resolve: false
42
- });
43
- const stats = await pfs.stat('./linkapp');
44
- (0, assert_1.default)(stats.isSymbolicLink());
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
45
  });
46
46
  it('Negative: Throw if destination already exists', async () => {
47
- const pfs = new src_1.default();
48
- try {
49
- await pfs.symlink(`./flexapp`, './tmpdir/binapp');
50
- }
51
- catch (err) {
52
- (0, assert_1.default)(err.errno === -17);
53
- }
47
+ await (0, expect_1.expect)(async () => {
48
+ await src_1.pfs.symlink('./tmpdir/tings.txt', './tmpdir/flexapp');
49
+ })
50
+ .rejects
51
+ .toThrow();
54
52
  });
55
- it('Negative: Throw if not exists resource', async () => {
56
- const pfs = new src_1.default();
57
- const chance = new chance_1.default();
58
- const base = chance.guid();
59
- try {
60
- await pfs.symlink(`./${base}`, './linkapp');
61
- }
62
- catch (err) {
63
- (0, assert_1.default)(err.errno === -2);
64
- }
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());
65
59
  });
66
- describe('sync mode', () => {
67
- it('Positive: Must be created a symbolic link', async () => {
68
- const pfs = new src_1.default();
69
- pfs.symlink('./tmpdir/binapp', './linkapp', {
70
- sync: true
71
- });
72
- const stats = await pfs.stat('./linkapp');
73
- (0, assert_1.default)(stats.isSymbolicLink());
60
+ it('[sync] Positive: Must be created a symbolic link for directory', () => {
61
+ src_1.pfs.symlink('./tmpdir/digest', './tmpdir/linkapp', {
62
+ sync: true
74
63
  });
75
- it('Positive: Must be created a symbolic link for directory', async () => {
76
- const pfs = new src_1.default();
77
- pfs.symlink(`./tmpdir/libxbase`, './linkapp', {
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', {
78
70
  sync: true
79
71
  });
80
- const stats = await pfs.stat('./linkapp');
81
- (0, assert_1.default)(stats.isSymbolicLink());
82
- });
83
- it('Positive: Must be created a symbolic, when path is absolute', async () => {
84
- const pfs = new src_1.default();
85
- const cwd = process.cwd();
86
- pfs.symlink(`${cwd}${path_1.sep}tmpdir${path_1.sep}libxbase`, `${cwd}${path_1.sep}linkapp`, {
87
- sync: true,
88
- resolve: false
89
- });
90
- const stats = await pfs.stat('./linkapp');
91
- (0, assert_1.default)(stats.isSymbolicLink());
92
- });
93
- it('Negative: Throw if destination already exists', async () => {
94
- const pfs = new src_1.default();
95
- try {
96
- pfs.symlink(`./flexapp`, './tmpdir/binapp', {
97
- sync: true
98
- });
99
- }
100
- catch (err) {
101
- (0, assert_1.default)(err.errno === -17);
102
- }
103
- });
104
- it('Negative: Throw if not exists resource', async () => {
105
- const pfs = new src_1.default();
106
- const chance = new chance_1.default();
107
- const base = chance.guid();
108
- try {
109
- pfs.symlink(`./${base}`, './linkapp', {
110
- sync: true
111
- });
112
- }
113
- catch (err) {
114
- (0, assert_1.default)(err.errno === -2);
115
- }
116
72
  });
117
73
  });
118
74
  });
@@ -3,87 +3,58 @@ 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 assert_1 = __importDefault(require("assert"));
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 src_1 = __importDefault(require("../src"));
8
+ const __fmock_1 = require("./__fmock");
9
+ const src_1 = require("../src");
11
10
  describe('test(src[, options])', () => {
11
+ const chance = new chance_1.default();
12
12
  beforeEach(() => {
13
- const chance = new chance_1.default();
14
- (0, mock_fs_1.default)({
15
- 'tmpdir': {
16
- 'binapp': chance.string(),
17
- 'libxbase': mock_fs_1.default.directory()
13
+ (0, __fmock_1.fmock)({
14
+ './tmpdir/tings.txt': {
15
+ type: 'file',
16
+ data: chance.string()
18
17
  },
19
- 'flexapp': mock_fs_1.default.symlink({
20
- path: 'tmpdir/binapp'
21
- })
18
+ './tmpdir/digest/': { type: 'directory' }
22
19
  });
23
20
  });
24
- afterEach(mock_fs_1.default.restore);
25
- it(`Positive: Should return 'true' for current working directory`, async () => {
26
- const pfs = new src_1.default();
27
- const exist = await pfs.test('.');
28
- (0, assert_1.default)(exist);
21
+ afterEach(() => {
22
+ (0, __fmock_1.restore)('./tmpdir');
29
23
  });
30
- it(`Positive: For existing directory should return 'true'`, async () => {
31
- const pfs = new src_1.default();
32
- const exist = await pfs.test('./tmpdir/libxbase');
33
- (0, assert_1.default)(exist);
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);
34
27
  });
35
28
  it(`Positive: For existing file should return 'true'`, async () => {
36
- const pfs = new src_1.default();
37
- const exist = await pfs.test('./tmpdir/binapp');
38
- (0, assert_1.default)(exist);
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);
39
35
  });
40
36
  it(`Positive: A non-existent file must return 'false'`, async () => {
41
- const pfs = new src_1.default();
42
- const chance = new chance_1.default();
43
- const base = chance.guid();
44
- const exists = await pfs.test(`./${base}`);
45
- (0, assert_1.default)(exists === false);
37
+ const guid = chance.guid();
38
+ const exist = await src_1.pfs.test(`./tmpdir/${guid}`);
39
+ (0, node_assert_1.default)(exist === false);
46
40
  });
47
- it(`Positive: Should return 'true' for absolute source`, async () => {
48
- const pfs = new src_1.default();
49
- const cwd = process.cwd();
50
- const exists = await pfs.test(`${cwd}${path_1.sep}tmpdir`, {
51
- resolve: false
41
+ it(`Positive: For existing file should return 'true'`, () => {
42
+ const exist = src_1.pfs.test('./tmpdir/tings.txt', {
43
+ sync: true
52
44
  });
53
- (0, assert_1.default)(exists);
45
+ (0, node_assert_1.default)(exist);
54
46
  });
55
- describe('sync mode', () => {
56
- it(`Positive: For existing directory should return 'true'`, () => {
57
- const pfs = new src_1.default();
58
- const exist = pfs.test('./tmpdir/libxbase', {
59
- sync: true
60
- });
61
- (0, assert_1.default)(exist);
62
- });
63
- it(`Positive: For existing file should return 'true'`, () => {
64
- const pfs = new src_1.default();
65
- const exist = pfs.test('./tmpdir/binapp', {
66
- sync: true
67
- });
68
- (0, assert_1.default)(exist);
47
+ it(`[sync] Positive: For existing directory should return 'true'`, () => {
48
+ const exist = src_1.pfs.test('./tmpdir/digest', {
49
+ sync: true
69
50
  });
70
- it(`Positive: A non-existent file must return 'false'`, async () => {
71
- const pfs = new src_1.default();
72
- const chance = new chance_1.default();
73
- const base = chance.guid();
74
- const exists = pfs.test(`./${base}`, {
75
- sync: true
76
- });
77
- (0, assert_1.default)(exists === false);
78
- });
79
- it(`Positive: Should return 'true' for absolute source`, async () => {
80
- const pfs = new src_1.default();
81
- const cwd = process.cwd();
82
- const exists = pfs.test(`${cwd}${path_1.sep}tmpdir`, {
83
- sync: true,
84
- resolve: false
85
- });
86
- (0, assert_1.default)(exists);
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
87
57
  });
58
+ (0, node_assert_1.default)(exist === false);
88
59
  });
89
60
  });