@zenfs/core 1.8.6 → 1.8.8

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.
@@ -66,21 +66,21 @@ import { join } from '../vfs/path.js';
66
66
  */
67
67
  export function Async(FS) {
68
68
  class AsyncFS extends FS {
69
- get _queueRunning() {
70
- return !!this._queue.length;
69
+ async done() {
70
+ await this._promise;
71
71
  }
72
72
  queueDone() {
73
- return new Promise(resolve => {
74
- const check = () => (this._queueRunning ? setTimeout(check) : resolve());
75
- check();
76
- });
73
+ return this.done();
74
+ }
75
+ _async(promise) {
76
+ if (!this._promise) {
77
+ this._promise = promise;
78
+ return;
79
+ }
80
+ this._promise = this._promise.then(() => promise);
77
81
  }
78
82
  constructor(...args) {
79
83
  super(...args);
80
- /**
81
- * Queue of pending asynchronous operations.
82
- */
83
- this._queue = [];
84
84
  this._isInitialized = false;
85
85
  this._patchAsync();
86
86
  }
@@ -124,7 +124,7 @@ export function Async(FS) {
124
124
  renameSync(oldPath, newPath) {
125
125
  this.checkSync(oldPath, 'rename');
126
126
  this._sync.renameSync(oldPath, newPath);
127
- this.queue('rename', oldPath, newPath);
127
+ this._async(this.rename(oldPath, newPath));
128
128
  }
129
129
  statSync(path) {
130
130
  this.checkSync(path, 'stat');
@@ -133,7 +133,7 @@ export function Async(FS) {
133
133
  createFileSync(path, flag, mode, options) {
134
134
  this.checkSync(path, 'createFile');
135
135
  this._sync.createFileSync(path, flag, mode, options);
136
- this.queue('createFile', path, flag, mode, options);
136
+ this._async(this.createFile(path, flag, mode, options));
137
137
  return this.openFileSync(path, flag);
138
138
  }
139
139
  openFileSync(path, flag) {
@@ -144,17 +144,17 @@ export function Async(FS) {
144
144
  unlinkSync(path) {
145
145
  this.checkSync(path, 'unlinkSync');
146
146
  this._sync.unlinkSync(path);
147
- this.queue('unlink', path);
147
+ this._async(this.unlink(path));
148
148
  }
149
149
  rmdirSync(path) {
150
150
  this.checkSync(path, 'rmdir');
151
151
  this._sync.rmdirSync(path);
152
- this.queue('rmdir', path);
152
+ this._async(this.rmdir(path));
153
153
  }
154
154
  mkdirSync(path, mode, options) {
155
155
  this.checkSync(path, 'mkdir');
156
156
  this._sync.mkdirSync(path, mode, options);
157
- this.queue('mkdir', path, mode, options);
157
+ this._async(this.mkdir(path, mode, options));
158
158
  }
159
159
  readdirSync(path) {
160
160
  this.checkSync(path, 'readdir');
@@ -163,12 +163,12 @@ export function Async(FS) {
163
163
  linkSync(srcpath, dstpath) {
164
164
  this.checkSync(srcpath, 'link');
165
165
  this._sync.linkSync(srcpath, dstpath);
166
- this.queue('link', srcpath, dstpath);
166
+ this._async(this.link(srcpath, dstpath));
167
167
  }
168
168
  syncSync(path, data, stats) {
169
169
  this.checkSync(path, 'sync');
170
170
  this._sync.syncSync(path, data, stats);
171
- this.queue('sync', path, data, stats);
171
+ this._async(this.sync(path, data, stats));
172
172
  }
173
173
  existsSync(path) {
174
174
  this.checkSync(path, 'exists');
@@ -181,7 +181,7 @@ export function Async(FS) {
181
181
  writeSync(path, buffer, offset) {
182
182
  this.checkSync(path, 'write');
183
183
  this._sync.writeSync(path, buffer, offset);
184
- this.queue('write', path, buffer, offset);
184
+ this._async(this.write(path, buffer, offset));
185
185
  }
186
186
  /**
187
187
  * @internal
@@ -219,25 +219,6 @@ export function Async(FS) {
219
219
  }
220
220
  await Promise.all(promises);
221
221
  }
222
- /**
223
- * @internal
224
- */
225
- async _next() {
226
- if (!this._queueRunning) {
227
- return;
228
- }
229
- const [method, ...args] = this._queue.shift();
230
- // @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)
231
- await this[method](...args);
232
- await this._next();
233
- }
234
- /**
235
- * @internal
236
- */
237
- queue(...op) {
238
- this._queue.push(op);
239
- void this._next();
240
- }
241
222
  /**
242
223
  * @internal
243
224
  * Patch all async methods to also call their synchronous counterparts unless called from the queue
@@ -263,7 +244,7 @@ export function Async(FS) {
263
244
  this[key] = async (...args) => {
264
245
  var _a, _b;
265
246
  const result = await originalMethod.apply(this, args);
266
- if (new Error().stack.includes(`at async ${this.constructor.name}._next`) || !this._isInitialized)
247
+ if (new Error().stack.includes(`at <computed> [as ${key}]`) || !this._isInitialized)
267
248
  return result;
268
249
  try {
269
250
  // @ts-expect-error 2556
@@ -37,6 +37,12 @@ export function Sync(FS) {
37
37
  async sync(path, data, stats) {
38
38
  return this.syncSync(path, data, stats);
39
39
  }
40
+ async read(path, buffer, offset, end) {
41
+ return this.readSync(path, buffer, offset, end);
42
+ }
43
+ async write(path, buffer, offset) {
44
+ return this.writeSync(path, buffer, offset);
45
+ }
40
46
  }
41
47
  return SyncFS;
42
48
  }
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "1.8.6",
3
+ "version": "1.8.8",
4
4
  "description": "A filesystem, anywhere",
5
5
  "funding": {
6
6
  "type": "individual",
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.strictEqual(await ctx.promises.readlink('link', 'utf8'), '/example.txt');
19
- assert.strictEqual(await fs.promises.readlink('/ctx/link'), '/example.txt');
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.strictEqual(ctx.realpathSync('/'), '/');
29
- assert.strictEqual(ctx.realpathSync('example.txt'), '/example.txt');
30
- assert.strictEqual(ctx.realpathSync('../link'), '/example.txt');
31
- assert.strictEqual(await ctx.promises.realpath('/../link'), '/example.txt');
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.strictEqual(fs.realpathSync('/ctx/link'), '/example.txt');
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.strictEqual(lastFile!, 'xpto.txt');
52
+ assert.equal(lastFile!, 'xpto.txt');
53
53
  await ctx.promises.unlink('/xpto.txt');
54
- assert.strictEqual(lastFile, 'xpto.txt');
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 { constants, type FileHandle, open } from '../../dist/vfs/promises.js';
4
4
 
@@ -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.deepStrictEqual(fs.readdirSync('/'), ['nested']);
16
- assert.deepStrictEqual(fs.readdirSync('/nested'), ['dir']);
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.strictEqual(x, 4);
60
+ assert.equal(x, 4);
61
61
  });
62
62
  });
@@ -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 { basename, dirname, extname, join, normalize, resolve } from '../../dist/vfs/path.js';
4
4
 
@@ -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
 
@@ -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.strictEqual(dirent3, null);
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.strictEqual(dirent3, null);
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.strictEqual(dirents.length, 2);
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.strictEqual(error.code, 'ENOENT');
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.strictEqual(error.code, 'EACCES');
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.strictEqual(error.code, 'ENOTEMPTY');
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.strictEqual(error.code, 'ENOTDIR');
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.strictEqual(error.code, 'ENOTDIR');
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.strictEqual(error.code, 'ENOENT');
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.strictEqual(error.code, 'ENOENT');
125
+ assert.equal(error.code, 'ENOENT');
126
126
  }
127
127
  });
128
128
 
@@ -1,4 +1,4 @@
1
- import assert from 'node:assert';
1
+ import assert from 'node:assert/strict';
2
2
  import test, { suite } from 'node:test';
3
3
  import type { ErrnoError } from '../../dist/error.js';
4
4
  import { fs } from '../common.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 { fs } from '../common.js';
4
4
 
@@ -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.strictEqual(destination, target);
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.strictEqual(targetContent, linkContent);
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.strictEqual(targetContent, linkContent);
55
+ assert.equal(targetContent, linkContent);
56
56
  });
57
57
  });
@@ -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.strictEqual(error?.code, 'ENOENT');
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.strictEqual(error?.code, 'ENOENT');
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.strictEqual(error.code, 'EACCES');
53
+ assert.equal(error.code, 'EACCES');
54
54
  });
55
55
  if (!stats) {
56
56
  return;
@@ -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.strictEqual((buff[1] << 8) | buff[0], 32994);
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.strictEqual((buff[1] << 8) | buff[0], 32994);
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.strictEqual(bytesRead, expected.length);
48
- assert.strictEqual(bufferAsync.toString(), expected);
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.strictEqual(bufferSync.toString(), expected);
56
- assert.strictEqual(bytesRead, expected.length);
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.strictEqual(buffer.subarray(10, buffer.length).toString(), expected);
65
- assert.strictEqual(bytesRead, expected.length);
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.strictEqual(bytesRead, 0);
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.strictEqual(data, '');
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.strictEqual(data, '');
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.strictEqual(content[i], '…');
68
+ assert.equal(content[i], '…');
69
69
  }
70
70
 
71
- assert.strictEqual(content.length, 10000);
71
+ assert.equal(content.length, 10000);
72
72
  });
73
73
  });
@@ -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.strictEqual(contents.length, 2);
24
+ assert.equal(contents.length, 2);
25
25
 
26
26
  const subContents = await fs.promises.readdir(dir + '/_rename_me');
27
- assert.strictEqual(subContents.length, 1);
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 = '/rename_filedir_test';
75
- const file = '/rename_filedir_test.txt';
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 === 'EISDIR' || error.code === 'EPERM');
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 = '/renamedir_1';
98
- const renDir2 = '/renamedir_1/lol';
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.strictEqual(error.code, 'EBUSY');
94
+ assert.equal(error.code, 'EBUSY');
105
95
  });
106
96
  });
107
97
  });
@@ -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 { Stats } from '../../dist/stats.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 { 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.strictEqual(readStream.bytesRead, undefined);
45
- assert.strictEqual(readStream.path, undefined);
46
- assert.strictEqual(readStream.pending, undefined);
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.strictEqual(readStream.bytesRead, 10);
54
- assert.strictEqual(readStream.path, testFilePath);
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.strictEqual(writeStream.bytesWritten, undefined);
106
- assert.strictEqual(writeStream.path, undefined);
107
- assert.strictEqual(writeStream.pending, undefined);
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.strictEqual(writeStream.bytesWritten, 20);
115
- assert.strictEqual(writeStream.path, testFilePathWrite);
114
+ assert.equal(writeStream.bytesWritten, 20);
115
+ assert.equal(writeStream.path, testFilePathWrite);
116
116
  assert(writeStream.pending);
117
117
  });
118
118
 
@@ -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.deepStrictEqual(unixTimestamps(await fs.promises.stat(path)), times);
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.strictEqual(error.code, 'ENOENT');
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.deepStrictEqual(unixTimestamps(await handle.stat()), times);
41
+ assert.deepEqual(unixTimestamps(await handle.stat()), times);
42
42
 
43
43
  fs.utimesSync(path, atime, mtime);
44
- assert.deepStrictEqual(unixTimestamps(fs.statSync(path)), times);
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.strictEqual(error.code, 'ENOENT');
50
+ assert.equal(error.code, 'ENOENT');
51
51
  }
52
52
 
53
53
  try {
@@ -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 type { FileHandle } from '../../dist/vfs/promises.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 { 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.strictEqual(eventType, 'change');
18
- assert.strictEqual(filename, 'test.txt');
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.strictEqual(eventType, 'rename');
28
- assert.strictEqual(filename, 'test.txt');
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.strictEqual(eventType, 'change');
67
- assert.strictEqual(filename, 'newFile.txt');
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.strictEqual(eventType, resolver.eventType);
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.strictEqual(eventType, 'rename');
106
- assert.strictEqual(filename, 'tempFile.txt');
105
+ assert.equal(eventType, 'rename');
106
+ assert.equal(filename, 'tempFile.txt');
107
107
  });
108
108
 
109
109
  await fs.promises.unlink(tempFile);
@@ -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.strictEqual(bytesWritten, Buffer.from(expected).length);
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.strictEqual(data, expected);
16
+ assert.equal(data, expected);
17
17
 
18
18
  await fs.promises.unlink(fn);
19
19
  });
@@ -25,11 +25,11 @@ suite('write', () => {
25
25
 
26
26
  const written = await handle.write(expected, 0, expected.length, null);
27
27
 
28
- assert.strictEqual(expected.length, written.bytesWritten);
28
+ assert.equal(expected.length, written.bytesWritten);
29
29
 
30
30
  await handle.close();
31
31
 
32
- assert((await fs.promises.readFile(fn)).equals(expected));
32
+ assert.deepEqual(await fs.promises.readFile(fn), expected);
33
33
 
34
34
  await fs.promises.unlink(fn);
35
35
  });
@@ -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.strictEqual(written, 0);
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.strictEqual(written, 4);
47
+ assert.equal(written, 4);
48
48
 
49
49
  fs.closeSync(fd);
50
50
 
51
- assert.strictEqual(fs.readFileSync(fn, 'utf8'), 'foobár');
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.strictEqual(data.length, Buffer.from(s).length);
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.strictEqual(actual.length, expected.length);
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.strictEqual(read, data);
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.strictEqual(content, '123');
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.strictEqual(content, 'abc');
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, attachFS } from '../../dist/backends/port/fs.js';
@@ -1,4 +1,4 @@
1
- import assert from 'node:assert';
1
+ import assert from 'node:assert/strict';
2
2
  import { dirname } from 'node:path';
3
3
  import { suite, test } from 'node:test';
4
4
  import { fileURLToPath } from 'node:url';
@@ -1,4 +1,4 @@
1
- import assert from 'node:assert';
1
+ import assert from 'node:assert/strict';
2
2
  import { dirname } from 'node:path';
3
3
  import { suite, test } from 'node:test';
4
4
  import { fileURLToPath } from 'node:url';
@@ -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.strictEqual(error.code, 'EIO');
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.strictEqual(error.code, 'EIO');
43
+ assert.equal(error.code, 'EIO');
44
44
  assert(error.message.includes('RPC Failed'));
45
45
  });
46
46
  });