Closed Frando closed 3 years ago
Most of the core tests have to be changed to async/await and adapted for API changes in the next branch.
Most methods changed from callbacks to async/await. API changes can best be seen by looking what core/lib/compat.js does.
Workspace
const store = require('@arsonar/core')
const { Workspace } = require('@arsonar/core')
const store = new Store(storagePath, opts)
const workspace = new Workspace(opts)
store.create(name, opts, cb)
await workspace.createCollection(keyOrName, opts)
store.get(keyOrName, opts, cb)
await workspace.openCollectoin(keyOrName, opts)
store.share(key)
await collection.configure({ share: true })
store.unshare(key)
await collection.configure({ share: false })
store.updateCollection (key, info, cb)
await collection.configure(configuration)
Collection
compat.js
packages/core/test
Examples from core/test/basic.js:
core/test/basic.js
old:
tape('open close', t => { createStore({ network: false }, (err, workspace, cleanup) => { if (err) t.fail(err) t.true(workspace.opened, 'opened property is set') t.error(err) cleanup(err => { t.error(err) t.end() }) }) }) tape('put and get 1', t => { createStore({ network: false }, (err, workspace, cleanup) => { t.error(err, 'tempdir ok') workspace.create('default', (err, collection) => { t.error(err) collection.putType({ name: 'doc', fields: { title: { type: 'string' } } }, err => { t.error(err) collection.put({ type: 'doc', value: { title: 'hello' } }, (err, record) => { t.error(err) const id = record.id collection.query('records', { id }, { waitForSync: true }, (err, records) => { t.error(err) t.equal(records.length, 1) t.equal(records[0].value.title, 'hello') cleanup(() => t.end()) }) }) }) }) }) })
new:
tape('open close new', async t => { const { cleanup, workspace } = await createOne() t.true(workspace.opened, 'opened property is set') await cleanup() }) tape('put and get 1', async t => { const { cleanup, workspace } = await createOne() const collection = await workspace.openCollection('default') await collection.putType({ name: 'doc', fields: { title: { type: 'string' } } }) const record = await collection.put({ type: 'doc', value: { title: 'hello' } }) t.equal(record.value.title, 'hello') const id = record.id const records = await collection.query('records', { id }, { sync: true }) t.equal(records.length, 1) t.equal(records[0].value.title, 'hello') await cleanup() })
done
Most of the core tests have to be changed to async/await and adapted for API changes in the next branch.
API changes
Most methods changed from callbacks to async/await. API changes can best be seen by looking what core/lib/compat.js does.
Workspace
const store = require('@arsonar/core')
->const { Workspace } = require('@arsonar/core')
const store = new Store(storagePath, opts)
- >const workspace = new Workspace(opts)
store.create(name, opts, cb)
->await workspace.createCollection(keyOrName, opts)
store.get(keyOrName, opts, cb)
->await workspace.openCollectoin(keyOrName, opts)
store.share(key)
->await collection.configure({ share: true })
store.unshare(key)
->await collection.configure({ share: false })
store.updateCollection (key, info, cb)
->await collection.configure(configuration)
Collection
compat.js
What needs to be done
packages/core/test
Examples from
core/test/basic.js
:old:
new: