Created
January 7, 2020 20:39
-
-
Save pszabop/61c3b7c36aa5fe866834fda4531d9219 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check my fork, got it running with the auth stuff :)
BR, Jabis