diff --git a/.woodpecker.yaml b/.woodpecker.yaml new file mode 100644 index 0000000..d254f8d --- /dev/null +++ b/.woodpecker.yaml @@ -0,0 +1,13 @@ +matrix: + NODE_VERSION: + - 18 + - 20 + +steps: + test: + when: + event: [push] + image: node:${NODE_VERSION} + commands: + - npm install + - npm test \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index a8870ca..e1a6918 100644 --- a/lib/index.js +++ b/lib/index.js @@ -21,6 +21,7 @@ const Keypair = require('pzp-keypair') /** * @typedef {Emitter & { + * close(cb?: (err?: Error) => void): void, * db: PZPDB, * dict: PZPDict, * set: PZPSet, @@ -38,11 +39,11 @@ const Keypair = require('pzp-keypair') /** * - * @param {{ path: string }} opts + * @param {{ path?: string }=} opts * @returns {Promise} */ -async function createPeer({ path }) { - +async function createPeer(opts) { + let { path } = opts ?? {} if (!path) { if (process.env.PZP_DIR) { path = process.env.PZP_DIR @@ -101,6 +102,6 @@ async function createPeer({ path }) { return peer } -exports = { +module.exports = { createPeer, } diff --git a/package.json b/package.json index 9b931e7..7ef33f8 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "type": "commonjs", "main": "lib/index.js", "files": [ - "lib/**/*" + "lib/**/*", + "declarations/**/*" ], "exports": { ".": { diff --git a/test/index.test.js b/test/index.test.js new file mode 100644 index 0000000..732ee09 --- /dev/null +++ b/test/index.test.js @@ -0,0 +1,31 @@ +const { test } = require('node:test') +const assert = require('node:assert') +const p = require('node:util').promisify +const { createPeer } = require('../lib/') + +test('Basic createPeer', async (t) => { + const peer = await createPeer() + + // TODO: getting warning + //Warning: A resource generated asynchronous activity after the test ended. This activity created the error "Error: Cannot call values() before loading" which triggered an uncaughtException event, caught by the test runner. + await new Promise((res, rej) => { + peer.db.account.create({ + subdomain: 'account', + _nonce: 'bob', + }, (err, account) => { + assert(!err) + + peer.db.feed.publish({ + account, + domain: "post", + data: { + text: 'woo a post' + } + }, (err, rec) => { + assert(!err) + + peer.close(() => res(null)) + }) + }) + }) +}) \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 81044b4..16d5048 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,12 @@ { "include": [ "declarations", - "lib/**/*.js" + "lib/**/*.js", + "test/" ], "exclude": [ "coverage/", "node_modules/", - "test/" ], "compilerOptions": { "checkJs": true,