@zenfs/core 1.8.6 → 1.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vfs/promises.js +18 -0
- package/dist/vfs/sync.js +18 -0
- package/package.json +1 -1
- package/scripts/ci-cli.js +0 -0
- package/tests/common/context.test.ts +10 -10
- package/tests/common/devices.test.ts +1 -1
- package/tests/common/handle.test.ts +1 -1
- package/tests/common/mounts.test.ts +3 -3
- package/tests/common/mutex.test.ts +2 -2
- package/tests/common/path.test.ts +1 -1
- package/tests/fs/append.test.ts +1 -1
- package/tests/fs/dir.test.ts +4 -4
- package/tests/fs/directory.test.ts +8 -8
- package/tests/fs/errors.test.ts +1 -1
- package/tests/fs/exists.test.ts +1 -1
- package/tests/fs/links.test.ts +4 -4
- package/tests/fs/open.test.ts +3 -3
- package/tests/fs/permissions.test.ts +2 -2
- package/tests/fs/read.test.ts +9 -9
- package/tests/fs/readFile.test.ts +6 -6
- package/tests/fs/rename.test.ts +9 -19
- package/tests/fs/stat.test.ts +1 -1
- package/tests/fs/streams.test.ts +11 -11
- package/tests/fs/times.test.ts +6 -6
- package/tests/fs/truncate.test.ts +1 -1
- package/tests/fs/watch.test.ts +10 -10
- package/tests/fs/write.test.ts +7 -7
- package/tests/fs/writeFile.test.ts +6 -6
- package/tests/port/channel.test.ts +1 -1
- package/tests/port/config.test.ts +1 -1
- package/tests/port/remote.test.ts +1 -1
- package/tests/port/timeout.test.ts +3 -3
package/dist/vfs/promises.js
CHANGED
|
@@ -941,6 +941,24 @@ export async function realpath(path, options) {
|
|
|
941
941
|
const ctx_path = ((this === null || this === void 0 ? void 0 : this.root) || '') + path;
|
|
942
942
|
if (cache.paths.hasAsync(ctx_path))
|
|
943
943
|
return cache.paths.getAsync(ctx_path);
|
|
944
|
+
/* Try to resolve it directly. If this works,
|
|
945
|
+
that means we don't need to perform any resolution for parent directories. */
|
|
946
|
+
try {
|
|
947
|
+
const { fs, path: resolvedPath } = resolveMount(path, this);
|
|
948
|
+
// Stat it to make sure it exists
|
|
949
|
+
const stats = await fs.stat(resolvedPath);
|
|
950
|
+
let real = path.toString();
|
|
951
|
+
if (stats.isSymbolicLink()) {
|
|
952
|
+
const target = resolve(dirname(resolvedPath), (await readlink.call(this, resolvedPath, options)).toString());
|
|
953
|
+
real = cache.paths.get(((this === null || this === void 0 ? void 0 : this.root) || '') + target) || (await realpath.call(this, target));
|
|
954
|
+
cache.paths.set(ctx_path, real);
|
|
955
|
+
}
|
|
956
|
+
cache.paths.set(path.toString(), real);
|
|
957
|
+
return real;
|
|
958
|
+
}
|
|
959
|
+
catch {
|
|
960
|
+
// Go the long way
|
|
961
|
+
}
|
|
944
962
|
const { base, dir } = parse(path);
|
|
945
963
|
const realDir = dir == '/' ? '/' : await (cache.paths.getAsync(((this === null || this === void 0 ? void 0 : this.root) || '') + dir) || realpath.call(this, dir));
|
|
946
964
|
const lpath = join(realDir, base);
|
package/dist/vfs/sync.js
CHANGED
|
@@ -633,6 +633,24 @@ export function realpathSync(path, options) {
|
|
|
633
633
|
const ctx_path = ((this === null || this === void 0 ? void 0 : this.root) || '') + path;
|
|
634
634
|
if (cache.paths.has(ctx_path))
|
|
635
635
|
return cache.paths.get(ctx_path);
|
|
636
|
+
/* Try to resolve it directly. If this works,
|
|
637
|
+
that means we don't need to perform any resolution for parent directories. */
|
|
638
|
+
try {
|
|
639
|
+
const { fs, path: resolvedPath } = resolveMount(path, this);
|
|
640
|
+
// Stat it to make sure it exists
|
|
641
|
+
const stats = fs.statSync(resolvedPath);
|
|
642
|
+
let real = path;
|
|
643
|
+
if (stats.isSymbolicLink()) {
|
|
644
|
+
const target = resolve(dirname(resolvedPath), readlinkSync.call(this, resolvedPath, options).toString());
|
|
645
|
+
real = cache.paths.get(((this === null || this === void 0 ? void 0 : this.root) || '') + target) || realpathSync.call(this, target);
|
|
646
|
+
cache.paths.set(ctx_path, real);
|
|
647
|
+
}
|
|
648
|
+
cache.paths.set(path, real);
|
|
649
|
+
return real;
|
|
650
|
+
}
|
|
651
|
+
catch {
|
|
652
|
+
// Go the long way
|
|
653
|
+
}
|
|
636
654
|
const { base, dir } = parse(path);
|
|
637
655
|
const realDir = dir == '/' ? '/' : cache.paths.get(((this === null || this === void 0 ? void 0 : this.root) || '') + dir) || realpathSync.call(this, dir);
|
|
638
656
|
const lpath = join(realDir, base);
|
package/package.json
CHANGED
package/scripts/ci-cli.js
CHANGED
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { suite, test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
3
|
import { bindContext } from '../../dist/context.js';
|
|
4
4
|
import * as fs from '../../dist/vfs/index.js';
|
|
5
5
|
|
|
@@ -15,8 +15,8 @@ suite('Context', () => {
|
|
|
15
15
|
|
|
16
16
|
test('linking', async () => {
|
|
17
17
|
await ctx.promises.symlink('/example.txt', '/link');
|
|
18
|
-
assert.
|
|
19
|
-
assert.
|
|
18
|
+
assert.equal(await ctx.promises.readlink('link', 'utf8'), '/example.txt');
|
|
19
|
+
assert.equal(await fs.promises.readlink('/ctx/link'), '/example.txt');
|
|
20
20
|
assert.deepEqual(await ctx.promises.readFile('/link', 'utf-8'), await fs.promises.readFile('/ctx/example.txt', 'utf-8'));
|
|
21
21
|
|
|
22
22
|
// The symlink should only work inside the chroot /ctx
|
|
@@ -25,12 +25,12 @@ suite('Context', () => {
|
|
|
25
25
|
|
|
26
26
|
test('path resolution', async () => {
|
|
27
27
|
// Correct/normal
|
|
28
|
-
assert.
|
|
29
|
-
assert.
|
|
30
|
-
assert.
|
|
31
|
-
assert.
|
|
28
|
+
assert.equal(ctx.realpathSync('/'), '/');
|
|
29
|
+
assert.equal(ctx.realpathSync('example.txt'), '/example.txt');
|
|
30
|
+
assert.equal(ctx.realpathSync('../link'), '/example.txt');
|
|
31
|
+
assert.equal(await ctx.promises.realpath('/../link'), '/example.txt');
|
|
32
32
|
|
|
33
|
-
assert.
|
|
33
|
+
assert.equal(fs.realpathSync('/ctx/link'), '/example.txt');
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('break-out fails', () => {
|
|
@@ -49,8 +49,8 @@ suite('Context', () => {
|
|
|
49
49
|
}
|
|
50
50
|
})();
|
|
51
51
|
await ctx.promises.writeFile('/xpto.txt', 'in real root');
|
|
52
|
-
assert.
|
|
52
|
+
assert.equal(lastFile!, 'xpto.txt');
|
|
53
53
|
await ctx.promises.unlink('/xpto.txt');
|
|
54
|
-
assert.
|
|
54
|
+
assert.equal(lastFile, 'xpto.txt');
|
|
55
55
|
});
|
|
56
56
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { suite, test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
3
|
import { configure } from '../../dist/config.js';
|
|
4
4
|
import * as fs from '../../dist/vfs/index.js';
|
|
5
5
|
import { S_IFCHR, S_IFMT } from '../../dist/vfs/constants.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { configure } from '../../dist/config.js';
|
|
4
4
|
import * as fs from '../../dist/vfs/index.js';
|
|
@@ -12,8 +12,8 @@ suite('Mounts', () => {
|
|
|
12
12
|
},
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
assert.
|
|
16
|
-
assert.
|
|
15
|
+
assert.deepEqual(fs.readdirSync('/'), ['nested']);
|
|
16
|
+
assert.deepEqual(fs.readdirSync('/nested'), ['dir']);
|
|
17
17
|
|
|
18
18
|
// cleanup
|
|
19
19
|
fs.umount('/nested/dir');
|
|
@@ -3,7 +3,7 @@ import { Mutexed } from '../../dist/mixins/mutexed.js';
|
|
|
3
3
|
import { StoreFS } from '../../dist/backends/store/fs.js';
|
|
4
4
|
import { InMemoryStore } from '../../dist/backends/memory.js';
|
|
5
5
|
import { suite, test } from 'node:test';
|
|
6
|
-
import assert from 'node:assert';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
7
|
|
|
8
8
|
suite('LockFS mutex', () => {
|
|
9
9
|
const fs = new (Mutexed(StoreFS))(new InMemoryStore('test'));
|
|
@@ -57,6 +57,6 @@ suite('LockFS mutex', () => {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
await Promise.all([foo(), foo(), foo()]);
|
|
60
|
-
assert.
|
|
60
|
+
assert.equal(x, 4);
|
|
61
61
|
});
|
|
62
62
|
});
|
package/tests/fs/append.test.ts
CHANGED
package/tests/fs/dir.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert, { rejects } from 'node:assert';
|
|
1
|
+
import assert, { rejects } from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { fs, type Dirent } from '../common.js';
|
|
4
4
|
|
|
@@ -68,7 +68,7 @@ suite('Dir', () => {
|
|
|
68
68
|
assert(testFiles.includes(dirent2?.name));
|
|
69
69
|
|
|
70
70
|
const dirent3 = await dir.read();
|
|
71
|
-
assert.
|
|
71
|
+
assert.equal(dirent3, null);
|
|
72
72
|
|
|
73
73
|
await dir.close();
|
|
74
74
|
});
|
|
@@ -85,7 +85,7 @@ suite('Dir', () => {
|
|
|
85
85
|
assert(testFiles.includes(dirent2?.name));
|
|
86
86
|
|
|
87
87
|
const dirent3 = dir.readSync();
|
|
88
|
-
assert.
|
|
88
|
+
assert.equal(dirent3, null);
|
|
89
89
|
|
|
90
90
|
dir.closeSync();
|
|
91
91
|
});
|
|
@@ -110,7 +110,7 @@ suite('Dir', () => {
|
|
|
110
110
|
dirents.push(dirent);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
assert.
|
|
113
|
+
assert.equal(dirents.length, 2);
|
|
114
114
|
assert(dirents[0] instanceof fs.Dirent);
|
|
115
115
|
assert(testFiles.includes(dirents[0].name));
|
|
116
116
|
assert(testFiles.includes(dirents[1].name));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { ErrnoError } from '../../dist/error.js';
|
|
4
4
|
import { fs } from '../common.js';
|
|
@@ -32,7 +32,7 @@ suite('Directories', () => {
|
|
|
32
32
|
await fs.promises.mkdir('/nested/dir');
|
|
33
33
|
} catch (error: any) {
|
|
34
34
|
assert(error instanceof ErrnoError);
|
|
35
|
-
assert.
|
|
35
|
+
assert.equal(error.code, 'ENOENT');
|
|
36
36
|
}
|
|
37
37
|
assert(!(await fs.promises.exists('/nested/dir')));
|
|
38
38
|
});
|
|
@@ -66,7 +66,7 @@ suite('Directories', () => {
|
|
|
66
66
|
fs.readdirSync('/two');
|
|
67
67
|
} catch (error: any) {
|
|
68
68
|
assert(error instanceof ErrnoError);
|
|
69
|
-
assert.
|
|
69
|
+
assert.equal(error.code, 'EACCES');
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
|
|
@@ -78,7 +78,7 @@ suite('Directories', () => {
|
|
|
78
78
|
await fs.promises.rmdir('/rmdirTest');
|
|
79
79
|
} catch (error: any) {
|
|
80
80
|
assert(error instanceof ErrnoError);
|
|
81
|
-
assert.
|
|
81
|
+
assert.equal(error.code, 'ENOTEMPTY');
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
|
|
@@ -90,7 +90,7 @@ suite('Directories', () => {
|
|
|
90
90
|
} catch (error: any) {
|
|
91
91
|
assert(error instanceof ErrnoError);
|
|
92
92
|
wasThrown = true;
|
|
93
|
-
assert.
|
|
93
|
+
assert.equal(error.code, 'ENOTDIR');
|
|
94
94
|
}
|
|
95
95
|
assert(wasThrown);
|
|
96
96
|
});
|
|
@@ -100,7 +100,7 @@ suite('Directories', () => {
|
|
|
100
100
|
await fs.promises.readdir('a.js');
|
|
101
101
|
} catch (error: any) {
|
|
102
102
|
assert(error instanceof ErrnoError);
|
|
103
|
-
assert.
|
|
103
|
+
assert.equal(error.code, 'ENOTDIR');
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
|
|
@@ -112,7 +112,7 @@ suite('Directories', () => {
|
|
|
112
112
|
} catch (error: any) {
|
|
113
113
|
assert(error instanceof ErrnoError);
|
|
114
114
|
wasThrown = true;
|
|
115
|
-
assert.
|
|
115
|
+
assert.equal(error.code, 'ENOENT');
|
|
116
116
|
}
|
|
117
117
|
assert(wasThrown);
|
|
118
118
|
});
|
|
@@ -122,7 +122,7 @@ suite('Directories', () => {
|
|
|
122
122
|
await fs.promises.readdir('/does/not/exist');
|
|
123
123
|
} catch (error: any) {
|
|
124
124
|
assert(error instanceof ErrnoError);
|
|
125
|
-
assert.
|
|
125
|
+
assert.equal(error.code, 'ENOENT');
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
|
package/tests/fs/errors.test.ts
CHANGED
package/tests/fs/exists.test.ts
CHANGED
package/tests/fs/links.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { join } from '../../dist/vfs/path.js';
|
|
4
4
|
import { fs } from '../common.js';
|
|
@@ -20,7 +20,7 @@ suite('Links', () => {
|
|
|
20
20
|
|
|
21
21
|
test('readlink', async () => {
|
|
22
22
|
const destination = await fs.promises.readlink(symlink);
|
|
23
|
-
assert.
|
|
23
|
+
assert.equal(destination, target);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
test('read target contents', async () => {
|
|
@@ -43,7 +43,7 @@ suite('Links', () => {
|
|
|
43
43
|
}
|
|
44
44
|
const targetContent = await fs.promises.readFile(target, 'utf8');
|
|
45
45
|
const linkContent = await fs.promises.readFile(hardlink, 'utf8');
|
|
46
|
-
assert.
|
|
46
|
+
assert.equal(targetContent, linkContent);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test('file inside symlinked directory', async () => {
|
|
@@ -52,6 +52,6 @@ suite('Links', () => {
|
|
|
52
52
|
const link = join('link', target);
|
|
53
53
|
assert((await fs.promises.realpath(link)) === target);
|
|
54
54
|
const linkContent = await fs.promises.readFile(link, 'utf8');
|
|
55
|
-
assert.
|
|
55
|
+
assert.equal(targetContent, linkContent);
|
|
56
56
|
});
|
|
57
57
|
});
|
package/tests/fs/open.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { ErrnoError } from '../../dist/error.js';
|
|
4
4
|
import { fs } from '../common.js';
|
|
@@ -12,7 +12,7 @@ suite('fs file opening', () => {
|
|
|
12
12
|
fs.openSync('/path/to/file/that/does/not/exist', 'r');
|
|
13
13
|
} catch (error: any) {
|
|
14
14
|
assert(error instanceof ErrnoError);
|
|
15
|
-
assert.
|
|
15
|
+
assert.equal(error?.code, 'ENOENT');
|
|
16
16
|
caughtException = true;
|
|
17
17
|
}
|
|
18
18
|
assert(caughtException);
|
|
@@ -23,7 +23,7 @@ suite('fs file opening', () => {
|
|
|
23
23
|
await fs.promises.open('/path/to/file/that/does/not/exist', 'r');
|
|
24
24
|
} catch (error: any) {
|
|
25
25
|
assert(error instanceof ErrnoError);
|
|
26
|
-
assert.
|
|
26
|
+
assert.equal(error?.code, 'ENOENT');
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { credentials } from '../../dist/credentials.js';
|
|
4
4
|
import { R_OK, W_OK, X_OK } from '../../dist/vfs/constants.js';
|
|
@@ -50,7 +50,7 @@ suite('Permissions', () => {
|
|
|
50
50
|
async function test_item(path: string): Promise<void> {
|
|
51
51
|
const stats = await fs.promises.stat(path).catch((error: ErrnoError) => {
|
|
52
52
|
assert(error instanceof ErrnoError);
|
|
53
|
-
assert.
|
|
53
|
+
assert.equal(error.code, 'EACCES');
|
|
54
54
|
});
|
|
55
55
|
if (!stats) {
|
|
56
56
|
return;
|
package/tests/fs/read.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { fs } from '../common.js';
|
|
4
4
|
import { Buffer } from 'buffer';
|
|
@@ -27,12 +27,12 @@ suite('read', () => {
|
|
|
27
27
|
suite('read binary', () => {
|
|
28
28
|
test('Read a file and check its binary bytes (asynchronous)', async () => {
|
|
29
29
|
const buff = await fs.promises.readFile('elipses.txt');
|
|
30
|
-
assert.
|
|
30
|
+
assert.equal((buff[1] << 8) | buff[0], 32994);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
test('Read a file and check its binary bytes (synchronous)', () => {
|
|
34
34
|
const buff = fs.readFileSync('elipses.txt');
|
|
35
|
-
assert.
|
|
35
|
+
assert.equal((buff[1] << 8) | buff[0], 32994);
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
|
|
@@ -44,16 +44,16 @@ suite('read buffer', () => {
|
|
|
44
44
|
const handle = await fs.promises.open(filepath, 'r');
|
|
45
45
|
const { bytesRead } = await handle.read(bufferAsync, 0, expected.length, 0);
|
|
46
46
|
|
|
47
|
-
assert.
|
|
48
|
-
assert.
|
|
47
|
+
assert.equal(bytesRead, expected.length);
|
|
48
|
+
assert.equal(bufferAsync.toString(), expected);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('read file synchronously', () => {
|
|
52
52
|
const fd = fs.openSync(filepath, 'r');
|
|
53
53
|
const bytesRead = fs.readSync(fd, bufferSync, 0, expected.length, 0);
|
|
54
54
|
|
|
55
|
-
assert.
|
|
56
|
-
assert.
|
|
55
|
+
assert.equal(bufferSync.toString(), expected);
|
|
56
|
+
assert.equal(bytesRead, expected.length);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
test('read file synchronously to non-zero offset', () => {
|
|
@@ -61,7 +61,7 @@ suite('read buffer', () => {
|
|
|
61
61
|
const buffer = Buffer.alloc(expected.length + 10);
|
|
62
62
|
const bytesRead = fs.readSync(fd, buffer, 10, expected.length, 0);
|
|
63
63
|
|
|
64
|
-
assert.
|
|
65
|
-
assert.
|
|
64
|
+
assert.equal(buffer.subarray(10, buffer.length).toString(), expected);
|
|
65
|
+
assert.equal(bytesRead, expected.length);
|
|
66
66
|
});
|
|
67
67
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { fs } from '../common.js';
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ suite('Reading', () => {
|
|
|
10
10
|
test('Reading past the end of a file should not be an error', async () => {
|
|
11
11
|
const handle = await fs.promises.open('a.js', 'r');
|
|
12
12
|
const { bytesRead } = await handle.read(new Uint8Array(10), 0, 10, 10000);
|
|
13
|
-
assert.
|
|
13
|
+
assert.equal(bytesRead, 0);
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
16
|
|
|
@@ -46,7 +46,7 @@ suite('Read File Test', () => {
|
|
|
46
46
|
|
|
47
47
|
test('read file with utf-8 encoding asynchronously', async () => {
|
|
48
48
|
const data: string = await fs.promises.readFile(fn, 'utf8');
|
|
49
|
-
assert.
|
|
49
|
+
assert.equal(data, '');
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
test('read file synchronously', () => {
|
|
@@ -56,7 +56,7 @@ suite('Read File Test', () => {
|
|
|
56
56
|
|
|
57
57
|
test('read file with utf-8 encoding synchronously', () => {
|
|
58
58
|
const data: string = fs.readFileSync(fn, 'utf8');
|
|
59
|
-
assert.
|
|
59
|
+
assert.equal(data, '');
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
|
|
@@ -65,9 +65,9 @@ suite('fs file reading', () => {
|
|
|
65
65
|
const content = fs.readFileSync('elipses.txt', 'utf8');
|
|
66
66
|
|
|
67
67
|
for (let i = 0; i < content.length; i++) {
|
|
68
|
-
assert.
|
|
68
|
+
assert.equal(content[i], '…');
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
assert.
|
|
71
|
+
assert.equal(content.length, 10000);
|
|
72
72
|
});
|
|
73
73
|
});
|
package/tests/fs/rename.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { ErrnoError } from '../../dist/error.js';
|
|
4
4
|
import { fs } from '../common.js';
|
|
@@ -21,10 +21,10 @@ suite('Rename', () => {
|
|
|
21
21
|
*/
|
|
22
22
|
async function check_directory(dir: string) {
|
|
23
23
|
const contents = await fs.promises.readdir(dir);
|
|
24
|
-
assert.
|
|
24
|
+
assert.equal(contents.length, 2);
|
|
25
25
|
|
|
26
26
|
const subContents = await fs.promises.readdir(dir + '/_rename_me');
|
|
27
|
-
assert.
|
|
27
|
+
assert.equal(subContents.length, 1);
|
|
28
28
|
|
|
29
29
|
assert(await fs.promises.exists(dir + '/file.dat'));
|
|
30
30
|
assert(await fs.promises.exists(dir + '/_rename_me/lol.txt'));
|
|
@@ -71,37 +71,27 @@ suite('Rename', () => {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
test('File to Directory and Directory to File Rename', async () => {
|
|
74
|
-
const dir = '/
|
|
75
|
-
const file = '/
|
|
74
|
+
const dir = '/rename_file_dir_test';
|
|
75
|
+
const file = '/rename_file_dir_test.txt';
|
|
76
76
|
|
|
77
77
|
await fs.promises.mkdir(dir);
|
|
78
78
|
await fs.promises.writeFile(file, 'file contents go here');
|
|
79
79
|
|
|
80
80
|
await fs.promises.rename(file, dir).catch((error: ErrnoError) => {
|
|
81
81
|
assert(error instanceof ErrnoError);
|
|
82
|
-
assert(error.code
|
|
82
|
+
assert.match(error.code, /EISDIR|EPERM/);
|
|
83
83
|
});
|
|
84
|
-
|
|
85
|
-
// JV: Removing test for now. I noticed that you can do that in Node v0.12 on Mac,
|
|
86
|
-
// but it might be FS independent.
|
|
87
|
-
/*fs.rename(dir, file, function (e) {
|
|
88
|
-
if (e == null) {
|
|
89
|
-
throw new Error("Failed invariant: Cannot rename a directory over a file.");
|
|
90
|
-
} else {
|
|
91
|
-
assert.strictEqual(e.code, 'ENOTDIR');
|
|
92
|
-
}
|
|
93
|
-
});*/
|
|
94
84
|
});
|
|
95
85
|
|
|
96
86
|
test('rename directory inside itself', async () => {
|
|
97
|
-
const renDir1 = '/
|
|
98
|
-
const renDir2 = '/
|
|
87
|
+
const renDir1 = '/rename_dir_1';
|
|
88
|
+
const renDir2 = '/rename_dir_1/lol';
|
|
99
89
|
|
|
100
90
|
await fs.promises.mkdir(renDir1);
|
|
101
91
|
|
|
102
92
|
await fs.promises.rename(renDir1, renDir2).catch((error: ErrnoError) => {
|
|
103
93
|
assert(error instanceof ErrnoError);
|
|
104
|
-
assert.
|
|
94
|
+
assert.equal(error.code, 'EBUSY');
|
|
105
95
|
});
|
|
106
96
|
});
|
|
107
97
|
});
|
package/tests/fs/stat.test.ts
CHANGED
package/tests/fs/streams.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { fs } from '../common.js';
|
|
4
4
|
|
|
@@ -41,17 +41,17 @@ suite('ReadStream', () => {
|
|
|
41
41
|
|
|
42
42
|
test('ReadStream declared properties', () => {
|
|
43
43
|
const readStream = new fs.ReadStream();
|
|
44
|
-
assert.
|
|
45
|
-
assert.
|
|
46
|
-
assert.
|
|
44
|
+
assert.equal(readStream.bytesRead, undefined);
|
|
45
|
+
assert.equal(readStream.path, undefined);
|
|
46
|
+
assert.equal(readStream.pending, undefined);
|
|
47
47
|
|
|
48
48
|
// Assign values
|
|
49
49
|
readStream.bytesRead = 10;
|
|
50
50
|
readStream.path = testFilePath;
|
|
51
51
|
readStream.pending = false;
|
|
52
52
|
|
|
53
|
-
assert.
|
|
54
|
-
assert.
|
|
53
|
+
assert.equal(readStream.bytesRead, 10);
|
|
54
|
+
assert.equal(readStream.path, testFilePath);
|
|
55
55
|
assert(!readStream.pending);
|
|
56
56
|
});
|
|
57
57
|
|
|
@@ -102,17 +102,17 @@ suite('WriteStream', () => {
|
|
|
102
102
|
|
|
103
103
|
test('WriteStream declared properties', () => {
|
|
104
104
|
const writeStream = new fs.WriteStream();
|
|
105
|
-
assert.
|
|
106
|
-
assert.
|
|
107
|
-
assert.
|
|
105
|
+
assert.equal(writeStream.bytesWritten, undefined);
|
|
106
|
+
assert.equal(writeStream.path, undefined);
|
|
107
|
+
assert.equal(writeStream.pending, undefined);
|
|
108
108
|
|
|
109
109
|
// Assign values
|
|
110
110
|
writeStream.bytesWritten = 20;
|
|
111
111
|
writeStream.path = testFilePathWrite;
|
|
112
112
|
writeStream.pending = true;
|
|
113
113
|
|
|
114
|
-
assert.
|
|
115
|
-
assert.
|
|
114
|
+
assert.equal(writeStream.bytesWritten, 20);
|
|
115
|
+
assert.equal(writeStream.path, testFilePathWrite);
|
|
116
116
|
assert(writeStream.pending);
|
|
117
117
|
});
|
|
118
118
|
|
package/tests/fs/times.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { wait } from 'utilium';
|
|
4
4
|
import { ErrnoError } from '../../dist/error.js';
|
|
@@ -28,26 +28,26 @@ suite('times', () => {
|
|
|
28
28
|
|
|
29
29
|
await fs.promises.utimes(path, atime, mtime);
|
|
30
30
|
|
|
31
|
-
assert.
|
|
31
|
+
assert.deepEqual(unixTimestamps(await fs.promises.stat(path)), times);
|
|
32
32
|
|
|
33
33
|
await fs.promises.utimes('foobarbaz', atime, mtime).catch((error: ErrnoError) => {
|
|
34
34
|
assert(error instanceof ErrnoError);
|
|
35
|
-
assert.
|
|
35
|
+
assert.equal(error.code, 'ENOENT');
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
await using handle = await fs.promises.open(path, 'r');
|
|
39
39
|
|
|
40
40
|
await handle.utimes(atime, mtime);
|
|
41
|
-
assert.
|
|
41
|
+
assert.deepEqual(unixTimestamps(await handle.stat()), times);
|
|
42
42
|
|
|
43
43
|
fs.utimesSync(path, atime, mtime);
|
|
44
|
-
assert.
|
|
44
|
+
assert.deepEqual(unixTimestamps(fs.statSync(path)), times);
|
|
45
45
|
|
|
46
46
|
try {
|
|
47
47
|
fs.utimesSync('foobarbaz', atime, mtime);
|
|
48
48
|
} catch (error: any) {
|
|
49
49
|
assert(error instanceof ErrnoError);
|
|
50
|
-
assert.
|
|
50
|
+
assert.equal(error.code, 'ENOENT');
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
try {
|
package/tests/fs/watch.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { fs, type Stats } from '../common.js';
|
|
4
4
|
|
|
@@ -14,8 +14,8 @@ await fs.promises.writeFile(testFile, 'Initial content');
|
|
|
14
14
|
suite('Watch Features', () => {
|
|
15
15
|
test('fs.watch should emit events on file change', async () => {
|
|
16
16
|
using watcher = fs.watch(testFile, (eventType, filename) => {
|
|
17
|
-
assert.
|
|
18
|
-
assert.
|
|
17
|
+
assert.equal(eventType, 'change');
|
|
18
|
+
assert.equal(filename, 'test.txt');
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
// Modify the file to trigger the event
|
|
@@ -24,8 +24,8 @@ suite('Watch Features', () => {
|
|
|
24
24
|
|
|
25
25
|
test('fs.watch should emit events on file rename (delete)', async () => {
|
|
26
26
|
using watcher = fs.watch(testFile, (eventType, filename) => {
|
|
27
|
-
assert.
|
|
28
|
-
assert.
|
|
27
|
+
assert.equal(eventType, 'rename');
|
|
28
|
+
assert.equal(filename, 'test.txt');
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
// Delete the file to trigger the event
|
|
@@ -63,8 +63,8 @@ suite('Watch Features', () => {
|
|
|
63
63
|
|
|
64
64
|
test('fs.watch should work with directories', async () => {
|
|
65
65
|
using watcher = fs.watch(testDir, (eventType, filename) => {
|
|
66
|
-
assert.
|
|
67
|
-
assert.
|
|
66
|
+
assert.equal(eventType, 'change');
|
|
67
|
+
assert.equal(filename, 'newFile.txt');
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
await fs.promises.writeFile(`${testDir}/newFile.txt`, 'Content');
|
|
@@ -87,7 +87,7 @@ suite('Watch Features', () => {
|
|
|
87
87
|
using watcher = fs.watch(testDir, (eventType, filename) => {
|
|
88
88
|
const resolver = fileResolvers[filename];
|
|
89
89
|
assert.notEqual(resolver, undefined); // should have a resolver so file is expected
|
|
90
|
-
assert.
|
|
90
|
+
assert.equal(eventType, resolver.eventType);
|
|
91
91
|
resolver.resolver.resolve();
|
|
92
92
|
});
|
|
93
93
|
|
|
@@ -102,8 +102,8 @@ suite('Watch Features', () => {
|
|
|
102
102
|
await fs.promises.writeFile(tempFile, 'Temporary content');
|
|
103
103
|
|
|
104
104
|
using watcher = fs.watch(tempFile, (eventType, filename) => {
|
|
105
|
-
assert.
|
|
106
|
-
assert.
|
|
105
|
+
assert.equal(eventType, 'rename');
|
|
106
|
+
assert.equal(filename, 'tempFile.txt');
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
await fs.promises.unlink(tempFile);
|
package/tests/fs/write.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { fs } from '../common.js';
|
|
4
4
|
const fn = 'write.txt';
|
|
@@ -9,11 +9,11 @@ suite('write', () => {
|
|
|
9
9
|
const handle = await fs.promises.open(fn, 'w', 0o644);
|
|
10
10
|
await handle.write('', 0, 'utf8');
|
|
11
11
|
const { bytesWritten } = await handle.write(expected, 0, 'utf8');
|
|
12
|
-
assert.
|
|
12
|
+
assert.equal(bytesWritten, Buffer.from(expected).length);
|
|
13
13
|
await handle.close();
|
|
14
14
|
|
|
15
15
|
const data = await fs.promises.readFile(fn, 'utf8');
|
|
16
|
-
assert.
|
|
16
|
+
assert.equal(data, expected);
|
|
17
17
|
|
|
18
18
|
await fs.promises.unlink(fn);
|
|
19
19
|
});
|
|
@@ -25,7 +25,7 @@ suite('write', () => {
|
|
|
25
25
|
|
|
26
26
|
const written = await handle.write(expected, 0, expected.length, null);
|
|
27
27
|
|
|
28
|
-
assert.
|
|
28
|
+
assert.equal(expected.length, written.bytesWritten);
|
|
29
29
|
|
|
30
30
|
await handle.close();
|
|
31
31
|
|
|
@@ -38,16 +38,16 @@ suite('write', () => {
|
|
|
38
38
|
const fd = fs.openSync(fn, 'w');
|
|
39
39
|
|
|
40
40
|
let written = fs.writeSync(fd, '');
|
|
41
|
-
assert.
|
|
41
|
+
assert.equal(written, 0);
|
|
42
42
|
|
|
43
43
|
fs.writeSync(fd, 'foo');
|
|
44
44
|
|
|
45
45
|
const data = Buffer.from('bár');
|
|
46
46
|
written = fs.writeSync(fd, data, 0, data.length);
|
|
47
|
-
assert.
|
|
47
|
+
assert.equal(written, 4);
|
|
48
48
|
|
|
49
49
|
fs.closeSync(fd);
|
|
50
50
|
|
|
51
|
-
assert.
|
|
51
|
+
assert.equal(fs.readFileSync(fn, 'utf8'), 'foobár');
|
|
52
52
|
});
|
|
53
53
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { fs } from '../common.js';
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ suite('writeFile', () => {
|
|
|
10
10
|
const filename = 'test.txt';
|
|
11
11
|
await fs.promises.writeFile(filename, s);
|
|
12
12
|
const data = await fs.promises.readFile(filename);
|
|
13
|
-
assert.
|
|
13
|
+
assert.equal(data.length, Buffer.from(s).length);
|
|
14
14
|
await fs.promises.unlink(filename);
|
|
15
15
|
});
|
|
16
16
|
|
|
@@ -20,7 +20,7 @@ suite('writeFile', () => {
|
|
|
20
20
|
|
|
21
21
|
await fs.promises.writeFile(filename, expected);
|
|
22
22
|
const actual = await fs.promises.readFile(filename);
|
|
23
|
-
assert.
|
|
23
|
+
assert.equal(actual.length, expected.length);
|
|
24
24
|
|
|
25
25
|
await fs.promises.unlink(filename);
|
|
26
26
|
});
|
|
@@ -35,7 +35,7 @@ suite('writeFile', () => {
|
|
|
35
35
|
await fs.promises.writeFile(filePath, buffer);
|
|
36
36
|
|
|
37
37
|
const read = await fs.promises.readFile(filePath, 'base64');
|
|
38
|
-
assert.
|
|
38
|
+
assert.equal(read, data);
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
|
|
@@ -47,7 +47,7 @@ suite('File Writing with Custom Mode', () => {
|
|
|
47
47
|
fs.writeFileSync(file, '123', { mode });
|
|
48
48
|
|
|
49
49
|
const content = fs.readFileSync(file, 'utf8');
|
|
50
|
-
assert.
|
|
50
|
+
assert.equal(content, '123');
|
|
51
51
|
assert((fs.statSync(file).mode & 0o777) === mode);
|
|
52
52
|
|
|
53
53
|
fs.unlinkSync(file);
|
|
@@ -60,7 +60,7 @@ suite('File Writing with Custom Mode', () => {
|
|
|
60
60
|
fs.appendFileSync(file, 'abc', { mode });
|
|
61
61
|
|
|
62
62
|
const content = fs.readFileSync(file, { encoding: 'utf8' });
|
|
63
|
-
assert.
|
|
63
|
+
assert.equal(content, 'abc');
|
|
64
64
|
|
|
65
65
|
assert((fs.statSync(file).mode & 0o777) === mode);
|
|
66
66
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
2
|
import { suite, test } from 'node:test';
|
|
3
3
|
import { MessageChannel } from 'node:worker_threads';
|
|
4
4
|
import { Port } from '../../dist/backends/port/fs.js';
|
|
@@ -26,7 +26,7 @@ await suite('Timeout', { timeout: 1000 }, () => {
|
|
|
26
26
|
error = e;
|
|
27
27
|
}
|
|
28
28
|
assert(error! instanceof ErrnoError);
|
|
29
|
-
assert.
|
|
29
|
+
assert.equal(error.code, 'EIO');
|
|
30
30
|
assert(error.message.includes('RPC Failed'));
|
|
31
31
|
});
|
|
32
32
|
|
|
@@ -40,7 +40,7 @@ await suite('Timeout', { timeout: 1000 }, () => {
|
|
|
40
40
|
error = e;
|
|
41
41
|
}
|
|
42
42
|
assert(error! instanceof ErrnoError);
|
|
43
|
-
assert.
|
|
43
|
+
assert.equal(error.code, 'EIO');
|
|
44
44
|
assert(error.message.includes('RPC Failed'));
|
|
45
45
|
});
|
|
46
46
|
});
|