Bladeren bron

fix(test): reset _productionMode in getDefaultDbPath test

Bun runs all test files in a single process, so module-level state
leaks between files. The getDefaultDbPath test now resets the
_productionMode flag before asserting it throws, fixing the flaky
failure on Bun (ubuntu-latest) in CI.
Tobi Lutke 1 maand geleden
bovenliggende
commit
66e70c028e
2 gewijzigde bestanden met toevoegingen van 9 en 0 verwijderingen
  1. 5 0
      src/store.ts
  2. 4 0
      test/store.helpers.unit.test.ts

+ 5 - 0
src/store.ts

@@ -522,6 +522,11 @@ export function enableProductionMode(): void {
   _productionMode = true;
 }
 
+/** Reset production mode flag — only for testing. */
+export function _resetProductionModeForTesting(): void {
+  _productionMode = false;
+}
+
 export function getDefaultDbPath(indexName: string = "index"): string {
   // Always allow override via INDEX_PATH (for testing)
   if (process.env.INDEX_PATH) {

+ 4 - 0
test/store.helpers.unit.test.ts

@@ -7,6 +7,7 @@ import {
   homedir,
   resolve,
   getDefaultDbPath,
+  _resetProductionModeForTesting,
   getPwd,
   getRealPath,
   isVirtualPath,
@@ -48,6 +49,9 @@ describe("Path Utilities", () => {
   test("getDefaultDbPath throws in test mode without INDEX_PATH", () => {
     const originalIndexPath = process.env.INDEX_PATH;
     delete process.env.INDEX_PATH;
+    // Reset production mode in case another test file set it (bun runs all
+    // files in a single process, so module state leaks between files).
+    _resetProductionModeForTesting();
 
     expect(() => getDefaultDbPath()).toThrow("Database path not set");