11/* eslint-env mocha */
22const expect = require ( 'chai' ) . expect
33const ram = require ( 'random-access-memory' )
4+ const tmp = require ( 'tmp' )
5+ const path = require ( 'path' )
6+ const hyperdb = require ( 'hyperdb' )
7+
48const hypergraph = require ( '../index' )
59const constants = require ( '../lib/constants' )
610
@@ -69,7 +73,7 @@ describe('hypergraph', function () {
6973 db . on ( 'ready' , ( ) => {
7074 const stream = db . db . createReadStream ( '@prefix/' )
7175 stream . on ( 'data' , ( nodes ) => {
72-
76+ // add test
7377 } )
7478 stream . on ( 'error' , done )
7579 stream . on ( 'end' , ( ) => {
@@ -79,7 +83,38 @@ describe('hypergraph', function () {
7983 } )
8084 } )
8185 context ( 'when loading db that already exists' , ( ) => {
82- it ( 'does not add new metadata' )
86+ it ( 'does not add new metadata' , ( done ) => {
87+ tmp . dir ( function ( err , dir , cleanupCallback ) {
88+ if ( err ) return done ( err )
89+ console . log ( 'Dir: ' , dir )
90+ const dbDir = path . join ( dir , 'test.db' )
91+ // create new hyperdb
92+ const hyper = hyperdb ( dbDir )
93+ hyper . on ( 'ready' , ( ) => {
94+ // as something so that its not an empty feed
95+ hyper . put ( 'test' , 'data' , ( err ) => {
96+ if ( err ) return finish ( err )
97+ openExistingDBAsGraphDB ( )
98+ } )
99+ } )
100+ hyper . on ( 'error' , finish )
101+
102+ function openExistingDBAsGraphDB ( ) {
103+ db = hypergraph ( dbDir )
104+ db . on ( 'ready' , ( ) => {
105+ db . db . get ( '@version' , ( err , nodes ) => {
106+ expect ( nodes ) . to . eql ( null )
107+ done ( err )
108+ } )
109+ } )
110+ db . on ( 'error' , finish )
111+ }
112+ function finish ( e ) {
113+ cleanupCallback ( )
114+ done ( e )
115+ }
116+ } )
117+ } )
83118 it ( 'overrides options with metadata set in hyperdb (index)' )
84119 it ( 'overrides options with metadata set in hyperdb (name)' )
85120 } )
0 commit comments