Files
iNaturalistReactNative/tests/helpers/uniqueRealm.js
Ryan Stelly b78be9243d lint rule & autofix for "trailing comma" (#3299)
* (lint) MOB-1063 enforce trailing commas

* autofix trailing commas

* manually fix newly introduced maxlen violations

* add trailing comma convention to i18n build
2025-12-22 20:17:13 -06: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,
};
}