diff --git a/spec/state-store-spec.js b/spec/state-store-spec.js index 89679a7b8d..7342bb7ea8 100644 --- a/spec/state-store-spec.js +++ b/spec/state-store-spec.js @@ -50,6 +50,12 @@ describe('StateStore', () => { }); }); + it('returns a database instance via dbPromise', async () => { + const store = new StateStore(databaseName, version); + const instance = await store.dbPromise; + expect(instance instanceof IDBDatabase).toBe(true); + }); + describe('when there is an error reading from the database', () => { it('rejects the promise returned by load', () => { const store = new StateStore(databaseName, version); @@ -119,5 +125,12 @@ describe('StateStore', () => { expect(count).toBe(0); }); }); + + it('returns a database instance via dbPromise', async () => { + const store = new StateStore(databaseName, version); + const instance = await store.dbPromise; + const Database = require("better-sqlite3"); + expect(instance instanceof Database).toBe(true); + }); }); }); diff --git a/src/state-store.js b/src/state-store.js index 1b3482aedc..adc4189021 100644 --- a/src/state-store.js +++ b/src/state-store.js @@ -44,6 +44,11 @@ module.exports = class StateStore { return this._getCorrectImplementation().then(i => i.count()); } + get dbPromise() { + // Exposed due to usage in [`project-plus`](https://web.pulsar-edit.dev/packages/project-plus) + return this._getCorrectImplementation().then(i => i.dbPromise); + } + _getCorrectImplementation() { return awaitForAtomGlobal().then(() => { if(atom.config.get('core.useLegacySessionStore')) {