mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2025-12-23 22:18:36 -05:00
* (lint) MOB-1063 enforce trailing commas * autofix trailing commas * manually fix newly introduced maxlen violations * add trailing comma convention to i18n build
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import mockOs from "os";
|
|
import mockPath from "path";
|
|
import Realm from "realm";
|
|
// eslint-disable-next-line import/extensions
|
|
import realmConfig from "realmModels/index";
|
|
|
|
// Mock the realm config so it uses an in-memory database. This means data is
|
|
// only persisted until realm.close() gets called, so if the code under test
|
|
// needs data to persist in Realm across opening/closing events, we will need
|
|
// to take a different approach, e.g. writing to Realm to disk and erasing
|
|
// those files after each test run
|
|
jest.mock( "realmModels/index", ( ) => {
|
|
const originalModule = jest.requireActual( "realmModels/index" );
|
|
|
|
// Mock the default export and named export 'foo'
|
|
return {
|
|
__esModule: true,
|
|
...originalModule,
|
|
default: {
|
|
schema: originalModule.default.schema,
|
|
schemaVersion: originalModule.default.schemaVersion,
|
|
inMemory: true,
|
|
path: mockPath.join( mockOs.tmpdir( ), "testArtifacts.realm" ),
|
|
},
|
|
};
|
|
} );
|
|
|
|
// Mock the contexts so the useRealm hook will provide a single, custom copy
|
|
// of the Realm connection
|
|
jest.mock( "providers/contexts", ( ) => {
|
|
const originalModule = jest.requireActual( "providers/contexts" );
|
|
return {
|
|
__esModule: true,
|
|
...originalModule,
|
|
RealmContext: {
|
|
...originalModule.RealmContext,
|
|
useRealm: ( ) => global.realm,
|
|
},
|
|
};
|
|
} );
|
|
|
|
// Open a realm connection and stuff it in global. If there's a better way to
|
|
// do this without having jest.mock complain about referring to variables out
|
|
// of scope, please propose it.
|
|
beforeAll( async ( ) => {
|
|
global.realm = await Realm.open( realmConfig );
|
|
} );
|
|
|
|
// Ensure the realm connection gets closed
|
|
afterAll( ( ) => {
|
|
global.realm?.close( );
|
|
Realm.shutdown();
|
|
} );
|