Files
iNaturalistReactNative/tests/helpers/uniqueRealm.js
Johannes Klein 26f0863ec9 Fix: integration tests store setup when changing layout slice (#2932)
* Update MyObservations.test.js

* Remove comment

* Remove unnecessary setState

* Update MyObservationsLocalization.test.js

* Previous change can be more specific

* Update MyObservationsSimple.test.js

* Update AICamera.test.js

* Update Explore.test.js

* Update MyObservations.test.js

* Update ObsEdit.test.js

* Update SoundRecorder.test.js

* Update PhotoImport.test.js

* Update CustomTabBar.test.js

* Update SuggestionsWithUnsyncedObs.test.js

* Update SuggestionsWithSyncedObs.test.js

* Update PhotoDeletion.test.js

* Update Suggestions.test.js

* Update AddObsButton.test.js

* Update MediaViewer.test.js

* Update PhotoLibrary.test.js

* Update StandardCamera.test.js

* Update SimpleUploadBannerContainer.test.js

* This test needs to be in advanced mode

* Remove setState of shownOnce back to default

* Refactor store override calls into a helper function

* Update MyObservationsLocalization.test.js

* Update MyObservationsSimple.test.js

* Update PhotoDeletion.test.js

* Update PhotoImport.test.js

* Update SuggestionsWithSyncedObs.test.js

* Refactor to use helper

* Update SimpleUploadBannerContainer.test.js
2025-06-10 16:10:19 +02:00

44 lines
1.3 KiB
JavaScript

import os from "os";
import path from "path";
import Realm from "realm";
import realmConfig from "realmModels/index";
export default function setupUniqueRealm( realmIdentifier ) {
const mockRealmConfig = {
schema: realmConfig.schema,
schemaVersion: realmConfig.schemaVersion,
// No need to actually write to disk
inMemory: true,
// For an in memory db path is basically a unique identifier, *but* Realm
// may still write some metadata to disk, so this needs to be a real, but
// temporary, path. In theory this should prevent this test from
// interacting with other tests
path: path.join( os.tmpdir( ), `${realmIdentifier}.realm` )
};
// Mock config so that all code that runs during this test talks to the same
// database
const mockRealmModelsIndex = {
__esModule: true,
default: mockRealmConfig
};
const uniqueRealmBeforeAll = async ( ) => {
global.mockRealms = global.mockRealms || {};
global.mockRealms[realmIdentifier] = await Realm.open( mockRealmConfig );
};
// Ensure the realm connection gets closed
const uniqueRealmAfterAll = ( ) => {
global.mockRealms[realmIdentifier]?.close( );
jest.clearAllMocks( );
};
return {
mockRealmConfig,
mockRealmModelsIndex,
uniqueRealmBeforeAll,
uniqueRealmAfterAll
};
}