Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict'
const tape = require('tape')
const _test = require('tape-promise').default // <---- notice 'default'
const test = _test(tape) // decorate tape
const Gun = require('gun');
const GunThen = require('gun/lib/then.js')
const GunPromise = require('gun/lib/promise.js')
const mkdirp = require('mkdirp');
const { Random } = require('random-js');
const random = new Random();
test('create a key value pair using promises v2', async function (t) {
// gundb doesn't do this correctly, it errors out with a mkdir message
mkdirp.sync('testdb');
// don't use gun's default database, else state is saved across tests, which is an anti-pattern
const dbfilename = 'testdb/' + random.string(16) + '.json';
const gun = Gun({peers: [], multicast: false, file: dbfilename, web: undefined});
const value = 'value';
const result = await gun.get('key').put({property: value }).then();
t.equal(result.property, value, 'result was what we put in');
const result2 = await gun.get('key').then();
t.equal(result2.property, value, 'result2 was what we put in');
});
// gundb doesn't unref its internal timers and also multicast
// so force the process to exit.
// This test should always be last
test('force test to end', async function(t) {
t.ok(true, 'forcing test to end with process.exit');
t.end();
process.exit();
});
@jabis
Copy link

jabis commented Jan 13, 2020

Check my fork, got it running with the auth stuff :)
BR, Jabis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment