Skip to content

Commit

Permalink
Switch to strict assertion mode
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Jan 18, 2025
1 parent 3d68f9d commit 9a58b1a
Show file tree
Hide file tree
Showing 28 changed files with 109 additions and 109 deletions.
20 changes: 10 additions & 10 deletions tests/common/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { suite, test } from 'node:test';
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { bindContext } from '../../dist/context.js';
import * as fs from '../../dist/vfs/index.js';

Expand All @@ -15,8 +15,8 @@ suite('Context', () => {

test('linking', async () => {
await ctx.promises.symlink('/example.txt', '/link');
assert.strictEqual(await ctx.promises.readlink('link', 'utf8'), '/example.txt');
assert.strictEqual(await fs.promises.readlink('/ctx/link'), '/example.txt');
assert.equal(await ctx.promises.readlink('link', 'utf8'), '/example.txt');
assert.equal(await fs.promises.readlink('/ctx/link'), '/example.txt');
assert.deepEqual(await ctx.promises.readFile('/link', 'utf-8'), await fs.promises.readFile('/ctx/example.txt', 'utf-8'));

// The symlink should only work inside the chroot /ctx
Expand All @@ -25,12 +25,12 @@ suite('Context', () => {

test('path resolution', async () => {
// Correct/normal
assert.strictEqual(ctx.realpathSync('/'), '/');
assert.strictEqual(ctx.realpathSync('example.txt'), '/example.txt');
assert.strictEqual(ctx.realpathSync('../link'), '/example.txt');
assert.strictEqual(await ctx.promises.realpath('/../link'), '/example.txt');
assert.equal(ctx.realpathSync('/'), '/');
assert.equal(ctx.realpathSync('example.txt'), '/example.txt');
assert.equal(ctx.realpathSync('../link'), '/example.txt');
assert.equal(await ctx.promises.realpath('/../link'), '/example.txt');

assert.strictEqual(fs.realpathSync('/ctx/link'), '/example.txt');
assert.equal(fs.realpathSync('/ctx/link'), '/example.txt');
});

test('break-out fails', () => {
Expand All @@ -49,8 +49,8 @@ suite('Context', () => {
}
})();
await ctx.promises.writeFile('/xpto.txt', 'in real root');
assert.strictEqual(lastFile!, 'xpto.txt');
assert.equal(lastFile!, 'xpto.txt');
await ctx.promises.unlink('/xpto.txt');
assert.strictEqual(lastFile, 'xpto.txt');
assert.equal(lastFile, 'xpto.txt');
});
});
2 changes: 1 addition & 1 deletion tests/common/devices.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { suite, test } from 'node:test';
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { configure } from '../../dist/config.js';
import * as fs from '../../dist/vfs/index.js';
import { S_IFCHR, S_IFMT } from '../../dist/vfs/constants.js';
Expand Down
2 changes: 1 addition & 1 deletion tests/common/handle.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { constants, type FileHandle, open } from '../../dist/vfs/promises.js';

Expand Down
6 changes: 3 additions & 3 deletions tests/common/mounts.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { configure } from '../../dist/config.js';
import * as fs from '../../dist/vfs/index.js';
Expand All @@ -12,8 +12,8 @@ suite('Mounts', () => {
},
});

assert.deepStrictEqual(fs.readdirSync('/'), ['nested']);
assert.deepStrictEqual(fs.readdirSync('/nested'), ['dir']);
assert.deepEqual(fs.readdirSync('/'), ['nested']);
assert.deepEqual(fs.readdirSync('/nested'), ['dir']);

// cleanup
fs.umount('/nested/dir');
Expand Down
4 changes: 2 additions & 2 deletions tests/common/mutex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Mutexed } from '../../dist/mixins/mutexed.js';
import { StoreFS } from '../../dist/backends/store/fs.js';
import { InMemoryStore } from '../../dist/backends/memory.js';
import { suite, test } from 'node:test';
import assert from 'node:assert';
import assert from 'node:assert/strict';

suite('LockFS mutex', () => {
const fs = new (Mutexed(StoreFS))(new InMemoryStore('test'));
Expand Down Expand Up @@ -57,6 +57,6 @@ suite('LockFS mutex', () => {
}

await Promise.all([foo(), foo(), foo()]);
assert.strictEqual(x, 4);
assert.equal(x, 4);
});
});
2 changes: 1 addition & 1 deletion tests/common/path.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { basename, dirname, extname, join, normalize, resolve } from '../../dist/vfs/path.js';

Expand Down
2 changes: 1 addition & 1 deletion tests/fs/append.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { fs } from '../common.js';

Expand Down
8 changes: 4 additions & 4 deletions tests/fs/dir.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert, { rejects } from 'node:assert';
import assert, { rejects } from 'node:assert/strict';
import { suite, test } from 'node:test';
import { fs, type Dirent } from '../common.js';

Expand Down Expand Up @@ -68,7 +68,7 @@ suite('Dir', () => {
assert(testFiles.includes(dirent2?.name));

const dirent3 = await dir.read();
assert.strictEqual(dirent3, null);
assert.equal(dirent3, null);

await dir.close();
});
Expand All @@ -85,7 +85,7 @@ suite('Dir', () => {
assert(testFiles.includes(dirent2?.name));

const dirent3 = dir.readSync();
assert.strictEqual(dirent3, null);
assert.equal(dirent3, null);

dir.closeSync();
});
Expand All @@ -110,7 +110,7 @@ suite('Dir', () => {
dirents.push(dirent);
}

assert.strictEqual(dirents.length, 2);
assert.equal(dirents.length, 2);
assert(dirents[0] instanceof fs.Dirent);
assert(testFiles.includes(dirents[0].name));
assert(testFiles.includes(dirents[1].name));
Expand Down
16 changes: 8 additions & 8 deletions tests/fs/directory.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { ErrnoError } from '../../dist/error.js';
import { fs } from '../common.js';
Expand Down Expand Up @@ -32,7 +32,7 @@ suite('Directories', () => {
await fs.promises.mkdir('/nested/dir');
} catch (error: any) {
assert(error instanceof ErrnoError);
assert.strictEqual(error.code, 'ENOENT');
assert.equal(error.code, 'ENOENT');
}
assert(!(await fs.promises.exists('/nested/dir')));
});
Expand Down Expand Up @@ -66,7 +66,7 @@ suite('Directories', () => {
fs.readdirSync('/two');
} catch (error: any) {
assert(error instanceof ErrnoError);
assert.strictEqual(error.code, 'EACCES');
assert.equal(error.code, 'EACCES');
}
});

Expand All @@ -78,7 +78,7 @@ suite('Directories', () => {
await fs.promises.rmdir('/rmdirTest');
} catch (error: any) {
assert(error instanceof ErrnoError);
assert.strictEqual(error.code, 'ENOTEMPTY');
assert.equal(error.code, 'ENOTEMPTY');
}
});

Expand All @@ -90,7 +90,7 @@ suite('Directories', () => {
} catch (error: any) {
assert(error instanceof ErrnoError);
wasThrown = true;
assert.strictEqual(error.code, 'ENOTDIR');
assert.equal(error.code, 'ENOTDIR');
}
assert(wasThrown);
});
Expand All @@ -100,7 +100,7 @@ suite('Directories', () => {
await fs.promises.readdir('a.js');
} catch (error: any) {
assert(error instanceof ErrnoError);
assert.strictEqual(error.code, 'ENOTDIR');
assert.equal(error.code, 'ENOTDIR');
}
});

Expand All @@ -112,7 +112,7 @@ suite('Directories', () => {
} catch (error: any) {
assert(error instanceof ErrnoError);
wasThrown = true;
assert.strictEqual(error.code, 'ENOENT');
assert.equal(error.code, 'ENOENT');
}
assert(wasThrown);
});
Expand All @@ -122,7 +122,7 @@ suite('Directories', () => {
await fs.promises.readdir('/does/not/exist');
} catch (error: any) {
assert(error instanceof ErrnoError);
assert.strictEqual(error.code, 'ENOENT');
assert.equal(error.code, 'ENOENT');
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/fs/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import test, { suite } from 'node:test';
import type { ErrnoError } from '../../dist/error.js';
import { fs } from '../common.js';
Expand Down
2 changes: 1 addition & 1 deletion tests/fs/exists.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { fs } from '../common.js';

Expand Down
8 changes: 4 additions & 4 deletions tests/fs/links.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { join } from '../../dist/vfs/path.js';
import { fs } from '../common.js';
Expand All @@ -20,7 +20,7 @@ suite('Links', () => {

test('readlink', async () => {
const destination = await fs.promises.readlink(symlink);
assert.strictEqual(destination, target);
assert.equal(destination, target);
});

test('read target contents', async () => {
Expand All @@ -43,7 +43,7 @@ suite('Links', () => {
}
const targetContent = await fs.promises.readFile(target, 'utf8');
const linkContent = await fs.promises.readFile(hardlink, 'utf8');
assert.strictEqual(targetContent, linkContent);
assert.equal(targetContent, linkContent);
});

test('file inside symlinked directory', async () => {
Expand All @@ -52,6 +52,6 @@ suite('Links', () => {
const link = join('link', target);
assert((await fs.promises.realpath(link)) === target);
const linkContent = await fs.promises.readFile(link, 'utf8');
assert.strictEqual(targetContent, linkContent);
assert.equal(targetContent, linkContent);
});
});
6 changes: 3 additions & 3 deletions tests/fs/open.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { ErrnoError } from '../../dist/error.js';
import { fs } from '../common.js';
Expand All @@ -12,7 +12,7 @@ suite('fs file opening', () => {
fs.openSync('/path/to/file/that/does/not/exist', 'r');
} catch (error: any) {
assert(error instanceof ErrnoError);
assert.strictEqual(error?.code, 'ENOENT');
assert.equal(error?.code, 'ENOENT');
caughtException = true;
}
assert(caughtException);
Expand All @@ -23,7 +23,7 @@ suite('fs file opening', () => {
await fs.promises.open('/path/to/file/that/does/not/exist', 'r');
} catch (error: any) {
assert(error instanceof ErrnoError);
assert.strictEqual(error?.code, 'ENOENT');
assert.equal(error?.code, 'ENOENT');
}
});

Expand Down
4 changes: 2 additions & 2 deletions tests/fs/permissions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { credentials } from '../../dist/credentials.js';
import { R_OK, W_OK, X_OK } from '../../dist/vfs/constants.js';
Expand Down Expand Up @@ -50,7 +50,7 @@ suite('Permissions', () => {
async function test_item(path: string): Promise<void> {
const stats = await fs.promises.stat(path).catch((error: ErrnoError) => {
assert(error instanceof ErrnoError);
assert.strictEqual(error.code, 'EACCES');
assert.equal(error.code, 'EACCES');
});
if (!stats) {
return;
Expand Down
18 changes: 9 additions & 9 deletions tests/fs/read.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { fs } from '../common.js';
import { Buffer } from 'buffer';
Expand Down Expand Up @@ -27,12 +27,12 @@ suite('read', () => {
suite('read binary', () => {
test('Read a file and check its binary bytes (asynchronous)', async () => {
const buff = await fs.promises.readFile('elipses.txt');
assert.strictEqual((buff[1] << 8) | buff[0], 32994);
assert.equal((buff[1] << 8) | buff[0], 32994);
});

test('Read a file and check its binary bytes (synchronous)', () => {
const buff = fs.readFileSync('elipses.txt');
assert.strictEqual((buff[1] << 8) | buff[0], 32994);
assert.equal((buff[1] << 8) | buff[0], 32994);
});
});

Expand All @@ -44,24 +44,24 @@ suite('read buffer', () => {
const handle = await fs.promises.open(filepath, 'r');
const { bytesRead } = await handle.read(bufferAsync, 0, expected.length, 0);

assert.strictEqual(bytesRead, expected.length);
assert.strictEqual(bufferAsync.toString(), expected);
assert.equal(bytesRead, expected.length);
assert.equal(bufferAsync.toString(), expected);
});

test('read file synchronously', () => {
const fd = fs.openSync(filepath, 'r');
const bytesRead = fs.readSync(fd, bufferSync, 0, expected.length, 0);

assert.strictEqual(bufferSync.toString(), expected);
assert.strictEqual(bytesRead, expected.length);
assert.equal(bufferSync.toString(), expected);
assert.equal(bytesRead, expected.length);
});

test('read file synchronously to non-zero offset', () => {
const fd = fs.openSync(filepath, 'r');
const buffer = Buffer.alloc(expected.length + 10);
const bytesRead = fs.readSync(fd, buffer, 10, expected.length, 0);

assert.strictEqual(buffer.subarray(10, buffer.length).toString(), expected);
assert.strictEqual(bytesRead, expected.length);
assert.equal(buffer.subarray(10, buffer.length).toString(), expected);
assert.equal(bytesRead, expected.length);
});
});
12 changes: 6 additions & 6 deletions tests/fs/readFile.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import assert from 'node:assert/strict';
import { suite, test } from 'node:test';
import { fs } from '../common.js';

Expand All @@ -10,7 +10,7 @@ suite('Reading', () => {
test('Reading past the end of a file should not be an error', async () => {
const handle = await fs.promises.open('a.js', 'r');
const { bytesRead } = await handle.read(new Uint8Array(10), 0, 10, 10000);
assert.strictEqual(bytesRead, 0);
assert.equal(bytesRead, 0);
});
});

Expand Down Expand Up @@ -46,7 +46,7 @@ suite('Read File Test', () => {

test('read file with utf-8 encoding asynchronously', async () => {
const data: string = await fs.promises.readFile(fn, 'utf8');
assert.strictEqual(data, '');
assert.equal(data, '');
});

test('read file synchronously', () => {
Expand All @@ -56,7 +56,7 @@ suite('Read File Test', () => {

test('read file with utf-8 encoding synchronously', () => {
const data: string = fs.readFileSync(fn, 'utf8');
assert.strictEqual(data, '');
assert.equal(data, '');
});
});

Expand All @@ -65,9 +65,9 @@ suite('fs file reading', () => {
const content = fs.readFileSync('elipses.txt', 'utf8');

for (let i = 0; i < content.length; i++) {
assert.strictEqual(content[i], '…');
assert.equal(content[i], '…');
}

assert.strictEqual(content.length, 10000);
assert.equal(content.length, 10000);
});
});
Loading

0 comments on commit 9a58b1a

Please sign in to comment.