@zenfs/core 1.2.1 → 1.2.3
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/backends/store/simple.d.ts +3 -0
- package/dist/backends/store/simple.js +6 -0
- package/dist/backends/store/store.d.ts +16 -6
- package/dist/backends/store/store.js +7 -1
- package/dist/emulation/cache.d.ts +14 -2
- package/dist/emulation/cache.js +25 -0
- package/dist/emulation/promises.js +22 -12
- package/dist/emulation/sync.js +11 -11
- package/dist/mixins/async.js +17 -3
- package/package.json +1 -1
- package/src/backends/store/simple.ts +9 -0
- package/src/backends/store/store.ts +23 -6
- package/src/emulation/cache.ts +32 -3
- package/src/emulation/promises.ts +23 -12
- package/src/emulation/sync.ts +11 -11
- package/src/mixins/async.ts +22 -3
- package/tests/fs/appendFile.test.ts +3 -3
- package/tests/fs/dir.test.ts +7 -7
- package/tests/fs/directory.test.ts +7 -7
- package/tests/fs/links.test.ts +3 -3
- package/tests/fs/open.test.ts +2 -2
- package/tests/fs/permissions.test.ts +1 -1
- package/tests/fs/read.test.ts +5 -5
- package/tests/fs/readFile.test.ts +2 -2
- package/tests/fs/rename.test.ts +4 -4
- package/tests/fs/streams.test.ts +19 -19
- package/tests/fs/times.test.ts +4 -4
- package/tests/fs/watch.test.ts +10 -10
- package/tests/fs/write.test.ts +5 -5
- package/tests/fs/writeFile.test.ts +5 -5
- package/tests/handle.test.ts +2 -2
- package/tests/mutex.test.ts +1 -1
- package/tests/port/timeout.test.ts +2 -2
package/src/emulation/sync.ts
CHANGED
|
@@ -106,7 +106,7 @@ export function unlinkSync(path: fs.PathLike): void {
|
|
|
106
106
|
path = normalizePath(path);
|
|
107
107
|
const { fs, path: resolved } = resolveMount(path);
|
|
108
108
|
try {
|
|
109
|
-
if (config.checkAccess && !(cache.
|
|
109
|
+
if (config.checkAccess && !(cache.getStatsSync(path) || fs.statSync(resolved)).hasAccess(constants.W_OK)) {
|
|
110
110
|
throw ErrnoError.With('EACCES', resolved, 'unlink');
|
|
111
111
|
}
|
|
112
112
|
fs.unlinkSync(resolved);
|
|
@@ -387,7 +387,7 @@ export function rmdirSync(path: fs.PathLike): void {
|
|
|
387
387
|
path = normalizePath(path);
|
|
388
388
|
const { fs, path: resolved } = resolveMount(realpathSync(path));
|
|
389
389
|
try {
|
|
390
|
-
const stats = cache.
|
|
390
|
+
const stats = cache.getStatsSync(path) || fs.statSync(resolved);
|
|
391
391
|
if (!stats.isDirectory()) {
|
|
392
392
|
throw ErrnoError.With('ENOTDIR', resolved, 'rmdir');
|
|
393
393
|
}
|
|
@@ -460,8 +460,8 @@ export function readdirSync(
|
|
|
460
460
|
const { fs, path: resolved } = resolveMount(realpathSync(path));
|
|
461
461
|
let entries: string[];
|
|
462
462
|
try {
|
|
463
|
-
const stats = cache.
|
|
464
|
-
cache.
|
|
463
|
+
const stats = cache.getStatsSync(path) || fs.statSync(resolved);
|
|
464
|
+
cache.setStatsSync(path, stats);
|
|
465
465
|
if (config.checkAccess && !stats.hasAccess(constants.R_OK)) {
|
|
466
466
|
throw ErrnoError.With('EACCES', resolved, 'readdir');
|
|
467
467
|
}
|
|
@@ -488,8 +488,8 @@ export function readdirSync(
|
|
|
488
488
|
// Iterate over entries and handle recursive case if needed
|
|
489
489
|
const values: (string | Dirent | Buffer)[] = [];
|
|
490
490
|
for (const entry of entries) {
|
|
491
|
-
const entryStat = cache.
|
|
492
|
-
cache.
|
|
491
|
+
const entryStat = cache.getStatsSync(join(path, entry)) || fs.statSync(join(resolved, entry));
|
|
492
|
+
cache.setStatsSync(join(path, entry), entryStat);
|
|
493
493
|
|
|
494
494
|
if (options?.withFileTypes) {
|
|
495
495
|
values.push(new Dirent(entry, entryStat));
|
|
@@ -513,7 +513,7 @@ export function readdirSync(
|
|
|
513
513
|
}
|
|
514
514
|
|
|
515
515
|
if (!options?._isIndirect) {
|
|
516
|
-
cache.
|
|
516
|
+
cache.clearStatsSync();
|
|
517
517
|
}
|
|
518
518
|
return values as string[] | Dirent[] | Buffer[];
|
|
519
519
|
}
|
|
@@ -671,7 +671,7 @@ export function rmSync(path: fs.PathLike, options?: fs.RmOptions & InternalOptio
|
|
|
671
671
|
|
|
672
672
|
let stats: Stats | undefined;
|
|
673
673
|
try {
|
|
674
|
-
stats = cache.
|
|
674
|
+
stats = cache.getStatsSync(path) || statSync(path);
|
|
675
675
|
} catch (error) {
|
|
676
676
|
if ((error as ErrnoError).code != 'ENOENT' || !options?.force) throw error;
|
|
677
677
|
}
|
|
@@ -680,7 +680,7 @@ export function rmSync(path: fs.PathLike, options?: fs.RmOptions & InternalOptio
|
|
|
680
680
|
return;
|
|
681
681
|
}
|
|
682
682
|
|
|
683
|
-
cache.
|
|
683
|
+
cache.setStatsSync(path, stats);
|
|
684
684
|
|
|
685
685
|
switch (stats.mode & constants.S_IFMT) {
|
|
686
686
|
case constants.S_IFDIR:
|
|
@@ -701,12 +701,12 @@ export function rmSync(path: fs.PathLike, options?: fs.RmOptions & InternalOptio
|
|
|
701
701
|
case constants.S_IFIFO:
|
|
702
702
|
case constants.S_IFSOCK:
|
|
703
703
|
default:
|
|
704
|
-
cache.
|
|
704
|
+
cache.clearStatsSync();
|
|
705
705
|
throw new ErrnoError(Errno.EPERM, 'File type not supported', path, 'rm');
|
|
706
706
|
}
|
|
707
707
|
|
|
708
708
|
if (!options?._isIndirect) {
|
|
709
|
-
cache.
|
|
709
|
+
cache.clearStatsSync();
|
|
710
710
|
}
|
|
711
711
|
}
|
|
712
712
|
rmSync satisfies typeof fs.rmSync;
|
package/src/mixins/async.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { StoreFS } from '../backends/store/fs.js';
|
|
2
|
+
import type { Store } from '../backends/store/store.js';
|
|
1
3
|
import { join } from '../emulation/path.js';
|
|
2
4
|
import { Errno, ErrnoError } from '../error.js';
|
|
3
5
|
import { parseFlag, PreloadFile, type File } from '../file.js';
|
|
@@ -72,6 +74,22 @@ export function Async<T extends typeof FileSystem>(
|
|
|
72
74
|
|
|
73
75
|
await this._sync.ready();
|
|
74
76
|
|
|
77
|
+
// optimization: for 2 storeFS', we copy at a lower abstraction level.
|
|
78
|
+
if (this._sync instanceof StoreFS && this instanceof StoreFS) {
|
|
79
|
+
const sync = (this._sync as StoreFS<Store>)['store'].transaction();
|
|
80
|
+
const async = (this as StoreFS<Store>)['store'].transaction();
|
|
81
|
+
|
|
82
|
+
const promises = [];
|
|
83
|
+
for (const key of sync.keysSync()) {
|
|
84
|
+
promises.push(async.set(key, sync.getSync(key)));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
await Promise.all(promises);
|
|
88
|
+
|
|
89
|
+
this._isInitialized = true;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
75
93
|
try {
|
|
76
94
|
await this.crossCopy('/');
|
|
77
95
|
this._isInitialized = true;
|
|
@@ -175,10 +193,11 @@ export function Async<T extends typeof FileSystem>(
|
|
|
175
193
|
const stats = await this.stat(path);
|
|
176
194
|
this._sync.mkdirSync(path, stats.mode);
|
|
177
195
|
}
|
|
178
|
-
const
|
|
179
|
-
for (const file of
|
|
180
|
-
|
|
196
|
+
const promises = [];
|
|
197
|
+
for (const file of await this.readdir(path)) {
|
|
198
|
+
promises.push(this.crossCopy(join(path, file)));
|
|
181
199
|
}
|
|
200
|
+
await Promise.all(promises);
|
|
182
201
|
}
|
|
183
202
|
|
|
184
203
|
/**
|
|
@@ -10,7 +10,7 @@ suite('appendFile', () => {
|
|
|
10
10
|
const filename = 'append.txt';
|
|
11
11
|
await fs.promises.appendFile(filename, content);
|
|
12
12
|
const data = await fs.promises.readFile(filename, 'utf8');
|
|
13
|
-
assert(data
|
|
13
|
+
assert.equal(data, content);
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
test('append data to a non-empty file', async () => {
|
|
@@ -19,7 +19,7 @@ suite('appendFile', () => {
|
|
|
19
19
|
await fs.promises.writeFile(filename, original);
|
|
20
20
|
await fs.promises.appendFile(filename, content);
|
|
21
21
|
const data = await fs.promises.readFile(filename, 'utf8');
|
|
22
|
-
assert(data
|
|
22
|
+
assert.equal(data, original + content);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('append a buffer to the file', async () => {
|
|
@@ -28,6 +28,6 @@ suite('appendFile', () => {
|
|
|
28
28
|
await fs.promises.writeFile(filename, original);
|
|
29
29
|
await fs.promises.appendFile(filename, content);
|
|
30
30
|
const data = await fs.promises.readFile(filename, 'utf8');
|
|
31
|
-
assert(data
|
|
31
|
+
assert.equal(data, original + content);
|
|
32
32
|
});
|
|
33
33
|
});
|
package/tests/fs/dir.test.ts
CHANGED
|
@@ -18,8 +18,8 @@ suite('Dirent', () => {
|
|
|
18
18
|
const stats = await fs.promises.lstat(testFile);
|
|
19
19
|
const dirent = new fs.Dirent(testFile, stats);
|
|
20
20
|
|
|
21
|
-
assert(dirent.name
|
|
22
|
-
assert(dirent.parentPath
|
|
21
|
+
assert.equal(dirent.name, testFile);
|
|
22
|
+
assert.equal(dirent.parentPath, testFile);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('Dirent.isFile', async () => {
|
|
@@ -68,7 +68,7 @@ suite('Dir', () => {
|
|
|
68
68
|
assert(testFiles.includes(dirent2?.name));
|
|
69
69
|
|
|
70
70
|
const dirent3 = await dir.read();
|
|
71
|
-
assert(dirent3
|
|
71
|
+
assert.strictEqual(dirent3, null);
|
|
72
72
|
|
|
73
73
|
await dir.close();
|
|
74
74
|
});
|
|
@@ -76,8 +76,8 @@ suite('Dir', () => {
|
|
|
76
76
|
test('Dir read() method (Callback varient)', (_, done) => {
|
|
77
77
|
const dir = new fs.Dir(testDirPath);
|
|
78
78
|
dir.read((err, dirent) => {
|
|
79
|
-
assert(err
|
|
80
|
-
assert(dirent
|
|
79
|
+
assert.strictEqual(err, undefined);
|
|
80
|
+
assert.notEqual(dirent, undefined);
|
|
81
81
|
assert(dirent instanceof fs.Dirent);
|
|
82
82
|
assert(testFiles.includes(dirent?.name));
|
|
83
83
|
dir.closeSync();
|
|
@@ -97,7 +97,7 @@ suite('Dir', () => {
|
|
|
97
97
|
assert(testFiles.includes(dirent2?.name));
|
|
98
98
|
|
|
99
99
|
const dirent3 = dir.readSync();
|
|
100
|
-
assert(dirent3
|
|
100
|
+
assert.strictEqual(dirent3, null);
|
|
101
101
|
|
|
102
102
|
dir.closeSync();
|
|
103
103
|
});
|
|
@@ -122,7 +122,7 @@ suite('Dir', () => {
|
|
|
122
122
|
dirents.push(dirent);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
assert(dirents.length
|
|
125
|
+
assert.strictEqual(dirents.length, 2);
|
|
126
126
|
assert(dirents[0] instanceof fs.Dirent);
|
|
127
127
|
assert(testFiles.includes(dirents[0].name));
|
|
128
128
|
assert(testFiles.includes(dirents[1].name));
|
|
@@ -17,7 +17,7 @@ suite('Directory', () => {
|
|
|
17
17
|
await fs.promises.mkdir('/nested/dir');
|
|
18
18
|
} catch (error: any) {
|
|
19
19
|
assert(error instanceof ErrnoError);
|
|
20
|
-
assert(error.code
|
|
20
|
+
assert.strictEqual(error.code, 'ENOENT');
|
|
21
21
|
}
|
|
22
22
|
assert(!(await fs.promises.exists('/nested/dir')));
|
|
23
23
|
});
|
|
@@ -51,7 +51,7 @@ suite('Directory', () => {
|
|
|
51
51
|
fs.readdirSync('/two');
|
|
52
52
|
} catch (error: any) {
|
|
53
53
|
assert(error instanceof ErrnoError);
|
|
54
|
-
assert(error.code
|
|
54
|
+
assert.strictEqual(error.code, 'EACCES');
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
|
|
@@ -63,7 +63,7 @@ suite('Directory', () => {
|
|
|
63
63
|
await fs.promises.rmdir('/rmdirTest');
|
|
64
64
|
} catch (error: any) {
|
|
65
65
|
assert(error instanceof ErrnoError);
|
|
66
|
-
assert(error.code
|
|
66
|
+
assert.strictEqual(error.code, 'ENOTEMPTY');
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
|
|
@@ -75,7 +75,7 @@ suite('Directory', () => {
|
|
|
75
75
|
} catch (error: any) {
|
|
76
76
|
assert(error instanceof ErrnoError);
|
|
77
77
|
wasThrown = true;
|
|
78
|
-
assert(error.code
|
|
78
|
+
assert.strictEqual(error.code, 'ENOTDIR');
|
|
79
79
|
}
|
|
80
80
|
assert(wasThrown);
|
|
81
81
|
});
|
|
@@ -85,7 +85,7 @@ suite('Directory', () => {
|
|
|
85
85
|
await fs.promises.readdir('a.js');
|
|
86
86
|
} catch (error: any) {
|
|
87
87
|
assert(error instanceof ErrnoError);
|
|
88
|
-
assert(error.code
|
|
88
|
+
assert.strictEqual(error.code, 'ENOTDIR');
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
91
|
|
|
@@ -97,7 +97,7 @@ suite('Directory', () => {
|
|
|
97
97
|
} catch (error: any) {
|
|
98
98
|
assert(error instanceof ErrnoError);
|
|
99
99
|
wasThrown = true;
|
|
100
|
-
assert(error.code
|
|
100
|
+
assert.strictEqual(error.code, 'ENOENT');
|
|
101
101
|
}
|
|
102
102
|
assert(wasThrown);
|
|
103
103
|
});
|
|
@@ -107,7 +107,7 @@ suite('Directory', () => {
|
|
|
107
107
|
await fs.promises.readdir('/does/not/exist');
|
|
108
108
|
} catch (error: any) {
|
|
109
109
|
assert(error instanceof ErrnoError);
|
|
110
|
-
assert(error.code
|
|
110
|
+
assert.strictEqual(error.code, 'ENOENT');
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
|
package/tests/fs/links.test.ts
CHANGED
|
@@ -19,7 +19,7 @@ suite('Links', () => {
|
|
|
19
19
|
|
|
20
20
|
test('readlink', async () => {
|
|
21
21
|
const destination = await fs.promises.readlink(symlink);
|
|
22
|
-
assert(destination
|
|
22
|
+
assert.strictEqual(destination, target);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('unlink', async () => {
|
|
@@ -32,7 +32,7 @@ suite('Links', () => {
|
|
|
32
32
|
await fs.promises.link(target, hardlink);
|
|
33
33
|
const targetContent = await fs.promises.readFile(target, 'utf8');
|
|
34
34
|
const linkContent = await fs.promises.readFile(hardlink, 'utf8');
|
|
35
|
-
assert(targetContent
|
|
35
|
+
assert.strictEqual(targetContent, linkContent);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
test('file inside symlinked directory', async () => {
|
|
@@ -41,6 +41,6 @@ suite('Links', () => {
|
|
|
41
41
|
const link = join('link', target);
|
|
42
42
|
assert((await fs.promises.realpath(link)) === target);
|
|
43
43
|
const linkContent = await fs.promises.readFile(link, 'utf8');
|
|
44
|
-
assert(targetContent
|
|
44
|
+
assert.strictEqual(targetContent, linkContent);
|
|
45
45
|
});
|
|
46
46
|
});
|
package/tests/fs/open.test.ts
CHANGED
|
@@ -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(error?.code
|
|
15
|
+
assert.strictEqual(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(error?.code
|
|
26
|
+
assert.strictEqual(error?.code, 'ENOENT');
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
|
|
@@ -10,7 +10,7 @@ suite('Permissions', () => {
|
|
|
10
10
|
async function test_item(path: string): Promise<void> {
|
|
11
11
|
const stats = await fs.promises.stat(path).catch((error: ErrnoError) => {
|
|
12
12
|
assert(error instanceof ErrnoError);
|
|
13
|
-
assert(error.code
|
|
13
|
+
assert.strictEqual(error.code, 'EACCES');
|
|
14
14
|
});
|
|
15
15
|
if (!stats) {
|
|
16
16
|
return;
|
package/tests/fs/read.test.ts
CHANGED
|
@@ -10,7 +10,7 @@ suite('read', () => {
|
|
|
10
10
|
const handle = await fs.promises.open(filepath, 'r');
|
|
11
11
|
const { bytesRead, buffer } = await handle.read(Buffer.alloc(expected.length), 0, expected.length, 0);
|
|
12
12
|
|
|
13
|
-
assert(bytesRead
|
|
13
|
+
assert.equal(bytesRead, expected.length);
|
|
14
14
|
assert(buffer.toString() == expected);
|
|
15
15
|
});
|
|
16
16
|
|
|
@@ -19,7 +19,7 @@ suite('read', () => {
|
|
|
19
19
|
const buffer = Buffer.alloc(expected.length);
|
|
20
20
|
const bytesRead = fs.readSync(fd, buffer, 0, expected.length, 0);
|
|
21
21
|
|
|
22
|
-
assert(bytesRead
|
|
22
|
+
assert.equal(bytesRead, expected.length);
|
|
23
23
|
assert(buffer.toString() == expected);
|
|
24
24
|
});
|
|
25
25
|
});
|
|
@@ -44,7 +44,7 @@ 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(bytesRead
|
|
47
|
+
assert.strictEqual(bytesRead, expected.length);
|
|
48
48
|
assert(bufferAsync.toString() === expected);
|
|
49
49
|
});
|
|
50
50
|
|
|
@@ -53,7 +53,7 @@ suite('read buffer', () => {
|
|
|
53
53
|
const bytesRead = fs.readSync(fd, bufferSync, 0, expected.length, 0);
|
|
54
54
|
|
|
55
55
|
assert(bufferSync.toString() === expected);
|
|
56
|
-
assert(bytesRead
|
|
56
|
+
assert.strictEqual(bytesRead, expected.length);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
test('read file synchronously to non-zero offset', () => {
|
|
@@ -62,6 +62,6 @@ suite('read buffer', () => {
|
|
|
62
62
|
const bytesRead = fs.readSync(fd, buffer, 10, expected.length, 0);
|
|
63
63
|
|
|
64
64
|
assert(buffer.subarray(10, buffer.length).toString() === expected);
|
|
65
|
-
assert(bytesRead
|
|
65
|
+
assert.strictEqual(bytesRead, expected.length);
|
|
66
66
|
});
|
|
67
67
|
});
|
|
@@ -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(content[i]
|
|
68
|
+
assert.strictEqual(content[i], '…');
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
assert(content.length
|
|
71
|
+
assert.strictEqual(content.length, 10000);
|
|
72
72
|
});
|
|
73
73
|
});
|
package/tests/fs/rename.test.ts
CHANGED
|
@@ -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(contents.length
|
|
24
|
+
assert.strictEqual(contents.length, 2);
|
|
25
25
|
|
|
26
26
|
const subContents = await fs.promises.readdir(dir + '/_rename_me');
|
|
27
|
-
assert(subContents.length
|
|
27
|
+
assert.strictEqual(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'));
|
|
@@ -88,7 +88,7 @@ suite('Rename', () => {
|
|
|
88
88
|
if (e == null) {
|
|
89
89
|
throw new Error("Failed invariant: Cannot rename a directory over a file.");
|
|
90
90
|
} else {
|
|
91
|
-
assert(e.code
|
|
91
|
+
assert.strictEqual(e.code, 'ENOTDIR');
|
|
92
92
|
}
|
|
93
93
|
});*/
|
|
94
94
|
});
|
|
@@ -101,7 +101,7 @@ suite('Rename', () => {
|
|
|
101
101
|
|
|
102
102
|
await fs.promises.rename(renDir1, renDir2).catch((error: ErrnoError) => {
|
|
103
103
|
assert(error instanceof ErrnoError);
|
|
104
|
-
assert(error.code
|
|
104
|
+
assert.strictEqual(error.code, 'EBUSY');
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
});
|
package/tests/fs/streams.test.ts
CHANGED
|
@@ -18,7 +18,7 @@ suite('ReadStream', () => {
|
|
|
18
18
|
data += chunk;
|
|
19
19
|
});
|
|
20
20
|
readStream.on('end', () => {
|
|
21
|
-
assert(data
|
|
21
|
+
assert.equal(data, testData);
|
|
22
22
|
done();
|
|
23
23
|
});
|
|
24
24
|
readStream.on('error', err => {
|
|
@@ -33,7 +33,7 @@ suite('ReadStream', () => {
|
|
|
33
33
|
closed = true;
|
|
34
34
|
});
|
|
35
35
|
readStream.close(err => {
|
|
36
|
-
assert(err
|
|
36
|
+
assert.strictEqual(err, undefined);
|
|
37
37
|
assert(closed);
|
|
38
38
|
done();
|
|
39
39
|
});
|
|
@@ -41,27 +41,27 @@ suite('ReadStream', () => {
|
|
|
41
41
|
|
|
42
42
|
test('ReadStream declared properties', () => {
|
|
43
43
|
const readStream = new fs.ReadStream();
|
|
44
|
-
assert(readStream.bytesRead
|
|
45
|
-
assert(readStream.path
|
|
46
|
-
assert(readStream.pending
|
|
44
|
+
assert.strictEqual(readStream.bytesRead, undefined);
|
|
45
|
+
assert.strictEqual(readStream.path, undefined);
|
|
46
|
+
assert.strictEqual(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(readStream.bytesRead
|
|
54
|
-
assert(readStream.path
|
|
53
|
+
assert.strictEqual(readStream.bytesRead, 10);
|
|
54
|
+
assert.strictEqual(readStream.path, testFilePath);
|
|
55
55
|
assert(!readStream.pending);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
test('ReadStream close method can be called multiple times', (_, done) => {
|
|
59
59
|
const readStream = new fs.ReadStream();
|
|
60
60
|
readStream.close(err => {
|
|
61
|
-
assert(err
|
|
61
|
+
assert.strictEqual(err, undefined);
|
|
62
62
|
// Call close again
|
|
63
63
|
readStream.close(err2 => {
|
|
64
|
-
assert(err2
|
|
64
|
+
assert.strictEqual(err2, undefined);
|
|
65
65
|
done();
|
|
66
66
|
});
|
|
67
67
|
});
|
|
@@ -94,7 +94,7 @@ suite('WriteStream', () => {
|
|
|
94
94
|
closed = true;
|
|
95
95
|
});
|
|
96
96
|
writeStream.close(err => {
|
|
97
|
-
assert(err
|
|
97
|
+
assert.strictEqual(err, undefined);
|
|
98
98
|
assert(closed);
|
|
99
99
|
done();
|
|
100
100
|
});
|
|
@@ -102,27 +102,27 @@ suite('WriteStream', () => {
|
|
|
102
102
|
|
|
103
103
|
test('WriteStream declared properties', () => {
|
|
104
104
|
const writeStream = new fs.WriteStream();
|
|
105
|
-
assert(writeStream.bytesWritten
|
|
106
|
-
assert(writeStream.path
|
|
107
|
-
assert(writeStream.pending
|
|
105
|
+
assert.strictEqual(writeStream.bytesWritten, undefined);
|
|
106
|
+
assert.strictEqual(writeStream.path, undefined);
|
|
107
|
+
assert.strictEqual(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(writeStream.bytesWritten
|
|
115
|
-
assert(writeStream.path
|
|
114
|
+
assert.strictEqual(writeStream.bytesWritten, 20);
|
|
115
|
+
assert.strictEqual(writeStream.path, testFilePathWrite);
|
|
116
116
|
assert(writeStream.pending);
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
test('WriteStream close method can be called multiple times', (_, done) => {
|
|
120
120
|
const writeStream = new fs.WriteStream();
|
|
121
121
|
writeStream.close(err => {
|
|
122
|
-
assert(err
|
|
122
|
+
assert.strictEqual(err, undefined);
|
|
123
123
|
// Call close again
|
|
124
124
|
writeStream.close(err2 => {
|
|
125
|
-
assert(err2
|
|
125
|
+
assert.strictEqual(err2, undefined);
|
|
126
126
|
done();
|
|
127
127
|
});
|
|
128
128
|
});
|
|
@@ -139,7 +139,7 @@ suite('FileHandle', () => {
|
|
|
139
139
|
data += chunk;
|
|
140
140
|
});
|
|
141
141
|
readStream.on('end', () => {
|
|
142
|
-
assert(data
|
|
142
|
+
assert.equal(data, testData);
|
|
143
143
|
resolve();
|
|
144
144
|
});
|
|
145
145
|
readStream.on('error', reject);
|
|
@@ -159,7 +159,7 @@ suite('FileHandle', () => {
|
|
|
159
159
|
writeStream.on('error', reject);
|
|
160
160
|
});
|
|
161
161
|
const data = await fs.promises.readFile(testFilePathWrite, 'utf8');
|
|
162
|
-
assert(data
|
|
162
|
+
assert.equal(data, testData);
|
|
163
163
|
await fileHandle.close();
|
|
164
164
|
});
|
|
165
165
|
|
package/tests/fs/times.test.ts
CHANGED
|
@@ -21,7 +21,7 @@ suite('times', () => {
|
|
|
21
21
|
|
|
22
22
|
await fs.promises.utimes('foobarbaz', atime, mtime).catch((error: ErrnoError) => {
|
|
23
23
|
assert(error instanceof ErrnoError);
|
|
24
|
-
assert(error.code
|
|
24
|
+
assert.strictEqual(error.code, 'ENOENT');
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
// don't close this fd
|
|
@@ -40,21 +40,21 @@ suite('times', () => {
|
|
|
40
40
|
expect_assert(handle.fd, atime, mtime);
|
|
41
41
|
} catch (error: any) {
|
|
42
42
|
assert(error instanceof ErrnoError);
|
|
43
|
-
assert(error.code
|
|
43
|
+
assert.strictEqual(error.code, 'ENOSYS');
|
|
44
44
|
}
|
|
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(error.code
|
|
50
|
+
assert.strictEqual(error.code, 'ENOENT');
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
try {
|
|
54
54
|
fs.futimesSync(-1, atime, mtime);
|
|
55
55
|
} catch (error: any) {
|
|
56
56
|
assert(error instanceof ErrnoError);
|
|
57
|
-
assert(error.code
|
|
57
|
+
assert.equal(error.code, 'EBADF');
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
package/tests/fs/watch.test.ts
CHANGED
|
@@ -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(eventType
|
|
18
|
-
assert(filename
|
|
17
|
+
assert.strictEqual(eventType, 'change');
|
|
18
|
+
assert.strictEqual(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(eventType
|
|
28
|
-
assert(filename
|
|
27
|
+
assert.strictEqual(eventType, 'rename');
|
|
28
|
+
assert.strictEqual(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(eventType
|
|
67
|
-
assert(filename
|
|
66
|
+
assert.strictEqual(eventType, 'change');
|
|
67
|
+
assert.strictEqual(filename, 'newFile.txt');
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
await fs.promises.writeFile(`${testDir}/newFile.txt`, 'Content');
|
|
@@ -77,8 +77,8 @@ suite('Watch Features', () => {
|
|
|
77
77
|
await fs.promises.writeFile(oldFile, 'Some content');
|
|
78
78
|
|
|
79
79
|
using watcher = fs.watch(testDir, (eventType, filename) => {
|
|
80
|
-
assert(eventType
|
|
81
|
-
assert(filename
|
|
80
|
+
assert.strictEqual(eventType, 'rename');
|
|
81
|
+
assert.strictEqual(filename, 'oldFile.txt');
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
// Rename the file to trigger the event
|
|
@@ -91,8 +91,8 @@ suite('Watch Features', () => {
|
|
|
91
91
|
await fs.promises.writeFile(tempFile, 'Temporary content');
|
|
92
92
|
|
|
93
93
|
using watcher = fs.watch(tempFile, (eventType, filename) => {
|
|
94
|
-
assert(eventType
|
|
95
|
-
assert(filename
|
|
94
|
+
assert.strictEqual(eventType, 'rename');
|
|
95
|
+
assert.strictEqual(filename, 'tempFile.txt');
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
await fs.promises.unlink(tempFile);
|
package/tests/fs/write.test.ts
CHANGED
|
@@ -10,11 +10,11 @@ suite('write', () => {
|
|
|
10
10
|
const handle = await fs.promises.open(fn, 'w', 0o644);
|
|
11
11
|
await handle.write('', 0, 'utf8');
|
|
12
12
|
const { bytesWritten } = await handle.write(expected, 0, 'utf8');
|
|
13
|
-
assert(bytesWritten
|
|
13
|
+
assert.strictEqual(bytesWritten, Buffer.from(expected).length);
|
|
14
14
|
await handle.close();
|
|
15
15
|
|
|
16
16
|
const data = await fs.promises.readFile(fn, 'utf8');
|
|
17
|
-
assert(data
|
|
17
|
+
assert.strictEqual(data, expected);
|
|
18
18
|
|
|
19
19
|
await fs.promises.unlink(fn);
|
|
20
20
|
});
|
|
@@ -27,7 +27,7 @@ suite('write', () => {
|
|
|
27
27
|
|
|
28
28
|
const written = await handle.write(expected, 0, expected.length, null);
|
|
29
29
|
|
|
30
|
-
assert(expected.length
|
|
30
|
+
assert.strictEqual(expected.length, written.bytesWritten);
|
|
31
31
|
|
|
32
32
|
await handle.close();
|
|
33
33
|
|
|
@@ -43,13 +43,13 @@ suite('writeSync', () => {
|
|
|
43
43
|
const fd = fs.openSync(fn, 'w');
|
|
44
44
|
|
|
45
45
|
let written = fs.writeSync(fd, '');
|
|
46
|
-
assert(written
|
|
46
|
+
assert.strictEqual(written, 0);
|
|
47
47
|
|
|
48
48
|
fs.writeSync(fd, 'foo');
|
|
49
49
|
|
|
50
50
|
const data = Buffer.from('bár');
|
|
51
51
|
written = fs.writeSync(fd, data, 0, data.length);
|
|
52
|
-
assert(written
|
|
52
|
+
assert.strictEqual(written, 4);
|
|
53
53
|
|
|
54
54
|
fs.closeSync(fd);
|
|
55
55
|
|