@@ -769,6 +769,7 @@ module.exports = function (test, testCommon) {
769
769
const db = testCommon . factory ( )
770
770
await db . open ( )
771
771
772
+ const textDecoder = new TextDecoder ( )
772
773
const books = db . sublevel ( 'books' , { valueEncoding : 'json' } )
773
774
const index = db . sublevel ( 'authors' , {
774
775
// Use JSON, which normally doesn't make sense for keys but
@@ -779,7 +780,14 @@ module.exports = function (test, testCommon) {
779
780
db . on ( 'write' , ( ops ) => {
780
781
// Check that data is written to correct sublevels, specifically
781
782
// !authors!Hesse~12 rather than !books!!authors!Hesse~12.
782
- t . same ( ops . map ( x => x . key ) , [ '!books!12' , '!authors!"Hesse~12"' ] )
783
+ t . same ( ops . map ( x => decode ( x . key ) ) , [ '!books!12' , '!authors!"Hesse~12"' ] )
784
+
785
+ // It's unfortunate DX but because the write is made via the sublevel, the
786
+ // format of keys depends on the supported encodings of db. For example on
787
+ // a MemoryLevel({ storeEncoding: 'buffer' }) the key will be a buffer.
788
+ function decode ( key ) {
789
+ return db . keyEncoding ( 'utf8' ) . format === 'utf8' ? key : textDecoder . decode ( key )
790
+ }
783
791
} )
784
792
785
793
books . on ( 'write' , ( ops ) => {
0 commit comments