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