@@ -2,6 +2,8 @@ const test = require('brittle')
22const Hyperbee = require ( 'hyperbee' )
33const b4a = require ( 'b4a' )
44const Hypercore = require ( 'hypercore' )
5+ const tmpDir = require ( 'test-tmp' )
6+ const Corestore = require ( 'corestore' )
57
68const BeeDiffStream = require ( '../index' )
79const { streamToArray, setup, encodedOpen, jsonKeyedOpen, confirm, replicateAndSync } = require ( './helpers' )
@@ -852,6 +854,34 @@ test('supports diffing values skipped by hyperbee encoding', async t => {
852854 t . alike ( diffs . map ( ( { right } ) => right ?. key ) , [ undefined , undefined ] ) // deletions
853855} )
854856
857+ test ( 'throws if a snapshot is not opened' , async t => {
858+ const store = new Corestore ( await tmpDir ( ) )
859+ const core = store . get ( { name : 'bee' } )
860+ const bee = new Hyperbee ( core )
861+ t . exception (
862+ ( ) => new BeeDiffStream ( bee , bee ) ,
863+ / S n a p s h o t m u s t b e o p e n e d / ,
864+ 'none open'
865+ )
866+
867+ await bee . ready ( )
868+ const snap = bee . snapshot ( )
869+
870+ t . exception (
871+ ( ) => new BeeDiffStream ( bee , snap ) ,
872+ / S n a p s h o t m u s t b e o p e n e d / ,
873+ 'right not open'
874+ )
875+ t . exception (
876+ ( ) => new BeeDiffStream ( snap , bee ) ,
877+ / S n a p s h o t m u s t b e o p e n e d / ,
878+ 'left not open'
879+ )
880+
881+ await snap . ready ( )
882+ t . execution ( ( ) => new BeeDiffStream ( snap , bee ) , 'sanity check that happy path does not throw' )
883+ } )
884+
855885function sameKeysAndValues ( t , actual , expected ) {
856886 const extractKeysAndValues = ( { left, right } ) => {
857887 const res = { }
0 commit comments