@@ -2,8 +2,8 @@ import * as assert from "assert";
22import * as fakeIndexedDB from "../../index.js" ;
33
44// `indexedDB` is read-only, all others are read-write
5- const readWriteProps = Object . keys ( fakeIndexedDB ) . filter ( ( prop ) =>
6- prop . startsWith ( "IDB" ) ,
5+ const props = Object . keys ( fakeIndexedDB ) . filter (
6+ ( prop ) => prop . startsWith ( "IDB" ) || prop === "indexedDB" ,
77) as Array < keyof typeof fakeIndexedDB > ;
88
99describe ( "auto" , ( ) => {
@@ -15,7 +15,7 @@ describe("auto", () => {
1515 enumerable : true ,
1616 configurable : true ,
1717 } ) ;
18- for ( const prop of readWriteProps ) {
18+ for ( const prop of props ) {
1919 Object . defineProperty ( globalThis , prop , {
2020 value : undefined ,
2121 enumerable : true ,
@@ -27,18 +27,8 @@ describe("auto", () => {
2727 // @ts -expect-error relative to the build/ directory
2828 await import ( "../../../../auto/index.mjs" ) ;
2929
30- // check read-only indexedDB global
31- const descriptor = Object . getOwnPropertyDescriptor (
32- globalThis ,
33- "indexedDB" ,
34- ) ;
35- assert . equal ( descriptor ! . set , undefined ) ;
36- assert . equal ( descriptor ! . get ! ( ) , fakeIndexedDB . indexedDB ) ;
37- assert . equal ( descriptor ! . enumerable , true ) ;
38- assert . equal ( descriptor ! . configurable , true ) ;
39-
40- // check read-write globals
41- for ( const prop of readWriteProps ) {
30+ // check our own globals
31+ for ( const prop of props ) {
4232 const descriptor = Object . getOwnPropertyDescriptor (
4333 globalThis ,
4434 prop ,
@@ -48,15 +38,21 @@ describe("auto", () => {
4838 assert . equal ( descriptor ! . configurable , true ) ;
4939 assert . equal ( descriptor ! . writable , true ) ;
5040 }
41+
42+ // check that we can still overwrite them with `globalThis.<prop> = ...`
43+ for ( const prop of props ) {
44+ const fake = { } ;
45+ ( globalThis as any ) [ prop ] = fake ;
46+ assert . equal ( ( globalThis as any ) [ prop ] , fake ) ;
47+ }
5148 } ) ;
5249
5350 it ( "exports as cjs directly, without `default` member - issue #130" , async ( ) => {
5451 // @ts -expect-error relative to the build/ directory
5552 await import ( "../../../../auto/index.js" ) ;
5653
5754 // ensure we directly set the export as `module.exports` rather than `module.exports.default`
58- assert . ok ( ! ( globalThis as any ) . indexedDB . default ) ;
59- for ( const prop of readWriteProps ) {
55+ for ( const prop of props ) {
6056 assert . ok ( ! ( globalThis as any ) [ prop ] . default ) ;
6157 }
6258 } ) ;
0 commit comments