@zenfs/devel 0.0.1 → 0.1.0

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 (71) hide show
  1. package/dist/bin/zenfs-test.js +3 -2
  2. package/dist/tests/common.js +1 -1
  3. package/dist/tests/fs/append.test.d.ts +1 -0
  4. package/dist/tests/fs/append.test.js +27 -0
  5. package/dist/tests/fs/concurrency.test.d.ts +1 -0
  6. package/dist/tests/fs/concurrency.test.js +76 -0
  7. package/dist/tests/fs/dir.test.d.ts +1 -0
  8. package/dist/tests/fs/dir.test.js +83 -0
  9. package/dist/tests/fs/directory.test.d.ts +1 -0
  10. package/dist/tests/fs/directory.test.js +151 -0
  11. package/dist/tests/fs/errors.test.d.ts +1 -0
  12. package/dist/tests/fs/errors.test.js +141 -0
  13. package/dist/tests/fs/exists.test.d.ts +1 -0
  14. package/dist/tests/fs/exists.test.js +19 -0
  15. package/dist/tests/fs/links.test.d.ts +1 -0
  16. package/dist/tests/fs/links.test.js +248 -0
  17. package/dist/tests/fs/open.test.d.ts +1 -0
  18. package/dist/tests/fs/open.test.js +95 -0
  19. package/dist/tests/fs/permissions.test.d.ts +1 -0
  20. package/dist/tests/fs/permissions.test.js +346 -0
  21. package/dist/tests/fs/read.test.d.ts +1 -0
  22. package/dist/tests/fs/read.test.js +149 -0
  23. package/dist/tests/fs/readFile.test.d.ts +1 -0
  24. package/dist/tests/fs/readFile.test.js +110 -0
  25. package/dist/tests/fs/rename.test.d.ts +1 -0
  26. package/dist/tests/fs/rename.test.js +70 -0
  27. package/dist/tests/fs/scaling.test.d.ts +1 -0
  28. package/dist/tests/fs/scaling.test.js +27 -0
  29. package/dist/tests/fs/stat.test.d.ts +1 -0
  30. package/dist/tests/fs/stat.test.js +93 -0
  31. package/dist/tests/fs/streams.test.d.ts +1 -0
  32. package/dist/tests/fs/streams.test.js +161 -0
  33. package/dist/tests/fs/tempdir.test.d.ts +1 -0
  34. package/dist/tests/fs/tempdir.test.js +118 -0
  35. package/dist/tests/fs/times.test.d.ts +7 -0
  36. package/dist/tests/fs/times.test.js +134 -0
  37. package/dist/tests/fs/truncate.test.d.ts +1 -0
  38. package/dist/tests/fs/truncate.test.js +62 -0
  39. package/dist/tests/fs/watch.test.d.ts +1 -0
  40. package/dist/tests/fs/watch.test.js +320 -0
  41. package/dist/tests/fs/write.test.d.ts +1 -0
  42. package/dist/tests/fs/write.test.js +83 -0
  43. package/dist/tests/fs/xattr.test.d.ts +1 -0
  44. package/dist/tests/fs/xattr.test.js +137 -0
  45. package/dist/tests/setup/memory.d.ts +1 -0
  46. package/dist/tests/setup/memory.js +3 -0
  47. package/package.json +5 -5
  48. package/tests/readme.md +2 -2
  49. package/tests/fs/append.test.ts +0 -34
  50. package/tests/fs/concurrency.test.ts +0 -113
  51. package/tests/fs/dir.test.ts +0 -103
  52. package/tests/fs/directory.test.ts +0 -189
  53. package/tests/fs/errors.test.ts +0 -159
  54. package/tests/fs/exists.test.ts +0 -23
  55. package/tests/fs/links.test.ts +0 -308
  56. package/tests/fs/open.test.ts +0 -23
  57. package/tests/fs/permissions.test.ts +0 -344
  58. package/tests/fs/read.test.ts +0 -94
  59. package/tests/fs/readFile.test.ts +0 -58
  60. package/tests/fs/rename.test.ts +0 -93
  61. package/tests/fs/scaling.test.ts +0 -35
  62. package/tests/fs/stat.test.ts +0 -115
  63. package/tests/fs/streams.test.ts +0 -204
  64. package/tests/fs/tempdir.test.ts +0 -64
  65. package/tests/fs/times.test.ts +0 -85
  66. package/tests/fs/truncate.test.ts +0 -89
  67. package/tests/fs/watch.test.ts +0 -246
  68. package/tests/fs/write.test.ts +0 -118
  69. package/tests/fs/xattr.test.ts +0 -96
  70. package/tests/setup/memory.ts +0 -3
  71. package/tests/tsconfig.json +0 -8
@@ -1,34 +0,0 @@
1
- // SPDX-License-Identifier: LGPL-3.0-or-later
2
- import assert from 'node:assert/strict';
3
- import { suite, test } from 'node:test';
4
- import { fs, config } from '@zenfs/devel/tests/common';
5
-
6
- const content = 'Sample content',
7
- original = 'ABCD';
8
-
9
- suite('Appends', config('appends'), () => {
10
- test('Create an empty file and add content', config('async'), async () => {
11
- const filename = 'append.txt';
12
- await fs.promises.appendFile(filename, content);
13
- const data = await fs.promises.readFile(filename, 'utf8');
14
- assert.equal(data, content);
15
- });
16
-
17
- test('Append data to a non-empty file', config('async'), async () => {
18
- const filename = 'append2.txt';
19
-
20
- await fs.promises.writeFile(filename, original);
21
- await fs.promises.appendFile(filename, content);
22
- const data = await fs.promises.readFile(filename, 'utf8');
23
- assert.equal(data, original + content);
24
- });
25
-
26
- test('Append a buffer to the file', config('async'), async () => {
27
- const filename = 'append3.txt';
28
-
29
- await fs.promises.writeFile(filename, original);
30
- await fs.promises.appendFile(filename, content);
31
- const data = await fs.promises.readFile(filename, 'utf8');
32
- assert.equal(data, original + content);
33
- });
34
- });
@@ -1,113 +0,0 @@
1
- // SPDX-License-Identifier: LGPL-3.0-or-later
2
- import assert from 'node:assert/strict';
3
- import { suite, test } from 'node:test';
4
- import { config, fs } from '@zenfs/devel/tests/common';
5
-
6
- suite('Concurrency', config('write', 'async'), () => {
7
- test('parallel writeFile in the same directory does not lose entries #256', async () => {
8
- await fs.promises.mkdir('/issue-256');
9
-
10
- await Promise.all([fs.promises.writeFile('/issue-256/a1.txt', 'a1'), fs.promises.writeFile('/issue-256/a2.txt', 'a2')]);
11
-
12
- const files = await fs.promises.readdir('/issue-256');
13
- assert.deepEqual(files.sort(), ['a1.txt', 'a2.txt']);
14
- });
15
-
16
- test('concurrent file creation does not lose directory entries #298', async () => {
17
- await fs.promises.mkdir('/issue-298');
18
-
19
- const names = Array.from({ length: 32 }, (_, i) => `file-${i}.txt`);
20
- await Promise.all(names.map(name => fs.promises.writeFile(`/issue-298/${name}`, name)));
21
-
22
- const files = await fs.promises.readdir('/issue-298');
23
- assert.deepEqual(files.sort(), names.sort());
24
- });
25
-
26
- test('open handles for the same file share metadata #287', async () => {
27
- await fs.promises.writeFile('/issue-287.txt', 'Hello World');
28
-
29
- const a = await fs.promises.open('/issue-287.txt', 'r+');
30
- const b = await fs.promises.open('/issue-287.txt', 'r+');
31
-
32
- await a.truncate(5); // contents are now "Hello"
33
- const { size } = await b.stat();
34
- assert.equal(size, 5);
35
-
36
- await a.close();
37
- await b.close();
38
- });
39
-
40
- test('writes are visible to other open handles before syncing', async () => {
41
- const a = await fs.promises.open('/shared-write.txt', 'w+');
42
- const b = await fs.promises.open('/shared-write.txt', 'r');
43
-
44
- await a.write('some shared data');
45
-
46
- const { buffer } = await b.read(new Uint8Array(16), 0, 16, 0);
47
- assert.equal(new TextDecoder().decode(buffer), 'some shared data');
48
-
49
- await a.close();
50
- await b.close();
51
- });
52
-
53
- test('reads concurrent with an overwrite of the same file do not fail #303', async () => {
54
- await fs.promises.writeFile('/issue-303.txt', 'original contents');
55
-
56
- /* Every handle for a file shares one vnode, so closing any of these flushes whatever is dirty.
57
- Syncing took a shared lock, letting several of these run at once and corrupt each other. */
58
- for (let round = 0; round < 20; round++) {
59
- const contents = `rewritten contents for round ${round}`;
60
-
61
- const results = await Promise.allSettled([
62
- ...Array.from({ length: 4 }, () => fs.promises.readFile('/issue-303.txt', 'utf8')),
63
- fs.promises.writeFile('/issue-303.txt', contents),
64
- ...Array.from({ length: 4 }, () => fs.promises.readFile('/issue-303.txt', 'utf8')),
65
- ]);
66
-
67
- const rejected = results.filter(r => r.status === 'rejected');
68
- assert.deepEqual(
69
- rejected.map(r => r.reason.code ?? r.reason.message),
70
- [],
71
- );
72
-
73
- assert.equal(await fs.promises.readFile('/issue-303.txt', 'utf8'), contents);
74
- }
75
- });
76
-
77
- test('closing a handle does not fail because another handle has unsynced writes #303', async () => {
78
- await fs.promises.writeFile('/issue-303-close.txt', 'original');
79
-
80
- const reader = await fs.promises.open('/issue-303-close.txt', 'r');
81
- const writer = await fs.promises.open('/issue-303-close.txt', 'r+');
82
-
83
- // The reader wrote nothing, so its close must not report the writer's dirty data as EBUSY
84
- const [closed] = await Promise.allSettled([reader.close(), writer.write(new TextEncoder().encode('DIRTY'), 0, 5, 0)]);
85
- assert.equal(closed.status, 'fulfilled');
86
-
87
- await writer.close();
88
- assert.equal(await fs.promises.readFile('/issue-303-close.txt', 'utf8'), 'DIRTYnal');
89
- });
90
-
91
- test('concurrent recursive mkdir of overlapping trees does not fail #308', async () => {
92
- const paths = ['/308/a', '/308/a', '/308/a/b', '/308/a/b', '/308/c', '/308/c', '/308-2', '/308-2'];
93
-
94
- const results = await Promise.allSettled(paths.map(path => fs.promises.mkdir(path, { recursive: true })));
95
-
96
- const rejected = results.filter(r => r.status == 'rejected');
97
- assert.deepEqual(
98
- rejected.map(r => r.reason.code ?? r.reason.message),
99
- [],
100
- );
101
-
102
- for (const path of paths) assert((await fs.promises.stat(path)).isDirectory());
103
- });
104
-
105
- test('parallel recursive mkdir of the same path creates it once #308', async () => {
106
- const results = await Promise.all(Array.from({ length: 8 }, () => fs.promises.mkdir('/308-same/nested', { recursive: true })));
107
-
108
- assert.deepEqual(
109
- results.filter(result => result !== undefined),
110
- ['/308-same'],
111
- );
112
- });
113
- });
@@ -1,103 +0,0 @@
1
- // SPDX-License-Identifier: LGPL-3.0-or-later
2
- import { sync, type Dirent } from '@zenfs/core';
3
- import assert, { rejects } from 'node:assert/strict';
4
- import { suite, test } from 'node:test';
5
- import { config, fs } from '@zenfs/devel/tests/common';
6
-
7
- const testFile = 'test-file.txt';
8
- fs.writeFileSync(testFile, 'Sample content');
9
- fs.mkdirSync('test-directory');
10
- fs.symlinkSync(testFile, 'test-symlink');
11
- const testDirPath = 'test-dir';
12
- const testFiles = ['file1.txt', 'file2.txt'];
13
- fs.mkdirSync(testDirPath);
14
- for (const file of testFiles) {
15
- fs.writeFileSync(`${testDirPath}/${file}`, 'Sample content');
16
- }
17
- await sync();
18
-
19
- suite('Dir', config('directories'), () => {
20
- test('read()', config('async'), async () => {
21
- const dir = fs.opendirSync(testDirPath);
22
-
23
- const dirent1 = await dir.read();
24
- assert(dirent1 instanceof fs.Dirent);
25
- assert(testFiles.includes(dirent1?.name));
26
-
27
- const dirent2 = await dir.read();
28
- assert(dirent2 instanceof fs.Dirent);
29
- assert(testFiles.includes(dirent2?.name));
30
-
31
- const dirent3 = await dir.read();
32
- assert.equal(dirent3, null);
33
-
34
- await dir.close();
35
- });
36
-
37
- test('readSync()', config('sync'), () => {
38
- const dir = fs.opendirSync(testDirPath);
39
-
40
- const dirent1 = dir.readSync();
41
- assert(dirent1 instanceof fs.Dirent);
42
- assert(testFiles.includes(dirent1?.name));
43
-
44
- const dirent2 = dir.readSync();
45
- assert(dirent2 instanceof fs.Dirent);
46
- assert(testFiles.includes(dirent2?.name));
47
-
48
- const dirent3 = dir.readSync();
49
- assert.equal(dirent3, null);
50
-
51
- dir.closeSync();
52
- });
53
-
54
- test('close()', config('async'), async () => {
55
- const dir = fs.opendirSync(testDirPath);
56
- await dir.close();
57
- rejects(dir.read());
58
- });
59
-
60
- test('closeSync()', config('sync'), () => {
61
- const dir = fs.opendirSync(testDirPath);
62
- dir.closeSync();
63
- assert.throws(() => dir.readSync());
64
- });
65
-
66
- test('asynchronous iteration', config('async'), async () => {
67
- const dir = fs.opendirSync(testDirPath);
68
- const dirents: Dirent[] = [];
69
-
70
- for await (const dirent of dir) {
71
- dirents.push(dirent);
72
- }
73
-
74
- assert.equal(dirents.length, 2);
75
- assert(dirents[0] instanceof fs.Dirent);
76
- assert(testFiles.includes(dirents[0].name));
77
- assert(testFiles.includes(dirents[1].name));
78
- });
79
-
80
- test('read after directory is closed', config('async'), async () => {
81
- const dir = fs.opendirSync(testDirPath);
82
- await dir.close();
83
- await assert.rejects(dir.read());
84
- });
85
-
86
- test('readSync after directory is closed', config('sync'), () => {
87
- const dir = fs.opendirSync(testDirPath);
88
- dir.closeSync();
89
- assert.throws(() => dir.readSync());
90
- });
91
-
92
- test('close multiple times', config('async'), async () => {
93
- const dir = fs.opendirSync(testDirPath);
94
- await dir.close();
95
- await assert.rejects(dir.close(), { code: 'ERR_DIR_CLOSED' });
96
- });
97
-
98
- test('closeSync multiple times', config('sync'), () => {
99
- const dir = fs.opendirSync(testDirPath);
100
- dir.closeSync();
101
- assert.throws(() => dir.closeSync(), { code: 'ERR_DIR_CLOSED' });
102
- });
103
- });
@@ -1,189 +0,0 @@
1
- // SPDX-License-Identifier: LGPL-3.0-or-later
2
- import assert from 'node:assert/strict';
3
- import { join } from 'node:path/posix';
4
- import { suite, test } from 'node:test';
5
- import { config, fs } from '@zenfs/devel/tests/common';
6
-
7
- const testDir = 'test-dir';
8
- const testFiles = ['file1.txt', 'file2.txt', 'file3.txt'];
9
- const testDirectories = ['subdir1', 'subdir2'];
10
-
11
- await fs.promises.mkdir(testDir);
12
- for (const file of testFiles) {
13
- await fs.promises.writeFile(`${testDir}/${file}`, 'Sample content');
14
- }
15
- for (const dir of testDirectories) {
16
- await fs.promises.mkdir(`${testDir}/${dir}`);
17
- for (const file of ['file4.txt', 'file5.txt']) {
18
- await fs.promises.writeFile(`${testDir}/${dir}/${file}`, 'Sample content');
19
- }
20
- }
21
-
22
- suite('Directories', config('directories'), () => {
23
- test('mkdir', config('async'), async () => {
24
- await fs.promises.mkdir('/one', 0o755);
25
- assert(await fs.promises.stat('/one', { throwIfNoEntry: false }));
26
- await assert.rejects(fs.promises.mkdir('/one', 0o755), { code: 'EEXIST' });
27
- });
28
-
29
- test('mkdirSync', config('sync'), () => fs.mkdirSync('/two', 0o000));
30
-
31
- test('mkdir, nested', config('async'), async () => {
32
- await assert.rejects(fs.promises.mkdir('/nested/dir'), { code: 'ENOENT', path: '/nested/dir' });
33
- assert(!(await fs.promises.stat('/nested/dir', { throwIfNoEntry: false })));
34
- });
35
-
36
- test('mkdir, recursive', config('async'), async () => {
37
- assert.equal(await fs.promises.mkdir('/recursiveP/A/B', { recursive: true, mode: 0o755 }), '/recursiveP');
38
- assert.equal(await fs.promises.mkdir('/recursiveP/A/B/C/D', { recursive: true, mode: 0o777 }), '/recursiveP/A/B/C');
39
- assert.equal(await fs.promises.mkdir('/recursiveP/A/B/C/D', { recursive: true, mode: 0o700 }), undefined);
40
-
41
- assert.equal((await fs.promises.stat('/recursiveP')).mode, fs.constants.S_IFDIR | 0o755);
42
- assert.equal((await fs.promises.stat('/recursiveP/A')).mode, fs.constants.S_IFDIR | 0o755);
43
- assert.equal((await fs.promises.stat('/recursiveP/A/B')).mode, fs.constants.S_IFDIR | 0o755);
44
- assert.equal((await fs.promises.stat('/recursiveP/A/B/C')).mode, fs.constants.S_IFDIR | 0o777);
45
- assert.equal((await fs.promises.stat('/recursiveP/A/B/C/D')).mode, fs.constants.S_IFDIR | 0o777);
46
- });
47
-
48
- test('mkdir, recursive with a file in the way', config('async'), async () => {
49
- await fs.promises.writeFile('/recursiveF', 'Sample content');
50
-
51
- await assert.rejects(fs.promises.mkdir('/recursiveF', { recursive: true }), { code: 'EEXIST', path: '/recursiveF' });
52
- await assert.rejects(fs.promises.mkdir('/recursiveF/A/B', { recursive: true }), { code: 'ENOTDIR', path: '/recursiveF/A/B' });
53
- });
54
-
55
- test('mkdirSync, recursive', config('sync'), () => {
56
- assert.equal(fs.mkdirSync('/recursiveS/A/B', { recursive: true, mode: 0o755 }), '/recursiveS');
57
- assert.equal(fs.mkdirSync('/recursiveS/A/B/C/D', { recursive: true, mode: 0o777 }), '/recursiveS/A/B/C');
58
- assert.equal(fs.mkdirSync('/recursiveS/A/B/C/D', { recursive: true, mode: 0o700 }), undefined);
59
-
60
- assert.equal(fs.statSync('/recursiveS').mode, fs.constants.S_IFDIR | 0o755);
61
- assert.equal(fs.statSync('/recursiveS/A').mode, fs.constants.S_IFDIR | 0o755);
62
- assert.equal(fs.statSync('/recursiveS/A/B').mode, fs.constants.S_IFDIR | 0o755);
63
- assert.equal(fs.statSync('/recursiveS/A/B/C').mode, fs.constants.S_IFDIR | 0o777);
64
- assert.equal(fs.statSync('/recursiveS/A/B/C/D').mode, fs.constants.S_IFDIR | 0o777);
65
- });
66
-
67
- test('mkdirSync, recursive with a file in the way', config('sync'), () => {
68
- fs.writeFileSync('/recursiveSF', 'Sample content');
69
-
70
- assert.throws(() => fs.mkdirSync('/recursiveSF', { recursive: true }), { code: 'EEXIST', path: '/recursiveSF' });
71
- assert.throws(() => fs.mkdirSync('/recursiveSF/A/B', { recursive: true }), { code: 'ENOTDIR', path: '/recursiveSF/A/B' });
72
- });
73
-
74
- test('rmdir (non-empty)', config('async'), async () => {
75
- await fs.promises.mkdir('/rmdirTest');
76
- await fs.promises.mkdir('/rmdirTest/rmdirTest2');
77
-
78
- await assert.rejects(fs.promises.rmdir('/rmdirTest'), { code: 'ENOTEMPTY' });
79
- });
80
-
81
- test('readdirSync on file', config('sync'), () => {
82
- assert.throws(() => fs.readdirSync('a.js'), { code: 'ENOTDIR' });
83
- });
84
-
85
- test('readdir on file', config('async'), async () => {
86
- await assert.rejects(fs.promises.readdir('a.js'), { code: 'ENOTDIR' });
87
- });
88
-
89
- test('readdirSync on non-existent directory', config('sync'), () => {
90
- assert.throws(() => fs.readdirSync('/does/not/exist'), { code: 'ENOENT' });
91
- });
92
-
93
- test('readdir on non-existent directory', config('async'), async () => {
94
- await assert.rejects(fs.promises.readdir('/does/not/exist'), { code: 'ENOENT' });
95
- });
96
-
97
- test('rm recursively', config('async'), async () => {
98
- await fs.promises.mkdir('/rmDirRecursively');
99
- await fs.promises.mkdir('/rmDirRecursively/rmDirNested');
100
- await fs.promises.writeFile('/rmDirRecursively/rmDirNested/test.txt', 'hello world!');
101
-
102
- await fs.promises.rm('/rmDirRecursively', { recursive: true });
103
- });
104
-
105
- test('rmSync recursively', config('sync'), () => {
106
- fs.mkdirSync('/rmDirRecursively');
107
- fs.mkdirSync('/rmDirRecursively/rmDirNested');
108
- fs.writeFileSync('/rmDirRecursively/rmDirNested/test.txt', 'hello world!');
109
-
110
- fs.rmSync('/rmDirRecursively', { recursive: true });
111
- });
112
-
113
- test('readdir returns files and directories', config('async'), async () => {
114
- const dirents = await fs.promises.readdir(testDir, { withFileTypes: true });
115
- const files = dirents.filter(dirent => dirent.isFile()).map(dirent => dirent.name);
116
- const dirs = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
117
-
118
- assert(testFiles.every(file => files.includes(file)));
119
- assert(testDirectories.every(dir => dirs.includes(dir)));
120
- });
121
-
122
- test('readdirSync returns files and directories', config('sync'), () => {
123
- const dirents = fs.readdirSync(testDir, { withFileTypes: true });
124
- const files = dirents.filter(dirent => dirent.isFile()).map(dirent => dirent.name);
125
- const dirs = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
126
-
127
- assert(testFiles.every(file => files.includes(file)));
128
- assert(testDirectories.every(dir => dirs.includes(dir)));
129
- });
130
-
131
- test('readdir returns Dirent objects', config('async'), async () => {
132
- const dirents = await fs.promises.readdir(testDir, { withFileTypes: true });
133
- assert(dirents[0] instanceof fs.Dirent);
134
- });
135
-
136
- test('readdirSync returns Dirent objects', config('sync'), () => {
137
- const dirents = fs.readdirSync(testDir, { withFileTypes: true });
138
- assert(dirents[0] instanceof fs.Dirent);
139
- });
140
-
141
- test('readdir works without withFileTypes option', config('async'), async () => {
142
- const files = await fs.promises.readdir(testDir);
143
- assert(testFiles.every(entry => files.includes(entry)));
144
- assert(testDirectories.every(entry => files.includes(entry)));
145
- });
146
-
147
- test('readdirSync works without withFileTypes option', config('sync'), () => {
148
- const files = fs.readdirSync(testDir);
149
- assert(testFiles.every(entry => files.includes(entry)));
150
- assert(testDirectories.every(entry => files.includes(entry)));
151
- });
152
-
153
- test('readdir returns files recursively', config('async'), async () => {
154
- const entries = await fs.promises.readdir(testDir, { recursive: true });
155
- assert(entries.includes('file1.txt'));
156
- assert(entries.includes('subdir1/file4.txt'));
157
- assert(entries.includes('subdir2/file5.txt'));
158
- });
159
-
160
- test('readdir returns Dirent recursively', config('async'), async () => {
161
- const entries = await fs.promises.readdir(testDir, { recursive: true, withFileTypes: true });
162
- entries.sort((a, b) => join(a.parentPath, a.name).localeCompare(join(b.parentPath, b.name)));
163
- const values = entries.map(entry => [entry.parentPath, entry.name]);
164
-
165
- // `parentPath` is resolved against the directory that was read
166
- assert.deepEqual(values[0], ['/' + testDir, 'file1.txt']);
167
- assert.deepEqual(values[4], ['/' + testDir + '/subdir1', 'file4.txt']);
168
- assert.deepEqual(values[8], ['/' + testDir + '/subdir2', 'file5.txt']);
169
- });
170
-
171
- test('readdirSync returns files recursively', config('sync'), () => {
172
- const entries = fs.readdirSync(testDir, { recursive: true }).sort();
173
- assert.equal(entries[0], 'file1.txt');
174
- assert.equal(entries[4], 'subdir1/file4.txt');
175
- assert.equal(entries[8], 'subdir2/file5.txt');
176
- });
177
-
178
- test('Cyrillic file names', config('sync'), () => {
179
- fs.writeFileSync('/мой-файл.txt', 'HELLO!', 'utf-8');
180
- assert(fs.readdirSync('/').includes('мой-файл.txt'));
181
- });
182
-
183
- test('re-creating a deleted path still shows up in readdir #305', config('sync'), () => {
184
- fs.unlinkSync('/elipses.txt');
185
- fs.writeFileSync('/elipses.txt', '...');
186
-
187
- assert(fs.readdirSync('/').includes('elipses.txt'));
188
- });
189
- });
@@ -1,159 +0,0 @@
1
- // SPDX-License-Identifier: LGPL-3.0-or-later
2
- import assert from 'node:assert/strict';
3
- import test, { suite } from 'node:test';
4
- import { config, fs } from '@zenfs/devel/tests/common';
5
-
6
- const existingFile = '/exit.js';
7
- const path = '/non-existent';
8
-
9
- interface Case {
10
- /** The name of the test */
11
- name: string;
12
- code: string;
13
- /** The syscall the error should be attributed to, which is not always the name of the function */
14
- syscall: string;
15
- path: string;
16
- dest?: string;
17
- sync: (this: void) => unknown;
18
- async: (this: void) => Promise<unknown>;
19
- }
20
-
21
- const cases: Case[] = [
22
- {
23
- name: 'stat',
24
- code: 'ENOENT',
25
- syscall: 'stat',
26
- path,
27
- sync: () => fs.statSync(path),
28
- async: () => fs.promises.stat(path),
29
- },
30
- {
31
- name: 'lstat',
32
- code: 'ENOENT',
33
- syscall: 'lstat',
34
- path,
35
- sync: () => fs.lstatSync(path),
36
- async: () => fs.promises.lstat(path),
37
- },
38
- {
39
- name: 'mkdir',
40
- code: 'EEXIST',
41
- syscall: 'mkdir',
42
- path: existingFile,
43
- sync: () => fs.mkdirSync(existingFile, 0o666),
44
- async: () => fs.promises.mkdir(existingFile, 0o666),
45
- },
46
- {
47
- name: 'rmdir (missing)',
48
- code: 'ENOENT',
49
- syscall: 'rmdir',
50
- path,
51
- sync: () => fs.rmdirSync(path),
52
- async: () => fs.promises.rmdir(path),
53
- },
54
- {
55
- name: 'rmdir (not a directory)',
56
- code: 'ENOTDIR',
57
- syscall: 'rmdir',
58
- path: existingFile,
59
- sync: () => fs.rmdirSync(existingFile),
60
- async: () => fs.promises.rmdir(existingFile),
61
- },
62
- {
63
- name: 'rename',
64
- code: 'ENOENT',
65
- syscall: 'rename',
66
- path,
67
- dest: '/foo',
68
- sync: () => fs.renameSync(path, 'foo'),
69
- async: () => fs.promises.rename(path, 'foo'),
70
- },
71
- {
72
- name: 'open',
73
- code: 'ENOENT',
74
- syscall: 'open',
75
- path,
76
- sync: () => fs.openSync(path, 'r'),
77
- async: () => fs.promises.open(path, 'r'),
78
- },
79
- {
80
- // Note Node attributes `readdir` failures to `scandir`
81
- name: 'readdir',
82
- code: 'ENOENT',
83
- syscall: 'scandir',
84
- path,
85
- sync: () => fs.readdirSync(path),
86
- async: () => fs.promises.readdir(path),
87
- },
88
- {
89
- name: 'unlink',
90
- code: 'ENOENT',
91
- syscall: 'unlink',
92
- path,
93
- sync: () => fs.unlinkSync(path),
94
- async: () => fs.promises.unlink(path),
95
- },
96
- {
97
- // Note `path` is the existing file and `dest` is the new link
98
- name: 'link',
99
- code: 'ENOENT',
100
- syscall: 'link',
101
- path,
102
- dest: '/foo',
103
- sync: () => fs.linkSync(path, 'foo'),
104
- async: () => fs.promises.link(path, 'foo'),
105
- },
106
- {
107
- name: 'chmod',
108
- code: 'ENOENT',
109
- syscall: 'chmod',
110
- path,
111
- sync: () => fs.chmodSync(path, 0o666),
112
- async: () => fs.promises.chmod(path, 0o666),
113
- },
114
- {
115
- name: 'readlink',
116
- code: 'ENOENT',
117
- syscall: 'readlink',
118
- path,
119
- sync: () => fs.readlinkSync(path),
120
- async: () => fs.promises.readlink(path),
121
- },
122
- ];
123
-
124
- /**
125
- * Checks an error against the expected code, syscall, path, and message.
126
- *
127
- * The message is only matched at the start, since the description text for an errno
128
- * is not standardized and implementations may add more information at the end.
129
- */
130
- function check(error: unknown, c: Case): void {
131
- const e = error as NodeJS.ErrnoException & { dest?: string };
132
-
133
- assert.equal(e.code, c.code);
134
- assert.equal(e.syscall, c.syscall);
135
- assert.equal(e.path, c.path);
136
- if (c.dest) assert.equal(e.dest, c.dest);
137
-
138
- // e.g. `ENOENT: no such file or directory, stat '/non-existent'`
139
- const expected = new RegExp(`^${c.code}: .+, ${c.syscall} '${c.path}'` + (c.dest ? ` -> '${c.dest}'` : ''));
140
- assert.match(e.message, expected);
141
- }
142
-
143
- suite('Error messages', () => {
144
- for (const c of cases) {
145
- test(c.name, config('async'), async () => {
146
- await assert.rejects(c.async, (error: unknown) => {
147
- check(error, c);
148
- return true;
149
- });
150
- });
151
-
152
- test(c.name + 'Sync', config('sync'), () => {
153
- assert.throws(c.sync, (error: unknown) => {
154
- check(error, c);
155
- return true;
156
- });
157
- });
158
- }
159
- });
@@ -1,23 +0,0 @@
1
- // SPDX-License-Identifier: LGPL-3.0-or-later
2
- import assert from 'node:assert/strict';
3
- import { suite, test } from 'node:test';
4
- import { config, fs } from '@zenfs/devel/tests/common';
5
-
6
- suite('exists', () => {
7
- const f = 'x.txt';
8
-
9
- test('return true for an existing file', config('async', 'promises.exists'), async () => {
10
- const exists = await fs.promises.exists(f);
11
- assert(exists);
12
- });
13
-
14
- test('return false for a non-existent file', config('async', 'promises.exists'), async () => {
15
- const exists = await fs.promises.exists(f + '-NO');
16
- assert(!exists);
17
- });
18
-
19
- test('have sync methods that behave the same', config('sync'), () => {
20
- assert(fs.existsSync(f));
21
- assert(!fs.existsSync(f + '-NO'));
22
- });
23
- });