diff --git a/packages/benchmarks/src/utils/run-node.ts b/packages/benchmarks/src/utils/run-node.ts index a5028da6..9d647583 100644 --- a/packages/benchmarks/src/utils/run-node.ts +++ b/packages/benchmarks/src/utils/run-node.ts @@ -70,6 +70,8 @@ export default async (path: string, options: { persistent?: boolean } = {}): Pro setTimeout(() => { forceQuit().finally(() => { promise.reject(new Error('process did not exit cleanly')) + }).catch(() => { + promise.reject(new Error('process did not exit cleanly')) }) }, 3000) diff --git a/packages/daemon/src/modules/filesystem/utils.ts b/packages/daemon/src/modules/filesystem/utils.ts index 203a7590..6752418a 100644 --- a/packages/daemon/src/modules/filesystem/utils.ts +++ b/packages/daemon/src/modules/filesystem/utils.ts @@ -1,3 +1,4 @@ +import assert from 'assert/strict' import Path from 'path' import { CID } from 'multiformats/cid' import { DATA_KEY, EncodedEntry, type Entry } from './interface.js' @@ -9,7 +10,11 @@ export const encodeEntry = (entry: Entry): NonNullable => { } // Parse will strip foreign keys... - return EncodedEntry.parse(ee)! + const stripped = EncodedEntry.parse(ee) + + assert(stripped != null) + + return stripped } export const decodeEntry = (entry: NonNullable): Entry => ({ diff --git a/packages/daemon/src/modules/revisions/utils.ts b/packages/daemon/src/modules/revisions/utils.ts index 2b9fff3d..be478a00 100644 --- a/packages/daemon/src/modules/revisions/utils.ts +++ b/packages/daemon/src/modules/revisions/utils.ts @@ -1,3 +1,4 @@ +import assert from 'assert/strict' import Path from 'path' import { CID } from 'multiformats/cid' import { fromString as uint8arrayFromString } from 'uint8arrays/from-string' @@ -11,7 +12,11 @@ export const encodeEntry = (entry: Entry): NonNullable => { } // Parse will strip foreign keys... - return EncodedEntry.parse(ee)! + const stripped = EncodedEntry.parse(ee) + + assert(stripped != null) + + return stripped } export const decodeEntry = (entry: NonNullable): Entry => ({ diff --git a/packages/daemon/src/modules/scheduler/utils.ts b/packages/daemon/src/modules/scheduler/utils.ts index e0f50739..339b3c00 100644 --- a/packages/daemon/src/modules/scheduler/utils.ts +++ b/packages/daemon/src/modules/scheduler/utils.ts @@ -1,8 +1,13 @@ +import assert from 'assert/strict' import { type Entry, EncodedEntry } from './interface.js' export const encodeEntry = (entry: Entry): NonNullable => { // Parse will strip foreign keys... - return EncodedEntry.parse(entry)! + const stripped = EncodedEntry.parse(entry) + + assert(stripped != null) + + return stripped } export const decodeEntry = (encodedEntry: NonNullable): Entry => ({ diff --git a/packages/daemon/test/modules/groups.spec.ts b/packages/daemon/test/modules/groups.spec.ts index 365f3817..be5c11a9 100644 --- a/packages/daemon/test/modules/groups.spec.ts +++ b/packages/daemon/test/modules/groups.spec.ts @@ -34,7 +34,7 @@ describe('groups', () => { const { components } = await create() const group = await createGroup(components, 'test') - assert(group) + assert(group != null) await components.stop() }) @@ -225,7 +225,7 @@ describe('groups', () => { const database = components[0].components.groups.get(group) - assert(database) + assert(database != null) assert.equal(database.manifest.name, name) client.stop() diff --git a/packages/e2e-tests/test/connectivity.spec.ts b/packages/e2e-tests/test/connectivity.spec.ts index 617a7fa0..70be3ad1 100644 --- a/packages/e2e-tests/test/connectivity.spec.ts +++ b/packages/e2e-tests/test/connectivity.spec.ts @@ -21,7 +21,7 @@ describe('connectivity', () => { const data: string[] = await runClient(nodes[0], 'addresses') const tcp = data.find(d => d.startsWith('/ip4/127.0.0.1/tcp')) - assert(tcp) + assert(tcp != null) }) it('displays no connections on startup', async () => { @@ -34,7 +34,7 @@ describe('connectivity', () => { const peerAData: string[] = await runClient(nodes[0], 'addresses') const tcp = peerAData.find(d => d.startsWith('/ip4/127.0.0.1/tcp')) - assert(tcp) + assert(tcp != null) const peerBData = await runClient(nodes[1], 'connect', tcp) diff --git a/packages/e2e-tests/test/group.spec.ts b/packages/e2e-tests/test/group.spec.ts index e7c90337..e6bd7c97 100644 --- a/packages/e2e-tests/test/group.spec.ts +++ b/packages/e2e-tests/test/group.spec.ts @@ -47,7 +47,7 @@ describe('group', () => { const peerAData: string[] = await runClient(nodes[0], 'addresses') const tcp = peerAData.find(d => d.startsWith('/ip4/127.0.0.1/tcp')) - assert(tcp) + assert(tcp != null) const peerBData = await runClient(nodes[1], 'connect', tcp) diff --git a/packages/e2e-tests/test/revisions.spec.ts b/packages/e2e-tests/test/revisions.spec.ts index 220c7b87..018b7224 100644 --- a/packages/e2e-tests/test/revisions.spec.ts +++ b/packages/e2e-tests/test/revisions.spec.ts @@ -20,7 +20,7 @@ describe('revisions', () => { const response = await runClient(node, 'import', group, dataFile.path, virtualDir) - assert(response.success) + assert(response.success === true) }) after(async () => { @@ -30,7 +30,7 @@ describe('revisions', () => { it('has 1 revision after importing a file', async () => { const response = await runClient(node, 'revisions', group, virtualDir) - assert(response) + assert(response != null) assert(Array.isArray(response)) assert.equal(response.length, 1) assert.equal(response[0].sequence, 0) @@ -39,13 +39,13 @@ describe('revisions', () => { it("has 0 revisions after overwrite with strategy 'none'", async () => { const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'none') - assert(add.success) + assert(add.success === true) const response = await runClient(node, 'revisions', group, virtualDir) await new Promise(resolve => setTimeout(resolve, 3000)) - assert(response) + assert(response != null) assert(Array.isArray(response)) assert.equal(response.length, 0) // assert.equal(response[0].sequence, 1) @@ -54,11 +54,11 @@ describe('revisions', () => { it("has 1 revisions after overwrite with strategy 'log'", async () => { const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'log') - assert(add.success) + assert(add.success === true) const response = await runClient(node, 'revisions', group, virtualDir) - assert(response) + assert(response != null) assert(Array.isArray(response)) assert.equal(response.length, 1) assert.equal(response[0].sequence, 2) @@ -67,11 +67,11 @@ describe('revisions', () => { it("has 2 revisions after overwrite with strategy 'all'", async () => { const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'all') - assert(add.success) + assert(add.success === true) const response = await runClient(node, 'revisions', group, virtualDir) - assert(response) + assert(response != null) assert(Array.isArray(response)) assert.equal(response.length, 2) assert.equal(response[0].sequence, 2) @@ -81,11 +81,11 @@ describe('revisions', () => { it("reduces to 1 revision after overwrite with strategy 'log'", async () => { const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'log') - assert(add.success) + assert(add.success === true) const response = await runClient(node, 'revisions', group, virtualDir) - assert(response) + assert(response != null) assert(Array.isArray(response)) assert.equal(response.length, 1) assert.equal(response[0].sequence, 2) @@ -94,11 +94,11 @@ describe('revisions', () => { it("reduces to 0 revisions after overwrite with strategy 'none'", async () => { const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'none') - assert(add.success) + assert(add.success === true) const response = await runClient(node, 'revisions', group, virtualDir) - assert(response) + assert(response != null) assert(Array.isArray(response)) assert.equal(response.length, 0) }) diff --git a/packages/e2e-tests/test/synchronization.spec.ts b/packages/e2e-tests/test/synchronization.spec.ts index fccbb592..f37cff5e 100644 --- a/packages/e2e-tests/test/synchronization.spec.ts +++ b/packages/e2e-tests/test/synchronization.spec.ts @@ -19,12 +19,12 @@ describe('synchronization', () => { group = (await runClient(nodes[0], 'create-group', 'test')).group - assert(tcp) + assert(tcp != null) for (let i = 1; i < nodes.length; i++) { const response = await runClient(nodes[i], 'connect', tcp) - assert(response.success) + assert(response.success === true) } }) @@ -43,23 +43,23 @@ describe('synchronization', () => { virtualPath ) - assert(addRes.success) + assert(addRes.success === true) const joinRes = await runClient(nodes[1], 'join-group', group) - assert(joinRes.success) + assert(joinRes.success === true) // Ensure it syncs... const sync = await runClient(nodes[1], 'sync') - assert(sync.success) + assert(sync.success === true) const listRes = await runClient(nodes[1], 'list') - assert(listRes) + assert(listRes != null) assert.equal(typeof listRes, 'object') - assert(listRes.items) - assert(listRes.total) + assert(listRes.items != null) + assert(listRes.total != null) assert(Array.isArray(listRes.items)) assert.equal(listRes.items.length, 1) assert.equal(listRes.items[0].cid, addRes.imports[0].cid) @@ -78,25 +78,25 @@ describe('synchronization', () => { virtualPath ) - assert(addRes.success) + assert(addRes.success === true) // Ensure it syncs... const sync = await runClient(nodes[1], 'sync') - assert(sync.success) + assert(sync.success === true) const listRes = await runClient(nodes[1], 'list') - assert(listRes) + assert(listRes != null) assert.equal(typeof listRes, 'object') - assert(listRes.items) - assert(listRes.total) + assert(listRes.items != null) + assert(listRes.total != null) assert(Array.isArray(listRes.items)) assert.equal(listRes.items.length, 2) const item = listRes.items.find((i: { cid: string }) => i.cid === addRes.imports[0].cid) - assert(item) + assert(item != null) assert.equal(item.group, group) assert.equal(item.path, virtualPath) }) diff --git a/packages/e2e-tests/test/utils/run-node.ts b/packages/e2e-tests/test/utils/run-node.ts index d96469e1..0ed1141b 100644 --- a/packages/e2e-tests/test/utils/run-node.ts +++ b/packages/e2e-tests/test/utils/run-node.ts @@ -68,6 +68,8 @@ export default async (name: string): Promise<{ start(): Promise, stop(): P setTimeout(() => { forceQuit().finally(() => { promise.reject(new Error('process did not exit cleanly')) + }).catch(() => { + promise.reject(new Error('process did not exit cleanly')) }) }, 3000) diff --git a/packages/helia-pin-manager/test/pin-manager.spec.ts b/packages/helia-pin-manager/test/pin-manager.spec.ts index 5dd6cbf0..a5d212b7 100644 --- a/packages/helia-pin-manager/test/pin-manager.spec.ts +++ b/packages/helia-pin-manager/test/pin-manager.spec.ts @@ -99,7 +99,7 @@ describe('pin manager', () => { it('constructs', () => { const pinManager = new PinManager(components) - assert(pinManager) + assert(pinManager != null) }) it('all returns all the pins', async () => { @@ -108,7 +108,7 @@ describe('pin manager', () => { const pins = await pm.all() for (const pin of pins) { - assert(data.pins.find(p => p.cid.equals(pin.cid))) + assert(data.pins.find(p => p.cid.equals(pin.cid)) != null) } }) @@ -189,7 +189,7 @@ describe('pin manager', () => { const raw = await pinsDatastore.get(new Key(root.toString())) const data = cborg.decode(raw) - assert(data) + assert(data != null) }) it('adds all the items in the dag as blocks', async () => { @@ -202,7 +202,7 @@ describe('pin manager', () => { assert.equal(pairs.length, Object.values(dag).length) for (const { key } of pairs) { - assert(dag.find(b => b.equals(CID.parse(key.baseNamespace())))) + assert(dag.find(b => b.equals(CID.parse(key.baseNamespace()))) != null) } }) @@ -244,7 +244,7 @@ describe('pin manager', () => { const raw = await pinsDatastore.get(new Key(root.toString())) const data = cborg.decode(raw) - assert(data) + assert(data != null) assert.equal(data.status, 'DOWNLOADING') }) @@ -269,7 +269,7 @@ describe('pin manager', () => { const pin = await pinsDatastore.get(new Key(root.toString())) assert.equal(downloads.length, 0) - assert(pin) + assert(pin != null) }) it('emits pins:adding event', async () => { diff --git a/packages/key-manager/test/key-manager.spec.ts b/packages/key-manager/test/key-manager.spec.ts index f8133fbd..7e510669 100644 --- a/packages/key-manager/test/key-manager.spec.ts +++ b/packages/key-manager/test/key-manager.spec.ts @@ -42,7 +42,10 @@ describe('key manager', () => { const peerId = await d.keyManager.getPeerId() const key = d.keyData.key.deriveHardened(0) - assert.deepEqual(new Uint8Array(key.privateKey as Buffer), (peerId.privateKey as Uint8Array).slice(4)) + assert(key.privateKey != null) + assert(peerId.privateKey != null) + + assert.deepEqual(new Uint8Array(key.privateKey), (peerId.privateKey).slice(4)) })) }) diff --git a/packages/key-manager/test/utils.spec.ts b/packages/key-manager/test/utils.spec.ts index 44388512..c73b9073 100644 --- a/packages/key-manager/test/utils.spec.ts +++ b/packages/key-manager/test/utils.spec.ts @@ -35,7 +35,7 @@ describe('nameToPath', () => { while (paths.length > 0) { const item = paths.pop() - assert(item) + assert(item != null) assert(!paths.includes(item)) } }) @@ -51,7 +51,7 @@ describe('nameToPath', () => { const nums = path.slice(2).split('/').map(s => Number.parseInt(s)) for (const num of nums) { - assert(num) + assert(num != null) assert(!Number.isNaN(num)) assert(num > 0) } @@ -82,7 +82,7 @@ describe('nameToPath', () => { describe('decodeKey', () => { it('decodes valid keys', () => { for (const { key } of data) { - assert(decodeKey(key)) + assert(decodeKey(key) != null) } }) }) @@ -126,7 +126,7 @@ describe('parseKeyData', () => { await Promise.all(data.map(async ({ key, psk }) => { const keyData = parseKeyData({ key, psk }) - assert(keyData) + assert(keyData != null) assert.deepEqual(keyData.key, decodeKey(key)) assert.deepEqual(keyData.psk, uint8ArrayFromString(psk)) })) diff --git a/packages/manual-block-broker/src/index.ts b/packages/manual-block-broker/src/index.ts index 263bd71e..047804f5 100644 --- a/packages/manual-block-broker/src/index.ts +++ b/packages/manual-block-broker/src/index.ts @@ -17,7 +17,7 @@ export class ManualBlockBroker implements BlockBroker { signal?.addEventListener('abort', () => { this.promises.delete(cid.toString()) - promise.reject('operation aborted') + promise.reject(new Error('operation aborted')) }) this.promises.set(cid.toString(), promise) diff --git a/packages/utils/test/walk.spec.ts b/packages/utils/test/walk.spec.ts index d4cc931d..c8c00a25 100644 --- a/packages/utils/test/walk.spec.ts +++ b/packages/utils/test/walk.spec.ts @@ -23,7 +23,7 @@ describe('walkDag', () => { for await (const getData of walk(blockstore, dag[0])) { const data = await getData() - assert(dag.find(cid => cid.equals(data.cid))) + assert(dag.find(cid => cid.equals(data.cid)) != null) count++ }