Add simple test

This commit is contained in:
Jacob Karlsson 2024-05-17 18:41:17 +02:00
parent 0f77ff66d6
commit dd0f0d042f
5 changed files with 53 additions and 7 deletions

13
.woodpecker.yaml Normal file
View File

@ -0,0 +1,13 @@
matrix:
NODE_VERSION:
- 18
- 20
steps:
test:
when:
event: [push]
image: node:${NODE_VERSION}
commands:
- npm install
- npm test

View File

@ -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<Peer>}
*/
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,
}

View File

@ -12,7 +12,8 @@
"type": "commonjs",
"main": "lib/index.js",
"files": [
"lib/**/*"
"lib/**/*",
"declarations/**/*"
],
"exports": {
".": {

31
test/index.test.js Normal file
View File

@ -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))
})
})
})
})

View File

@ -1,12 +1,12 @@
{
"include": [
"declarations",
"lib/**/*.js"
"lib/**/*.js",
"test/"
],
"exclude": [
"coverage/",
"node_modules/",
"test/"
],
"compilerOptions": {
"checkJs": true,