From aafb1eea52b1aec349a15ba2d0bca4ff61073dbf Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 17 May 2024 15:18:53 +0200 Subject: [PATCH] Try to start typechecking tests --- lib/index.js | 4 ++-- package.json | 3 ++- test/account-add.test.js | 1 - test/util.js | 23 +++++++++++++++++++++++ tsconfig.json | 6 +++--- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/index.js b/lib/index.js index 219e7d4..bd9e885 100644 --- a/lib/index.js +++ b/lib/index.js @@ -483,10 +483,10 @@ function initDB(peer, config) { } /** - * @param {CB} cb + * @param {CB | void} cb */ function loaded(cb) { - if (cb === void 0) return promisify(loaded)() + if (!cb) return promisify(loaded)() return scannedLog.onDone(() => { ghosts.onReady(cb) }) diff --git a/package.json b/package.json index 7d3f978..d286870 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ ], "types": "types/index.d.ts", "engines": { - "node": ">=16" + "node": ">=18" }, "exports": { ".": { @@ -49,6 +49,7 @@ }, "devDependencies": { "@types/b4a": "^1.6.0", + "@types/node": "^20.0.0", "@types/pull-stream": "^3.6.7", "c8": "^7.11.0", "flumecodec": "~0.0.1", diff --git a/test/account-add.test.js b/test/account-add.test.js index 3b295a8..38a6b86 100644 --- a/test/account-add.test.js +++ b/test/account-add.test.js @@ -6,7 +6,6 @@ const os = require('node:os') const rimraf = require('rimraf') const Keypair = require('pzp-keypair') const { createPeer } = require('./util') -const MsgV4 = require('../lib/msg-v4') const DIR = path.join(os.tmpdir(), 'pzp-db-account-add') rimraf.sync(DIR) diff --git a/test/util.js b/test/util.js index 65cadd7..2088b12 100644 --- a/test/util.js +++ b/test/util.js @@ -1,9 +1,32 @@ +/** + * @typedef {ReturnType} PZPDB + * @typedef {import('node:events').EventEmitter} Emitter + * @typedef {{ pubkey: string }} SHSE + */ + + +/** + * @typedef {Emitter & { + * db: PZPDB, + * shse: SHSE + * close(cb: () => void): void + * }} Peer + */ + +/** + * @param {unknown} globalConfig + * @returns {Peer} + */ function createPeer(globalConfig) { + // @ts-ignore return require('secret-stack/bare')() + // @ts-ignore .use(require('secret-stack/plugins/net')) .use(require('secret-handshake-ext/secret-stack')) .use(require('../lib')) + // @ts-ignore .use(require('ssb-box')) + // @ts-ignore .call(null, { shse: { caps: require('pzp-caps') }, global: globalConfig }) } diff --git a/tsconfig.json b/tsconfig.json index 55cd742..e2fc8c7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,12 @@ { "include": [ "declarations", - "lib/**/*.js" + "lib/**/*.js", + "test/" ], "exclude": [ "coverage/", - "node_modules/", - "test/" + "node_modules/" ], "compilerOptions": { "checkJs": true,