diff --git a/packages/app-distribution/e2e/app-distribution.e2e.js b/packages/app-distribution/e2e/app-distribution.e2e.js index 6389adfcac..5d05e3d7ee 100644 --- a/packages/app-distribution/e2e/app-distribution.e2e.js +++ b/packages/app-distribution/e2e/app-distribution.e2e.js @@ -17,6 +17,16 @@ describe('appDistribution()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('native module is loaded', function () { it('checks native module load status', function () { firebase.appDistribution().native; diff --git a/packages/app/e2e/app.e2e.js b/packages/app/e2e/app.e2e.js index 80bfe6d097..f825250b60 100644 --- a/packages/app/e2e/app.e2e.js +++ b/packages/app/e2e/app.e2e.js @@ -17,6 +17,16 @@ describe('modular', function () { describe('firebase v8 compat', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('it should allow read the default app from native', function () { if (Platform.other) return; // Not supported on non-native platforms. // app is created in tests app before all hook @@ -201,21 +211,20 @@ describe('modular', function () { }); it('it should initialize dynamic apps', async function () { - const { initializeApp, getApps, getApp } = modular; + const { initializeApp, getApps, getApp, deleteApp } = modular; - const appCount = firebase.apps.length; + const appCount = getApps().length; const name = `testscoreapp${FirebaseHelpers.id}`; const platformAppConfig = FirebaseHelpers.app.config(); const newApp = await initializeApp(platformAppConfig, name); newApp.name.should.equal(name); - newApp.toString().should.equal(name); newApp.options.apiKey.should.equal(platformAppConfig.apiKey); const apps = getApps(); should.equal(apps.includes(getApp(name)), true); should.equal(apps.length, appCount + 1); - return newApp.delete(); + return deleteApp(newApp); }); it('should error if dynamic app initialization values are incorrect', async function () { @@ -257,8 +266,8 @@ describe('modular', function () { } catch (e) { e.code.should.containEql('app/unknown'); e.message.should.containEql('Configuration fails'); - should.equal(firebase.apps.length, appCount); - should.equal(firebase.apps.includes('myname'), false); + should.equal(getApps().length, appCount); + should.equal(getApps().includes('myname'), false); } }); @@ -270,7 +279,6 @@ describe('modular', function () { const newApp = await initializeApp(platformAppConfig, name); newApp.name.should.equal(name); - newApp.toString().should.equal(name); newApp.options.apiKey.should.equal(platformAppConfig.apiKey); await deleteApp(newApp); diff --git a/packages/app/e2e/asyncStorage.e2e.js b/packages/app/e2e/asyncStorage.e2e.js index 73c6c552a6..911348bf36 100644 --- a/packages/app/e2e/asyncStorage.e2e.js +++ b/packages/app/e2e/asyncStorage.e2e.js @@ -16,8 +16,9 @@ describe('firebase.setReactNativeAsyncStorage()', function () { }); it('throws if asyncStorage is not an object', function () { + const { setReactNativeAsyncStorage } = modular; try { - firebase.setReactNativeAsyncStorage(123); + setReactNativeAsyncStorage(123); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { error.message.should.containEql("'asyncStorage' must be an object"); @@ -26,8 +27,9 @@ describe('firebase.setReactNativeAsyncStorage()', function () { }); it('throws if asyncStorage.setItem is not a function', function () { + const { setReactNativeAsyncStorage } = modular; try { - firebase.setReactNativeAsyncStorage({ setItem: 123 }); + setReactNativeAsyncStorage({ setItem: 123 }); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { error.message.should.containEql("'asyncStorage.setItem' must be a function"); @@ -36,8 +38,9 @@ describe('firebase.setReactNativeAsyncStorage()', function () { }); it('throws if asyncStorage.getItem is not a function', function () { + const { setReactNativeAsyncStorage } = modular; try { - firebase.setReactNativeAsyncStorage({ setItem: sinon.spy(), getItem: 123 }); + setReactNativeAsyncStorage({ setItem: sinon.spy(), getItem: 123 }); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { error.message.should.containEql("'asyncStorage.getItem' must be a function"); @@ -46,8 +49,9 @@ describe('firebase.setReactNativeAsyncStorage()', function () { }); it('throws if asyncStorage.removeItem is not a function', function () { + const { setReactNativeAsyncStorage } = modular; try { - firebase.setReactNativeAsyncStorage({ + setReactNativeAsyncStorage({ setItem: sinon.spy(), getItem: sinon.spy(), removeItem: 123, @@ -60,13 +64,14 @@ describe('firebase.setReactNativeAsyncStorage()', function () { }); it('sets the async storage instance', async function () { + const { setReactNativeAsyncStorage } = modular; isMemoryStorage().should.equal(true); const setItemSpy = sinon.spy(); const getItemSpy = sinon.spy(); const removeItemSpy = sinon.spy(); - firebase.setReactNativeAsyncStorage({ + setReactNativeAsyncStorage({ setItem: setItemSpy, getItem: getItemSpy, removeItem: removeItemSpy, @@ -84,10 +89,11 @@ describe('firebase.setReactNativeAsyncStorage()', function () { }); it('works with @react-native-async-storage/async-storage', async function () { + const { setReactNativeAsyncStorage } = modular; isMemoryStorage().should.equal(true); const key = Date.now().toString(); const value = 'bar'; - firebase.setReactNativeAsyncStorage(asyncStorage); + setReactNativeAsyncStorage(asyncStorage); isMemoryStorage().should.equal(false); // Through our internals, diff --git a/packages/app/e2e/config.e2e.js b/packages/app/e2e/config.e2e.js index 9e4ea2ec99..bcaef2667c 100644 --- a/packages/app/e2e/config.e2e.js +++ b/packages/app/e2e/config.e2e.js @@ -18,7 +18,8 @@ describe('config', function () { describe('meta', function () { it('should read Info.plist/AndroidManifest.xml meta data', async function () { - const metaData = await NativeModules.RNFBAppModule.metaGetAll(); + const { metaGetAll } = modular; + const metaData = await metaGetAll(); if (Platform.other) return; metaData.rnfirebase_meta_testing_string.should.equal('abc'); metaData.rnfirebase_meta_testing_boolean_false.should.equal(false); @@ -28,7 +29,8 @@ describe('config', function () { describe('json', function () { it('should read firebase.json data', async function () { - const jsonData = await NativeModules.RNFBAppModule.jsonGetAll(); + const { jsonGetAll } = modular; + const jsonData = await jsonGetAll(); if (Platform.other) return; jsonData.rnfirebase_json_testing_string.should.equal('abc'); jsonData.rnfirebase_json_testing_boolean_false.should.equal(false); @@ -38,40 +40,43 @@ describe('config', function () { describe('prefs', function () { beforeEach(async function () { - await NativeModules.RNFBAppModule.preferencesClearAll(); + const { preferencesClearAll } = modular; + await preferencesClearAll(); }); // NOTE: "preferencesClearAll" clears Firestore settings. Set DB as emulator again. after(async function () { + const { connectFirestoreEmulator, getFirestore } = firestoreModular; if (Platform.other) return; - await firebase - .firestore() - .settings({ host: 'localhost:8080', ssl: false, persistence: true }); + connectFirestoreEmulator(getFirestore(), 'localhost', 8080); }); it('should set bool values', async function () { - const prefsBefore = await NativeModules.RNFBAppModule.preferencesGetAll(); + const { preferencesGetAll, preferencesSetBool } = modular; + const prefsBefore = await preferencesGetAll(); should.equal(prefsBefore.invertase_oss, undefined); - await NativeModules.RNFBAppModule.preferencesSetBool('invertase_oss', true); - const prefsAfter = await NativeModules.RNFBAppModule.preferencesGetAll(); + await preferencesSetBool('invertase_oss', true); + const prefsAfter = await preferencesGetAll(); prefsAfter.invertase_oss.should.equal(true); }); it('should set string values', async function () { - const prefsBefore = await NativeModules.RNFBAppModule.preferencesGetAll(); + const { preferencesGetAll, preferencesSetString } = modular; + const prefsBefore = await preferencesGetAll(); should.equal(prefsBefore.invertase_oss, undefined); - await NativeModules.RNFBAppModule.preferencesSetString('invertase_oss', 'invertase.io'); - const prefsAfter = await NativeModules.RNFBAppModule.preferencesGetAll(); + await preferencesSetString('invertase_oss', 'invertase.io'); + const prefsAfter = await preferencesGetAll(); prefsAfter.invertase_oss.should.equal('invertase.io'); }); it('should clear all values', async function () { - await NativeModules.RNFBAppModule.preferencesSetString('invertase_oss', 'invertase.io'); - const prefsBefore = await NativeModules.RNFBAppModule.preferencesGetAll(); + const { preferencesClearAll, preferencesGetAll, preferencesSetString } = modular; + await preferencesSetString('invertase_oss', 'invertase.io'); + const prefsBefore = await preferencesGetAll(); prefsBefore.invertase_oss.should.equal('invertase.io'); - await NativeModules.RNFBAppModule.preferencesClearAll(); - const prefsAfter = await NativeModules.RNFBAppModule.preferencesGetAll(); + await preferencesClearAll(); + const prefsAfter = await preferencesGetAll(); should.equal(prefsAfter.invertase_oss, undefined); }); }); diff --git a/packages/app/e2e/utils.e2e.js b/packages/app/e2e/utils.e2e.js index 39c65ce54c..ec477fd4b7 100644 --- a/packages/app/e2e/utils.e2e.js +++ b/packages/app/e2e/utils.e2e.js @@ -19,34 +19,44 @@ describe('utils()', function () { if (Platform.other) return; // Not supported on non-native platforms. describe('namespace', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('accessible from firebase.app()', function () { const app = firebase.app(); should.exist(app.utils); app.utils().app.should.equal(app); }); - }); - describe('isRunningInTestLab', function () { - it('returns true or false', function () { - should.equal(firebase.utils().isRunningInTestLab, false); + describe('isRunningInTestLab', function () { + it('returns true or false', function () { + should.equal(firebase.utils().isRunningInTestLab, false); + }); }); - }); - describe('playServicesAvailability', function () { - it('returns isAvailable and Play Service status', async function () { - const playService = await firebase.utils().playServicesAvailability; - //iOS always returns { isAvailable: true, status: 0} - should(playService.isAvailable).equal(true); - should(playService.status).equal(0); + describe('playServicesAvailability', function () { + it('returns isAvailable and Play Service status', async function () { + const playService = await firebase.utils().playServicesAvailability; + //iOS always returns { isAvailable: true, status: 0} + should(playService.isAvailable).equal(true); + should(playService.status).equal(0); + }); }); - }); - describe('getPlayServicesStatus', function () { - it('returns isAvailable and Play Service status', async function () { - const status = await firebase.utils().getPlayServicesStatus(); - //iOS always returns { isAvailable: true, status: 0} - should(status.isAvailable).equal(true); - should(status.status).equal(0); + describe('getPlayServicesStatus', function () { + it('returns isAvailable and Play Service status', async function () { + const status = await firebase.utils().getPlayServicesStatus(); + //iOS always returns { isAvailable: true, status: 0} + should(status.isAvailable).equal(true); + should(status.status).equal(0); + }); }); }); }); diff --git a/packages/app/lib/FirebaseApp.js b/packages/app/lib/FirebaseApp.js index 7ff26f28c6..841138702c 100644 --- a/packages/app/lib/FirebaseApp.js +++ b/packages/app/lib/FirebaseApp.js @@ -73,7 +73,7 @@ export default class FirebaseApp { } toString() { - warnIfNotModularCall(arguments); + warnIfNotModularCall(arguments, '.name property'); return this.name; } } diff --git a/packages/app/lib/modular/index.d.ts b/packages/app/lib/modular/index.d.ts index 4f492ffd49..ec90f4f3d2 100644 --- a/packages/app/lib/modular/index.d.ts +++ b/packages/app/lib/modular/index.d.ts @@ -71,6 +71,46 @@ export function getApp(name?: string): FirebaseApp; */ export function setLogLevel(logLevel: LogLevelString): void; +/** + * Gets react-native-firebase specific "meta" data from native Info.plist / AndroidManifest.xml + * @returns map of key / value pairs containing native meta data + */ +export function metaGetAll(): Promise<{ [keyof: string]: string | boolean }>; + +/** + * Gets react-native-firebase specific "firebase.json" data + * @returns map of key / value pairs containing native firebase.json constants + */ +export function jsonGetAll(): Promise<{ [keyof: string]: string | boolean }>; + +/** + * Clears react-native-firebase specific native preferences + * @returns Promise + */ +export function preferencesClearAll(): Promise; + +/** + * Gets react-native-firebase specific native preferences + * @returns map of key / value pairs containing native preferences data + */ +export function preferencesGetAll(): Promise<{ [keyof: string]: string | boolean }>; + +/** + * Sets react-native-firebase specific native boolean preference + * @param key the name of the native preference to set + * @param value the value of the native preference to set + * @returns Promise + */ +export function preferencesSetBool(key: string, value: boolean): Promise; + +/** + * Sets react-native-firebase specific native string preference + * @param key the name of the native preference to set + * @param value the value of the native preference to set + * @returns Promise + */ +export function preferencesSetString(key: string, value: string): Promise; + /** * The `AsyncStorage` implementation to use for persisting data on 'Other' platforms. * If not specified, in memory persistence is used. diff --git a/packages/app/lib/modular/index.js b/packages/app/lib/modular/index.js index 3fa24aab65..bc4b0b1951 100644 --- a/packages/app/lib/modular/index.js +++ b/packages/app/lib/modular/index.js @@ -95,4 +95,56 @@ export function setReactNativeAsyncStorage(asyncStorage) { return setReactNativeAsyncStorageCompat.call(null, asyncStorage, MODULAR_DEPRECATION_ARG); } +/** + * Gets react-native-firebase specific "meta" data from native Info.plist / AndroidManifest.xml + * @returns map of key / value pairs containing native meta data + */ +export function metaGetAll() { + return NativeModules.RNFBAppModule.metaGetAll(); +} + +/** + * Gets react-native-firebase specific "firebase.json" data + * @returns map of key / value pairs containing native firebase.json constants + */ +export function jsonGetAll() { + return NativeModules.RNFBAppModule.jsonGetAll(); +} + +/** + * Clears react-native-firebase specific native preferences + * @returns Promise + */ +export function preferencesClearAll() { + return NativeModules.RNFBAppModule.preferencesClearAll(); +} + +/** + * Gets react-native-firebase specific native preferences + * @returns map of key / value pairs containing native preferences data + */ +export function preferencesGetAll() { + return NativeModules.RNFBAppModule.preferencesGetAll(); +} + +/** + * Sets react-native-firebase specific native boolean preference + * @param key the name of the native preference to set + * @param value the value of the native preference to set + * @returns Promise + */ +export function preferencesSetBool(key, value) { + return NativeModules.RNFBAppModule.preferencesSetBool(key, value); +} + +/** + * Sets react-native-firebase specific native string preference + * @param key the name of the native preference to set + * @param value the value of the native preference to set + * @returns Promise + */ +export function preferencesSetString(key, value) { + return NativeModules.RNFBAppModule.preferencesSetString(key, value); +} + export const SDK_VERSION = sdkVersion; diff --git a/packages/auth/e2e/auth.e2e.js b/packages/auth/e2e/auth.e2e.js index 646bb824b4..ca5c7d9fa5 100644 --- a/packages/auth/e2e/auth.e2e.js +++ b/packages/auth/e2e/auth.e2e.js @@ -26,6 +26,9 @@ const { clearAllUsers, disableUser, getLastOob, resetPassword } = require('./hel describe('auth() modular', function () { describe('firebase v8 compatibility', function () { before(async function () { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + await clearAllUsers(); await firebase.auth().createUserWithEmailAndPassword(TEST_EMAIL, TEST_PASS); const disabledUserCredential = await firebase @@ -41,6 +44,11 @@ describe('auth() modular', function () { } }); + after(async function afterTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('namespace', function () { it('accessible from firebase.app()', function () { const app = firebase.app(); @@ -1081,10 +1089,10 @@ describe('auth() modular', function () { describe('modular', function () { before(async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, getAuth } = authModular; + const defaultAuth = getAuth(getApp()); - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); await clearAllUsers(); await createUserWithEmailAndPassword(defaultAuth, TEST_EMAIL, TEST_PASS); const disabledUserCredential = await createUserWithEmailAndPassword( @@ -1096,9 +1104,10 @@ describe('auth() modular', function () { }); beforeEach(async function () { + const { getApp } = modular; const { signOut, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); if (defaultAuth.currentUser) { await signOut(defaultAuth); await Utils.sleep(50); @@ -1107,23 +1116,22 @@ describe('auth() modular', function () { describe('namespace', function () { it('accessible from firebase.app()', function () { + const { getApp } = modular; const { getAuth } = authModular; - const app = firebase.app(); - const auth = getAuth(app); + const auth = getAuth(getApp()); should.exist(auth); - auth.app.should.equal(app); }); // removing as pending if module.options.hasMultiAppSupport = true it('supports multiple apps', async function () { + const { getApp } = modular; const { getAuth } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); defaultAuth.app.name.should.equal('[DEFAULT]'); - const secondaryApp = firebase.app('secondaryFromNative'); + const secondaryApp = getApp('secondaryFromNative'); const secondaryAuth = getAuth(secondaryApp); secondaryAuth.app.name.should.equal('secondaryFromNative'); @@ -1134,33 +1142,35 @@ describe('auth() modular', function () { if (Platform.other) return; const { getAuth, getCustomAuthDomain } = authModular; - const { initializeApp } = modular; + const { getApp, initializeApp, deleteApp } = modular; const name = `testscoreapp${FirebaseHelpers.id}`; const platformAppConfig = FirebaseHelpers.app.config(); platformAppConfig.authDomain = 'example.com'; const newApp = await initializeApp(platformAppConfig, name); - const secondaryApp = firebase.app(name); + const secondaryApp = getApp(name); const secondaryAuth = getAuth(secondaryApp); secondaryAuth.app.name.should.equal(name); - secondaryApp.auth().app.name.should.equal(name); + getAuth(secondaryApp).app.name.should.equal(name); const customAuthDomain = await getCustomAuthDomain(secondaryAuth); customAuthDomain.should.equal(platformAppConfig.authDomain); - return newApp.delete(); + return deleteApp(newApp); }); }); describe('applyActionCode()', function () { // Needs a different setup to work against the auth emulator xit('works as expected', async function () { + const { getApp } = modular; const { applyActionCode, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); await applyActionCode(defaultAuth, 'fooby shooby dooby').then($ => $); }); it('errors on invalid code', async function () { + const { getApp } = modular; const { applyActionCode, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); let didError = false; try { await applyActionCode(defaultAuth, 'fooby shooby dooby').then($ => $); @@ -1174,8 +1184,9 @@ describe('auth() modular', function () { describe('checkActionCode()', function () { it('errors on invalid code', async function () { + const { getApp } = modular; const { checkActionCode, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); let didError = false; try { await checkActionCode(defaultAuth, 'fooby shooby dooby'); @@ -1192,33 +1203,35 @@ describe('auth() modular', function () { // Reload doesn't seem to update metadata on the user object. if (Platform.other) return; + const { getApp } = modular; const { signInAnonymously, signOut, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); - await signInAnonymously(defaultAuth); + const firstCredential = await signInAnonymously(defaultAuth); await Utils.sleep(500); - const firstUser = defaultAuth.currentUser; + const firstUser = firstCredential.user; await firstUser.reload(); await signOut(defaultAuth); - await signInAnonymously(defaultAuth); + const secondCredential = await signInAnonymously(defaultAuth); await Utils.sleep(500); - const secondUser = defaultAuth.currentUser; + const secondUser = secondCredential.user; await secondUser.reload(); firstUser.metadata.creationTime.should.not.equal(secondUser.metadata.creationTime); }); it('Meta data returns as expected with email and password sign in', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, signOut, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#aA'); const email1 = `${random}@${random}.com`; const pass = random; - await createUserWithEmailAndPassword(defaultAuth, email1, pass); - const firstUser = defaultAuth.currentUser; + const firstCredential = await createUserWithEmailAndPassword(defaultAuth, email1, pass); + const firstUser = firstCredential.user; await firstUser.reload(); await Utils.sleep(500); await signOut(defaultAuth); @@ -1226,8 +1239,8 @@ describe('auth() modular', function () { const anotherRandom = Utils.randString(12, '#aA'); const email2 = `${anotherRandom}@${anotherRandom}.com`; - await createUserWithEmailAndPassword(defaultAuth, email2, pass); - const secondUser = defaultAuth.currentUser; + const secondCredential = await createUserWithEmailAndPassword(defaultAuth, email2, pass); + const secondUser = secondCredential.user; await secondUser.reload(); firstUser.metadata.creationTime.should.not.equal(secondUser.metadata.creationTime); @@ -1236,8 +1249,9 @@ describe('auth() modular', function () { describe('confirmPasswordReset()', function () { it('errors on invalid code via API', async function () { + const { getApp } = modular; const { confirmPasswordReset, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); try { await confirmPasswordReset(defaultAuth, 'fooby shooby dooby', 'passwordthing'); @@ -1250,8 +1264,9 @@ describe('auth() modular', function () { describe('signInWithCustomToken()', function () { // Needs a different setup when running against the emulator xit('signs in with an admin SDK created custom auth token', async function () { + const { getApp } = modular; const { signInWithEmailAndPassword, signOut, signInWithCustomToken, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const successCb = currentUserCredential => { const currentUser = currentUserCredential.user; @@ -1289,10 +1304,11 @@ describe('auth() modular', function () { describe('onAuthStateChanged()', function () { it('calls callback with the current user and when auth state changes', async function () { + const { getApp } = modular; const { signInAnonymously, signOut, onAuthStateChanged, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); - await signInAnonymously(defaultAuth); + const credential = await signInAnonymously(defaultAuth); await Utils.sleep(50); // Test @@ -1306,7 +1322,7 @@ describe('auth() modular', function () { }); }); - callback.should.be.calledWith(defaultAuth.currentUser); + callback.should.be.calledWith(credential.user); callback.should.be.calledOnce(); // Sign out @@ -1323,8 +1339,9 @@ describe('auth() modular', function () { }); it('accepts observer instead of callback as well', async function () { + const { getApp } = modular; const { signInAnonymously, signOut, onAuthStateChanged, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); await signInAnonymously(defaultAuth); await Utils.sleep(200); @@ -1358,10 +1375,11 @@ describe('auth() modular', function () { }); it('stops listening when unsubscribed', async function () { + const { getApp } = modular; const { signInAnonymously, signOut, onAuthStateChanged, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); - await signInAnonymously(defaultAuth); + const credential = await signInAnonymously(defaultAuth); await Utils.sleep(200); // Test @@ -1375,7 +1393,7 @@ describe('auth() modular', function () { }); }); - callback.should.be.calledWith(defaultAuth.currentUser); + callback.should.be.calledWith(credential.user); callback.should.be.calledOnce(); // Sign out @@ -1401,8 +1419,9 @@ describe('auth() modular', function () { }); it('returns the same user with multiple subscribers #1815', async function () { + const { getApp } = modular; const { signInAnonymously, signOut, onAuthStateChanged, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const callback = sinon.spy(); @@ -1455,10 +1474,11 @@ describe('auth() modular', function () { describe('onIdTokenChanged()', function () { it('calls callback with the current user and when auth state changes', async function () { + const { getApp } = modular; const { signInAnonymously, signOut, onIdTokenChanged, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); - await signInAnonymously(defaultAuth); + const credential = await signInAnonymously(defaultAuth); await Utils.sleep(200); // Test @@ -1472,7 +1492,7 @@ describe('auth() modular', function () { }); }); - callback.should.be.calledWith(defaultAuth.currentUser); + callback.should.be.calledWith(credential.user); callback.should.be.calledOnce(); // Sign out @@ -1488,10 +1508,11 @@ describe('auth() modular', function () { }); it('stops listening when unsubscribed', async function () { + const { getApp } = modular; const { signInAnonymously, signOut, onIdTokenChanged, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); - await signInAnonymously(defaultAuth); + const credential = await signInAnonymously(defaultAuth); await Utils.sleep(200); // Test @@ -1505,7 +1526,7 @@ describe('auth() modular', function () { }); }); - callback.should.be.calledWith(defaultAuth.currentUser); + callback.should.be.calledWith(credential.user); callback.should.be.calledOnce(); // Sign out @@ -1531,8 +1552,9 @@ describe('auth() modular', function () { }); it('listens to a null user when auth result is not defined', async function () { + const { getApp } = modular; const { onIdTokenChanged, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); let unsubscribe; @@ -1551,8 +1573,9 @@ describe('auth() modular', function () { describe('signInAnonymously()', function () { it('it should sign in anonymously', async function () { + const { getApp } = modular; const { signInAnonymously, signOut, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const successCb = currentUserCredential => { const currentUser = currentUserCredential.user; @@ -1577,8 +1600,9 @@ describe('auth() modular', function () { describe('signInWithEmailAndPassword()', function () { it('it should login with email and password', async function () { + const { getApp } = modular; const { signInWithEmailAndPassword, signOut, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const successCb = currentUserCredential => { const currentUser = currentUserCredential.user; @@ -1606,8 +1630,9 @@ describe('auth() modular', function () { }); it('it should error on login if user is disabled', async function () { + const { getApp } = modular; const { signInWithEmailAndPassword, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const successCb = () => Promise.reject(new Error('Did not error.')); @@ -1625,8 +1650,9 @@ describe('auth() modular', function () { }); it('it should error on login if password incorrect', async function () { + const { getApp } = modular; const { signInWithEmailAndPassword, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const successCb = () => Promise.reject(new Error('Did not error.')); @@ -1644,8 +1670,9 @@ describe('auth() modular', function () { }); it('it should error on login if user not found', async function () { + const { getApp } = modular; const { signInWithEmailAndPassword, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#aA'); const email = `${random}@${random}.com`; @@ -1669,8 +1696,9 @@ describe('auth() modular', function () { describe('signInWithCredential()', function () { it('it should login with email and password', async function () { + const { getApp } = modular; const { signInWithCredential, getAuth, signOut } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const credential = firebase.auth.EmailAuthProvider.credential(TEST_EMAIL, TEST_PASS); const successCb = currentUserCredential => { @@ -1695,8 +1723,9 @@ describe('auth() modular', function () { }); it('it should error on login if user is disabled', async function () { + const { getApp } = modular; const { signInWithCredential, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const credential = firebase.auth.EmailAuthProvider.credential( DISABLED_EMAIL, DISABLED_PASS, @@ -1718,8 +1747,9 @@ describe('auth() modular', function () { }); it('it should error on login if password incorrect', async function () { + const { getApp } = modular; const { signInWithCredential, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const credential = firebase.auth.EmailAuthProvider.credential( TEST_EMAIL, TEST_PASS + '666', @@ -1741,8 +1771,9 @@ describe('auth() modular', function () { }); it('it should error on login if user not found', async function () { + const { getApp } = modular; const { signInWithCredential, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#aA'); const email = `${random}@${random}.com`; const pass = random; @@ -1766,8 +1797,9 @@ describe('auth() modular', function () { describe('createUserWithEmailAndPassword()', function () { it('it should create a user with an email and password', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#aA'); const email = `${random}@${random}.com`; @@ -1797,8 +1829,9 @@ describe('auth() modular', function () { }); it('it should error on create with invalid email', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#aA'); const email = `${random}${random}.com.boop.shoop`; @@ -1813,8 +1846,9 @@ describe('auth() modular', function () { }); it('it should error on create if email in use', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); try { await createUserWithEmailAndPassword(defaultAuth, TEST_EMAIL, TEST_PASS); @@ -1825,8 +1859,9 @@ describe('auth() modular', function () { }); it('it should error on create if password weak', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const email = 'testy@testy.com'; const pass = '123'; @@ -1844,8 +1879,9 @@ describe('auth() modular', function () { describe('fetchSignInMethodsForEmail()', function () { it('it should return password provider for an email address', async function () { + const { getApp } = modular; const { fetchSignInMethodsForEmail, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); try { const providers = await fetchSignInMethodsForEmail(defaultAuth, TEST_EMAIL); @@ -1857,8 +1893,9 @@ describe('auth() modular', function () { }); it('it should return an empty array for a not found email', async function () { + const { getApp } = modular; const { fetchSignInMethodsForEmail, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); try { const providers = await fetchSignInMethodsForEmail( @@ -1873,8 +1910,9 @@ describe('auth() modular', function () { }); it('it should return an error for a bad email address', async function () { + const { getApp } = modular; const { fetchSignInMethodsForEmail, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); try { await fetchSignInMethodsForEmail(defaultAuth, 'foobar'); @@ -1887,8 +1925,9 @@ describe('auth() modular', function () { describe('signOut()', function () { it('it should reject signOut if no currentUser', async function () { + const { getApp } = modular; const { signOut, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); if (defaultAuth.currentUser) { throw new Error(`A user is currently signed in. ${defaultAuth.currentUser.uid}`); @@ -1906,8 +1945,9 @@ describe('auth() modular', function () { describe('delete()', function () { it('should delete a user', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#aA'); const email = `${random}@${random}.com`; @@ -1930,8 +1970,9 @@ describe('auth() modular', function () { describe('languageCode', function () { it('it should change the language code', async function () { + const { getApp } = modular; const { getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); defaultAuth.languageCode = 'en'; @@ -1959,8 +2000,9 @@ describe('auth() modular', function () { describe('getRedirectResult()', function () { it('should throw an unsupported error', function () { + const { getApp } = modular; const { getRedirectResult, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); try { getRedirectResult(defaultAuth); @@ -1974,8 +2016,9 @@ describe('auth() modular', function () { describe('setPersistence()', function () { it('should throw an unsupported error', function () { + const { getApp } = modular; const { setPersistence, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); try { setPersistence(defaultAuth); @@ -1989,18 +2032,22 @@ describe('auth() modular', function () { describe('sendPasswordResetEmail()', function () { it('should not error', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, sendPasswordResetEmail, getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#aA'); const email = `${random}@${random}.com`; + let credential = undefined; try { - await createUserWithEmailAndPassword(defaultAuth, email, random); + credential = await createUserWithEmailAndPassword(defaultAuth, email, random); await sendPasswordResetEmail(defaultAuth, email); } catch (error) { throw new Error('sendPasswordResetEmail() caused an error', error); } finally { - await defaultAuth.currentUser.delete(); + if (credential) { + await credential.user.delete(); + } } }); @@ -2008,42 +2055,48 @@ describe('auth() modular', function () { // FIXME Fails on android against auth emulator with: // com.google.firebase.FirebaseException: An internal error has occurred. if (Platform.ios) { + const { getApp } = modular; const { createUserWithEmailAndPassword, sendPasswordResetEmail, getAuth, verifyPasswordResetCode, } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#a'); const email = `${random}@${random}.com`; + let credential = undefined; try { - await createUserWithEmailAndPassword(defaultAuth, email, random); + credential = await createUserWithEmailAndPassword(defaultAuth, email, random); await sendPasswordResetEmail(defaultAuth, email); const { oobCode } = await getLastOob(email); await verifyPasswordResetCode(defaultAuth, oobCode); } catch (error) { throw new Error('sendPasswordResetEmail() caused an error', error); } finally { - await defaultAuth.currentUser.delete(); + if (credential) { + await credential.user.delete(); + } } } }); it('should fail to verify with invalid code', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, sendPasswordResetEmail, getAuth, verifyPasswordResetCode, } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#a'); const email = `${random}@${random}.com`; + let credential = undefined; try { - await createUserWithEmailAndPassword(defaultAuth, email, random); + credential = await createUserWithEmailAndPassword(defaultAuth, email, random); await sendPasswordResetEmail(defaultAuth, email); const { oobCode } = await getLastOob(email); await verifyPasswordResetCode(defaultAuth, oobCode + 'badcode'); @@ -2051,11 +2104,14 @@ describe('auth() modular', function () { } catch (error) { error.message.should.containEql('[auth/invalid-action-code]'); } finally { - await defaultAuth.currentUser.delete(); + if (credential) { + await credential.user.delete(); + } } }); it('should change password correctly OOB', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, sendPasswordResetEmail, @@ -2063,12 +2119,13 @@ describe('auth() modular', function () { signOut, signInWithEmailAndPassword, } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#a'); const email = `${random}@${random}.com`; + let credential = undefined; try { - await createUserWithEmailAndPassword(defaultAuth, email, random); + credential = await createUserWithEmailAndPassword(defaultAuth, email, random); await sendPasswordResetEmail(defaultAuth, email); const { oobCode } = await getLastOob(email); await resetPassword(oobCode, 'testNewPassword'); @@ -2078,11 +2135,14 @@ describe('auth() modular', function () { } catch (error) { throw new Error('sendPasswordResetEmail() caused an error', error); } finally { - await defaultAuth.currentUser.delete(); + if (credential) { + await defaultAuth.currentUser.delete(); + } } }); it('should change password correctly via API', async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, sendPasswordResetEmail, @@ -2091,10 +2151,11 @@ describe('auth() modular', function () { signOut, signInWithEmailAndPassword, } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const random = Utils.randString(12, '#a'); const email = `${random}@${random}.com`; + let credential = undefined; try { await createUserWithEmailAndPassword(defaultAuth, email, random); await sendPasswordResetEmail(defaultAuth, email); @@ -2102,19 +2163,22 @@ describe('auth() modular', function () { await confirmPasswordReset(defaultAuth, oobCode, 'testNewPassword'); await signOut(defaultAuth); await Utils.sleep(50); - await signInWithEmailAndPassword(defaultAuth, email, 'testNewPassword'); + credential = await signInWithEmailAndPassword(defaultAuth, email, 'testNewPassword'); } catch (error) { throw new Error('sendPasswordResetEmail() caused an error', error); } finally { - await defaultAuth.currentUser.delete(); + if (credential) { + await credential.user.delete(); + } } }); }); describe('useDeviceLanguage()', function () { it('should throw an unsupported error', function () { + const { getApp } = modular; const { getAuth, useDeviceLanguage } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); try { useDeviceLanguage(defaultAuth); @@ -2129,8 +2193,9 @@ describe('auth() modular', function () { describe('useUserAccessGroup()', function () { // Android simply does Promise.resolve, that is sufficient for this test multi-platform it('should return "null" when accessing a group that exists', async function () { + const { getApp } = modular; const { getAuth, useUserAccessGroup } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); const successfulKeychain = await useUserAccessGroup( defaultAuth, @@ -2146,8 +2211,9 @@ describe('auth() modular', function () { }); it('should throw when requesting an inaccessible group', async function () { + const { getApp } = modular; const { getAuth, useUserAccessGroup } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); // Android will never throw, so this test is iOS only if (Platform.ios) { @@ -2163,8 +2229,9 @@ describe('auth() modular', function () { describe('setTenantId()', function () { it('should return null if tenantId unset', function () { + const { getApp } = modular; const { getAuth } = authModular; - const defaultAuth = getAuth(firebase.app()); + const defaultAuth = getAuth(getApp()); should.not.exist(defaultAuth.tenantId); }); diff --git a/packages/auth/e2e/helpers.js b/packages/auth/e2e/helpers.js index 5595c431d0..653826fbf7 100644 --- a/packages/auth/e2e/helpers.js +++ b/packages/auth/e2e/helpers.js @@ -178,34 +178,39 @@ exports.signInUser = async function signInUser(oobUrl) { }; async function createVerifiedUser(email, password) { - await firebase.auth().createUserWithEmailAndPassword(email, password); - await firebase.auth().currentUser.sendEmailVerification(); + const { getAuth, createUserWithEmailAndPassword } = authModular; + const credential = await createUserWithEmailAndPassword(getAuth(), email, password); + await credential.user.sendEmailVerification(); const { oobCode } = await getLastOob(email); await verifyEmail(oobCode); - await firebase.auth().currentUser.reload(); + await credential.user.reload(); + return credential.user; } exports.createVerifiedUser = createVerifiedUser; /** * Create a new user with a second factor enrolled. Returns phoneNumber, email and password * for testing purposes. The session used to enroll the factor is terminated. You'll have to - * sign in using `firebase.auth().signInWithEmailAndPassword()`. + * sign in using `signInWithEmailAndPassword(getAuth())`. */ exports.createUserWithMultiFactor = async function createUserWithMultiFactor() { + const { getAuth, multiFactor, signOut, PhoneAuthProvider, PhoneMultiFactorGenerator } = + authModular; const email = 'verified@example.com'; const password = 'test123'; - await createVerifiedUser(email, password); - const multiFactorUser = await firebase.auth().multiFactor(firebase.auth().currentUser); + const user = await createVerifiedUser(email, password); + const multiFactorUser = await multiFactor(user); const session = await multiFactorUser.getSession(); const phoneNumber = getRandomPhoneNumber(); - const verificationId = await firebase - .auth() - .verifyPhoneNumberForMultiFactor({ phoneNumber, session }); + const verificationId = await new PhoneAuthProvider(getAuth()).verifyPhoneNumber({ + phoneNumber, + session, + }); const verificationCode = await getLastSmsCode(phoneNumber); - const cred = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode); - const multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(cred); + const cred = PhoneAuthProvider.credential(verificationId, verificationCode); + const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(cred); await multiFactorUser.enroll(multiFactorAssertion, 'Hint displayName'); - await firebase.auth().signOut(); + await signOut(getAuth()); return Promise.resolve({ phoneNumber, @@ -219,19 +224,27 @@ exports.signInUserWithMultiFactor = async function signInUserWithMultiFactor( password, phoneNumber, ) { + const { + getAuth, + getMultiFactorResolver, + signInWithEmailAndPassword, + PhoneAuthProvider, + PhoneMultiFactorGenerator, + } = authModular; try { - await firebase.auth().signInWithEmailAndPassword(email, password); + await signInWithEmailAndPassword(getAuth(), email, password); } catch (e) { e.message.should.equal( '[auth/multi-factor-auth-required] Please complete a second factor challenge to finish signing into this account.', ); - const resolver = firebase.auth().getMultiFactorResolver(e); - let verificationId = await firebase - .auth() - .verifyPhoneNumberWithMultiFactorInfo(resolver.hints[0], resolver.session); + const resolver = getMultiFactorResolver(getAuth(), e); + let verificationId = await new PhoneAuthProvider(getAuth()).verifyPhoneNumber({ + multiFactorHint: resolver.hints[0], + session: resolver.session, + }); let verificationCode = await getLastSmsCode(phoneNumber); - const credential = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode); - let multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(credential); + const credential = PhoneAuthProvider.credential(verificationId, verificationCode); + let multiFactorAssertion = PhoneMultiFactorGenerator.assertion(credential); return resolver.resolveSignIn(multiFactorAssertion); } }; diff --git a/packages/auth/e2e/multiFactor.e2e.js b/packages/auth/e2e/multiFactor.e2e.js index e894f18cf2..1a48b6ed86 100644 --- a/packages/auth/e2e/multiFactor.e2e.js +++ b/packages/auth/e2e/multiFactor.e2e.js @@ -18,6 +18,9 @@ describe('multi-factor modular', function () { describe('firebase v8 compatibility', function () { beforeEach(async function () { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + await clearAllUsers(); await firebase.auth().createUserWithEmailAndPassword(TEST_EMAIL, TEST_PASS); if (firebase.auth().currentUser) { @@ -26,6 +29,11 @@ describe('multi-factor modular', function () { } }); + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('has no multi-factor information if not enrolled', async function () { await firebase.auth().signInWithEmailAndPassword(TEST_EMAIL, TEST_PASS); const { multiFactor } = firebase.auth().currentUser; @@ -520,10 +528,10 @@ describe('multi-factor modular', function () { describe('modular', function () { beforeEach(async function () { + const { getApp } = modular; const { createUserWithEmailAndPassword, getAuth, signOut } = authModular; + const defaultAuth = getAuth(getApp()); - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); await clearAllUsers(); await createUserWithEmailAndPassword(defaultAuth, TEST_EMAIL, TEST_PASS); if (defaultAuth.currentUser) { @@ -533,13 +541,13 @@ describe('multi-factor modular', function () { }); it('has no multi-factor information if not enrolled', async function () { + const { getApp } = modular; const { signInWithEmailAndPassword, getAuth } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); - await signInWithEmailAndPassword(defaultAuth, TEST_EMAIL, TEST_PASS); - const multiFactorUser = defaultAuth.currentUser.multiFactor; + const credential = await signInWithEmailAndPassword(defaultAuth, TEST_EMAIL, TEST_PASS); + const multiFactorUser = credential.user.multiFactor; multiFactorUser.should.be.an.Object(); multiFactorUser.enrolledFactors.should.be.an.Array(); multiFactorUser.enrolledFactors.length.should.equal(0); @@ -554,10 +562,16 @@ describe('multi-factor modular', function () { const { phoneNumber, email, password } = await createUserWithMultiFactor(); const maskedNumber = '+********' + phoneNumber.substring(phoneNumber.length - 4); - const { signInWithEmailAndPassword, getAuth, getMultiFactorResolver } = authModular; + const { getApp } = modular; + const { + signInWithEmailAndPassword, + getAuth, + getMultiFactorResolver, + PhoneAuthProvider, + PhoneMultiFactorGenerator, + } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); try { await signInWithEmailAndPassword(defaultAuth, email, password); @@ -573,9 +587,7 @@ describe('multi-factor modular', function () { multiFactorResolver.session.should.be.a.String(); - const verificationId = await new firebase.auth.PhoneAuthProvider( - defaultAuth, - ).verifyPhoneNumber({ + const verificationId = await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ multiFactorHint: multiFactorResolver.hints[0], session: multiFactorResolver.session, }); @@ -586,11 +598,11 @@ describe('multi-factor modular', function () { // iOS simulator uses a masked phone number verificationCode = await getLastSmsCode(maskedNumber); } - const phoneAuthCredential = new firebase.auth.PhoneAuthProvider.credential( + const phoneAuthCredential = new PhoneAuthProvider.credential( verificationId, verificationCode, ); - const assertion = firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential); + const assertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential); return multiFactorResolver .resolveSignIn(assertion) .then(userCredential => { @@ -620,15 +632,16 @@ describe('multi-factor modular', function () { const { phoneNumber, email, password } = await createUserWithMultiFactor(); + const { getApp } = modular; const { signInWithEmailAndPassword, getAuth, - // authPhoneMultiFactor, getMultiFactorResolver, + PhoneAuthProvider, + PhoneMultiFactorGenerator, } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); try { await signInWithEmailAndPassword(defaultAuth, email, password); @@ -637,39 +650,30 @@ describe('multi-factor modular', function () { const multiFactorResolver = getMultiFactorResolver(defaultAuth, e); - const verificationId = await new firebase.auth.PhoneAuthProvider( - defaultAuth, - ).verifyPhoneNumber({ + const verificationId = await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ multiFactorHint: multiFactorResolver.hints[0], session: multiFactorResolver.session, }); - const phoneAuthCredential = firebase.auth.PhoneAuthProvider.credential( - verificationId, - 'incorrect', - ); - const assertion = firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential); + const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, 'incorrect'); + const assertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential); try { await multiFactorResolver.resolveSignIn(assertion); } catch (e) { e.code.should.equal('auth/invalid-verification-code'); - const newVerificationId = await new firebase.auth.PhoneAuthProvider( - defaultAuth, - ).verifyPhoneNumber({ + const newVerificationId = await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ multiFactorHint: multiFactorResolver.hints[0], session: multiFactorResolver.session, }); const verificationCode = await getLastSmsCode(phoneNumber); - const newPhoneAuthCredential = firebase.auth.PhoneAuthProvider.credential( + const newPhoneAuthCredential = PhoneAuthProvider.credential( newVerificationId, verificationCode, ); - const newAssertion = - firebase.auth.PhoneMultiFactorGenerator.assertion(newPhoneAuthCredential); - await multiFactorResolver.resolveSignIn(newAssertion); - const currentUser = defaultAuth.currentUser; - currentUser.email.should.equal(email); + const newAssertion = PhoneMultiFactorGenerator.assertion(newPhoneAuthCredential); + const credential = await multiFactorResolver.resolveSignIn(newAssertion); + credential.user.email.should.equal(email); return Promise.resolve(); } } @@ -683,10 +687,16 @@ describe('multi-factor modular', function () { const { phoneNumber, email, password } = await createUserWithMultiFactor(); - const { signInWithEmailAndPassword, getAuth, getMultiFactorResolver } = authModular; + const { getApp } = modular; + const { + signInWithEmailAndPassword, + getAuth, + getMultiFactorResolver, + PhoneAuthProvider, + PhoneMultiFactorGenerator, + } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); try { await signInWithEmailAndPassword(defaultAuth, email, password); @@ -695,17 +705,14 @@ describe('multi-factor modular', function () { const multiFactorResolver = getMultiFactorResolver(defaultAuth, e); - await new firebase.auth.PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ + await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ multiFactorHint: multiFactorResolver.hints[0], session: multiFactorResolver.session, }); const verificationCode = await getLastSmsCode(phoneNumber); - const phoneAuthCredential = firebase.auth.PhoneAuthProvider.credential( - 'incorrect', - verificationCode, - ); - const assertion = firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential); + const phoneAuthCredential = PhoneAuthProvider.credential('incorrect', verificationCode); + const assertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential); try { await multiFactorResolver.resolveSignIn(assertion); } catch (e) { @@ -720,10 +727,11 @@ describe('multi-factor modular', function () { it('reports an error when using an unknown factor', async function () { const { email, password } = await createUserWithMultiFactor(); - const { signInWithEmailAndPassword, getAuth, getMultiFactorResolver } = authModular; + const { getApp } = modular; + const { signInWithEmailAndPassword, getAuth, getMultiFactorResolver, PhoneAuthProvider } = + authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); try { await signInWithEmailAndPassword(defaultAuth, email, password); @@ -736,7 +744,7 @@ describe('multi-factor modular', function () { uid: 'notknown', }; try { - await new firebase.auth.PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ + await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ multiFactorHint: unknownFactor, session: multiFactorResolver.session, }); @@ -759,10 +767,10 @@ describe('multi-factor modular', function () { this.skip(); } + const { getApp } = modular; const { signInWithEmailAndPassword, getAuth, multiFactor } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); await signInWithEmailAndPassword(defaultAuth, TEST_EMAIL, TEST_PASS); @@ -789,32 +797,30 @@ describe('multi-factor modular', function () { this.skip(); } - const { getAuth, multiFactor } = authModular; + const { getApp } = modular; + const { getAuth, multiFactor, PhoneAuthProvider, PhoneMultiFactorGenerator } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); try { - await createVerifiedUser('verified@example.com', 'test123'); + const user = await createVerifiedUser('verified@example.com', 'test123'); const phoneNumber = getRandomPhoneNumber(); - should.deepEqual(defaultAuth.currentUser.multiFactor.enrolledFactors, []); + should.deepEqual(user.multiFactor.enrolledFactors, []); const multiFactorUser = await multiFactor(defaultAuth.currentUser); const session = await multiFactorUser.getSession(); - const verificationId = await new firebase.auth.PhoneAuthProvider( - defaultAuth, - ).verifyPhoneNumber({ + const verificationId = await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ phoneNumber: phoneNumber, session, }); const verificationCode = await getLastSmsCode(phoneNumber); - const cred = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode); - const multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(cred); + const cred = PhoneAuthProvider.credential(verificationId, verificationCode); + const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(cred); await multiFactorUser.enroll(multiFactorAssertion, 'Hint displayName'); - const enrolledFactors = firebase.auth().currentUser.multiFactor.enrolledFactors; + const enrolledFactors = getAuth().currentUser.multiFactor.enrolledFactors; enrolledFactors.length.should.equal(1); enrolledFactors[0].displayName.should.equal('Hint displayName'); enrolledFactors[0].factorId.should.equal('phone'); @@ -831,32 +837,30 @@ describe('multi-factor modular', function () { this.skip(); } - const { getAuth, multiFactor } = authModular; + const { getApp } = modular; + const { getAuth, multiFactor, PhoneAuthProvider, PhoneMultiFactorGenerator } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); try { - await createVerifiedUser('verified@example.com', 'test123'); + const user = await createVerifiedUser('verified@example.com', 'test123'); const phoneNumber = getRandomPhoneNumber(); - should.deepEqual(defaultAuth.currentUser.multiFactor.enrolledFactors, []); - const multiFactorUser = await multiFactor(defaultAuth.currentUser); + should.deepEqual(user.multiFactor.enrolledFactors, []); + const multiFactorUser = await multiFactor(user); const session = await multiFactorUser.getSession(); - const verificationId = await new firebase.auth.PhoneAuthProvider( - defaultAuth, - ).verifyPhoneNumber({ + const verificationId = await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ phoneNumber: phoneNumber, session: session, }); const verificationCode = await getLastSmsCode(phoneNumber); - const cred = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode); - const multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(cred); + const cred = PhoneAuthProvider.credential(verificationId, verificationCode); + const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(cred); await multiFactorUser.enroll(multiFactorAssertion); - const enrolledFactors = defaultAuth.currentUser.multiFactor.enrolledFactors; + const enrolledFactors = getAuth().currentUser.multiFactor.enrolledFactors; enrolledFactors.length.should.equal(1); should.equal(enrolledFactors[0].displayName, null); } catch (e) { @@ -870,31 +874,29 @@ describe('multi-factor modular', function () { this.skip(); } - const { getAuth, multiFactor } = authModular; + const { getApp } = modular; + const { getAuth, multiFactor, PhoneAuthProvider, PhoneMultiFactorGenerator } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); const { email, password, phoneNumber } = await createUserWithMultiFactor(); - await signInUserWithMultiFactor(email, password, phoneNumber); + const credential = await signInUserWithMultiFactor(email, password, phoneNumber); const anotherNumber = getRandomPhoneNumber(); - const multiFactorUser = await multiFactor(defaultAuth.currentUser); + const multiFactorUser = await multiFactor(credential.user); const session = await multiFactorUser.getSession(); - const verificationId = await new firebase.auth.PhoneAuthProvider( - defaultAuth, - ).verifyPhoneNumber({ + const verificationId = await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ phoneNumber: anotherNumber, session: session, }); const verificationCode = await getLastSmsCode(anotherNumber); - const cred = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode); - const multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(cred); + const cred = PhoneAuthProvider.credential(verificationId, verificationCode); + const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(cred); const displayName = 'Another displayName'; await multiFactorUser.enroll(multiFactorAssertion, displayName); - const enrolledFactors = firebase.auth().currentUser.multiFactor.enrolledFactors; + const enrolledFactors = getAuth().currentUser.multiFactor.enrolledFactors; enrolledFactors.length.should.equal(2); const matchingFactor = enrolledFactors.find(factor => factor.displayName === displayName); matchingFactor.should.be.an.Object(); @@ -942,10 +944,16 @@ describe('multi-factor modular', function () { this.skip(); } - const { getAuth, signInWithEmailAndPassword, getMultiFactorResolver } = authModular; + const { getApp } = modular; + const { + getAuth, + signInWithEmailAndPassword, + getMultiFactorResolver, + PhoneAuthProvider, + PhoneMultiFactorGenerator, + } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); const { phoneNumber, email, password } = await createUserWithMultiFactor(); @@ -960,7 +968,7 @@ describe('multi-factor modular', function () { ); resolver = getMultiFactorResolver(defaultAuth, e); } - await new firebase.auth.PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ + await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ multiFactorHint: resolver.hints[0], session: resolver.session, }); @@ -968,11 +976,8 @@ describe('multi-factor modular', function () { // AND I request a verification code const verificationCode = await getLastSmsCode(phoneNumber); // AND I use an incorrect verificationId - const credential = firebase.auth.PhoneAuthProvider.credential( - 'wrongVerificationId', - verificationCode, - ); - const multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(credential); + const credential = PhoneAuthProvider.credential('wrongVerificationId', verificationCode); + const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(credential); try { // WHEN I try to resolve the sign-in @@ -988,10 +993,11 @@ describe('multi-factor modular', function () { }); it('throws an error for unknown sessions', async function () { - const { getAuth, signInWithEmailAndPassword, getMultiFactorResolver } = authModular; + const { getApp } = modular; + const { getAuth, signInWithEmailAndPassword, getMultiFactorResolver, PhoneAuthProvider } = + authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); const { email, password } = await createUserWithMultiFactor(); let resolver = null; @@ -1006,7 +1012,7 @@ describe('multi-factor modular', function () { } try { - await new firebase.auth.PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ + await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ multiFactorHint: resolver.hints[0], session: 'unknown-session', }); @@ -1021,10 +1027,16 @@ describe('multi-factor modular', function () { }); it('throws an error for unknown verification code', async function () { - const { getAuth, signInWithEmailAndPassword, getMultiFactorResolver } = authModular; + const { getApp } = modular; + const { + getAuth, + signInWithEmailAndPassword, + getMultiFactorResolver, + PhoneAuthProvider, + PhoneMultiFactorGenerator, + } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); const { email, password } = await createUserWithMultiFactor(); @@ -1039,19 +1051,14 @@ describe('multi-factor modular', function () { ); resolver = getMultiFactorResolver(defaultAuth, e); } - const verificationId = await new firebase.auth.PhoneAuthProvider( - defaultAuth, - ).verifyPhoneNumber({ + const verificationId = await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ multiFactorHint: resolver.hints[0], session: resolver.session, }); // AND I use an incorrect verificationId - const credential = firebase.auth.PhoneAuthProvider.credential( - verificationId, - 'wrong-verification-code', - ); - const multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(credential); + const credential = PhoneAuthProvider.credential(verificationId, 'wrong-verification-code'); + const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(credential); try { // WHEN I try to resolve the sign-in @@ -1072,22 +1079,22 @@ describe('multi-factor modular', function () { this.skip(); } - const { getAuth, signInWithPhoneNumber, multiFactor } = authModular; + const { getApp } = modular; + const { getAuth, signInWithPhoneNumber, multiFactor, PhoneAuthProvider } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); // GIVEN a user that only signs in with phone const testPhone = getRandomPhoneNumber(); const confirmResult = await signInWithPhoneNumber(defaultAuth, testPhone); const lastSmsCode = await getLastSmsCode(testPhone); - await confirmResult.confirm(lastSmsCode); + const credential = await confirmResult.confirm(lastSmsCode); // WHEN they attempt to enroll a second factor - const multiFactorUser = await multiFactor(defaultAuth.currentUser); + const multiFactorUser = await multiFactor(credential.user); const session = await multiFactorUser.getSession(); try { - await new firebase.auth.PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ + await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ phoneNumber: '+1123123', session, }); @@ -1103,16 +1110,16 @@ describe('multi-factor modular', function () { }); it('can not enroll when phone number is missing + sign', async function () { - const { getAuth, multiFactor } = authModular; + const { getApp } = modular; + const { getAuth, multiFactor, PhoneAuthProvider } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); - await createVerifiedUser('verified@example.com', 'test123'); - const multiFactorUser = multiFactor(defaultAuth.currentUser); + const user = await createVerifiedUser('verified@example.com', 'test123'); + const multiFactorUser = multiFactor(user); const session = await multiFactorUser.getSession(); try { - await new firebase.auth.PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ + await new PhoneAuthProvider(defaultAuth).verifyPhoneNumber({ phoneNumber: '491575', session, }); diff --git a/packages/auth/e2e/phone.e2e.js b/packages/auth/e2e/phone.e2e.js index de5ed76474..82c2456d25 100644 --- a/packages/auth/e2e/phone.e2e.js +++ b/packages/auth/e2e/phone.e2e.js @@ -11,22 +11,32 @@ describe('auth() => Phone', function () { describe('firebase v8 compatibility', function () { before(async function () { + const { getApp } = modular; + const { getAuth } = authModular; try { await clearAllUsers(); } catch (e) { throw e; } - firebase.auth().settings.appVerificationDisabledForTesting = true; + getAuth(getApp()).settings.appVerificationDisabledForTesting = true; await Utils.sleep(50); }); - beforeEach(async function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + if (firebase.auth().currentUser) { await firebase.auth().signOut(); await Utils.sleep(50); } }); + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('signInWithPhoneNumber', function () { it('signs in with a valid code', async function () { const testPhone = getRandomPhoneNumber(); @@ -189,10 +199,9 @@ describe('auth() => Phone', function () { describe('modular', function () { before(async function () { + const { getApp } = modular; const { getAuth } = authModular; - - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); try { await clearAllUsers(); @@ -204,10 +213,9 @@ describe('auth() => Phone', function () { }); beforeEach(async function () { + const { getApp } = modular; const { getAuth, signOut } = authModular; - - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); if (defaultAuth.currentUser) { await signOut(defaultAuth); @@ -217,10 +225,10 @@ describe('auth() => Phone', function () { describe('signInWithPhoneNumber', function () { it('signs in with a valid code', async function () { + const { getApp } = modular; const { getAuth, signInWithPhoneNumber } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); const testPhone = getRandomPhoneNumber(); const confirmResult = await signInWithPhoneNumber(defaultAuth, testPhone); @@ -238,10 +246,10 @@ describe('auth() => Phone', function () { }); it('errors on invalid code', async function () { + const { getApp } = modular; const { getAuth, signInWithPhoneNumber } = authModular; - const defaultApp = firebase.app(); - const defaultAuth = getAuth(defaultApp); + const defaultAuth = getAuth(getApp()); const testPhone = getRandomPhoneNumber(); const confirmResult = await signInWithPhoneNumber(defaultAuth, testPhone); diff --git a/packages/auth/e2e/provider.e2e.js b/packages/auth/e2e/provider.e2e.js index 91f4ffbb78..fd7b325a29 100644 --- a/packages/auth/e2e/provider.e2e.js +++ b/packages/auth/e2e/provider.e2e.js @@ -1,12 +1,20 @@ describe('auth() -> Providers', function () { describe('firebase v8 compatibility', function () { - beforeEach(async function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + if (firebase.auth().currentUser) { await firebase.auth().signOut(); await Utils.sleep(50); } }); + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('EmailAuthProvider', function () { describe('constructor', function () { it('should throw an unsupported error', function () { @@ -263,9 +271,10 @@ describe('auth() -> Providers', function () { describe('modular', function () { beforeEach(async function () { + const { getApp } = modular; const { signOut, getAuth } = authModular; - const defaultApp = firebase.app(); + const defaultApp = getApp(); const defaultAuth = getAuth(defaultApp); if (defaultAuth.currentUser) { diff --git a/packages/auth/e2e/user.e2e.js b/packages/auth/e2e/user.e2e.js index 0e6c1bd3a3..35eeeb13d0 100644 --- a/packages/auth/e2e/user.e2e.js +++ b/packages/auth/e2e/user.e2e.js @@ -12,26 +12,27 @@ const { describe('auth().currentUser', function () { describe('firebase v8 compatibility', function () { before(async function () { - try { - await clearAllUsers(); - } catch (e) { - throw e; - } - firebase.auth().settings.appVerificationDisabledForTesting = true; - try { - await firebase.auth().createUserWithEmailAndPassword(TEST_EMAIL, TEST_PASS); - } catch (_) { - // they may already exist, that's fine - } + const { getAuth, createUserWithEmailAndPassword } = authModular; + await clearAllUsers(); + getAuth().settings.appVerificationDisabledForTesting = true; + await createUserWithEmailAndPassword(getAuth(), TEST_EMAIL, TEST_PASS); }); - beforeEach(async function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + if (firebase.auth().currentUser) { await firebase.auth().signOut(); await Utils.sleep(50); } }); + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('getIdToken()', function () { it('should return a token', async function () { const random = Utils.randString(12, '#aA'); diff --git a/packages/auth/lib/modular/index.js b/packages/auth/lib/modular/index.js index ff53849f8e..346f735940 100644 --- a/packages/auth/lib/modular/index.js +++ b/packages/auth/lib/modular/index.js @@ -19,6 +19,7 @@ import { getApp } from '@react-native-firebase/app'; import { fetchPasswordPolicy } from '../password-policy/passwordPolicyApi'; import { PasswordPolicyImpl } from '../password-policy/PasswordPolicyImpl'; import FacebookAuthProvider from '../providers/FacebookAuthProvider'; +import { MultiFactorUser } from '../multiFactor'; export { FacebookAuthProvider }; /** @@ -462,7 +463,7 @@ export async function linkWithRedirect(user, provider, resolver) { * @returns {MultiFactorUser} */ export function multiFactor(user) { - return user._auth.multiFactor(user); + return new MultiFactorUser(getAuth(), user); } /** diff --git a/packages/database/e2e/DatabaseStatics.e2e.js b/packages/database/e2e/DatabaseStatics.e2e.js index 85efe31ddb..f1f2aba603 100644 --- a/packages/database/e2e/DatabaseStatics.e2e.js +++ b/packages/database/e2e/DatabaseStatics.e2e.js @@ -21,6 +21,16 @@ const TEST_PATH = `${PATH}/statics`; describe('database.X', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + after(function () { return wipe(TEST_PATH); }); diff --git a/packages/database/e2e/database.e2e.js b/packages/database/e2e/database.e2e.js index 81e69ef0ae..9209410449 100644 --- a/packages/database/e2e/database.e2e.js +++ b/packages/database/e2e/database.e2e.js @@ -17,6 +17,16 @@ describe('database()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('namespace', function () { it('accessible from firebase.app()', function () { const app = firebase.app(); @@ -204,24 +214,22 @@ describe('database()', function () { describe('modular', function () { describe('namespace', function () { it('accessible from getDatabase', function () { + const { getApp } = modular; const { getDatabase } = databaseModular; - const app = firebase.app(); - const database = getDatabase(app); - should.exist(app.database); - database.app.should.eql(app); + const database = getDatabase(getApp()); + database.app.should.eql(getApp()); }); it('supports multiple apps', async function () { + const { getApp } = modular; const { getDatabase } = databaseModular; const database = getDatabase(); - const secondaryDatabase = getDatabase(firebase.app('secondaryFromNative')); + const secondaryDatabase = getDatabase(getApp('secondaryFromNative')); database.app.name.should.eql('[DEFAULT]'); secondaryDatabase.app.name.should.eql('secondaryFromNative'); - - firebase.app('secondaryFromNative').database().app.name.should.eql('secondaryFromNative'); }); }); diff --git a/packages/database/e2e/helpers.js b/packages/database/e2e/helpers.js index 7aee880498..d93c769a28 100644 --- a/packages/database/e2e/helpers.js +++ b/packages/database/e2e/helpers.js @@ -52,9 +52,10 @@ const CONTENT = { }; exports.seed = function seed(path) { + const { getDatabase, ref } = databaseModular; return Promise.all([ - firebase.database().ref(`${path}/types`).set(CONTENT.TYPES), - firebase.database().ref(`${path}/query`).set(CONTENT.QUERY), + ref(getDatabase(), `${path}/types`).set(CONTENT.TYPES), + ref(getDatabase(), `${path}/query`).set(CONTENT.QUERY), // The database emulator does not load rules correctly. We force them pre-test. // TODO(ehesp): This is current erroring - however without it, we can't test rules. testingUtils.initializeTestEnvironment({ @@ -70,7 +71,8 @@ exports.seed = function seed(path) { }; exports.wipe = function wipe(path) { - return firebase.database().ref(path).remove(); + const { getDatabase, ref } = databaseModular; + return ref(getDatabase(), path).remove(); }; exports.PATH = PATH; diff --git a/packages/database/e2e/internal/connected.e2e.js b/packages/database/e2e/internal/connected.e2e.js index 86faa1183a..e8e6d75950 100644 --- a/packages/database/e2e/internal/connected.e2e.js +++ b/packages/database/e2e/internal/connected.e2e.js @@ -19,13 +19,19 @@ const { PATH } = require('../helpers'); const TEST_PATH = `${PATH}/connected`; describe("database().ref('.info/connected')", function () { - before(async function () { - await firebase.database().goOnline(); - }); - describe('v8 compatibility', function () { - after(async function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + await firebase.database().goOnline(); + }); + + afterEach(async function afterEachTest() { + // Ensures the db is online before running each test await firebase.database().goOnline(); + + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; }); xit('returns true when used with once', async function () { @@ -61,6 +67,12 @@ describe("database().ref('.info/connected')", function () { }); describe('modular', function () { + before(async function () { + const { getDatabase, goOnline } = databaseModular; + + await goOnline(getDatabase()); + }); + after(async function () { const { getDatabase, goOnline } = databaseModular; diff --git a/packages/database/e2e/internal/serverTimeOffset.e2e.js b/packages/database/e2e/internal/serverTimeOffset.e2e.js index 32954fe28f..3df68341a6 100644 --- a/packages/database/e2e/internal/serverTimeOffset.e2e.js +++ b/packages/database/e2e/internal/serverTimeOffset.e2e.js @@ -17,6 +17,16 @@ describe("database().ref('.info/serverTimeOffset')", function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('returns a valid number value', async function () { const snapshot = await firebase.database().ref('.info/serverTimeOffset').once('value'); diff --git a/packages/database/e2e/issues.e2e.js b/packages/database/e2e/issues.e2e.js index a82a9543fe..2142dbe751 100644 --- a/packages/database/e2e/issues.e2e.js +++ b/packages/database/e2e/issues.e2e.js @@ -29,6 +29,16 @@ describe('database issues', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + // FIXME requires a second database set up locally, full app initialization etc xit('#2813 should return a null snapshot key if path is root', async function () { firebase.database('https://react-native-firebase-testing-db2.firebaseio.com'); diff --git a/packages/database/e2e/onDisconnect/cancel.e2e.js b/packages/database/e2e/onDisconnect/cancel.e2e.js index bcde6b2d7d..365c3c4650 100644 --- a/packages/database/e2e/onDisconnect/cancel.e2e.js +++ b/packages/database/e2e/onDisconnect/cancel.e2e.js @@ -25,9 +25,17 @@ describe('database().ref().onDisconnect().cancel()', function () { }); describe('v8 compatibility', function () { - afterEach(async function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { // Ensures the db is online before running each test await firebase.database().goOnline(); + + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; }); it('throws if onComplete is not a function', function () { diff --git a/packages/database/e2e/onDisconnect/remove.e2e.js b/packages/database/e2e/onDisconnect/remove.e2e.js index 93963abb48..31727d7858 100644 --- a/packages/database/e2e/onDisconnect/remove.e2e.js +++ b/packages/database/e2e/onDisconnect/remove.e2e.js @@ -25,9 +25,17 @@ describe('database().ref().onDisconnect().remove()', function () { }); describe('v8 compatibility', function () { - afterEach(async function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { // Ensures the db is online before running each test await firebase.database().goOnline(); + + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; }); it('throws if onComplete is not a function', function () { diff --git a/packages/database/e2e/onDisconnect/set.e2e.js b/packages/database/e2e/onDisconnect/set.e2e.js index ce5cc1d488..26978f0b43 100644 --- a/packages/database/e2e/onDisconnect/set.e2e.js +++ b/packages/database/e2e/onDisconnect/set.e2e.js @@ -25,9 +25,17 @@ describe('database().ref().onDisconnect().set()', function () { }); describe('v8 compatibility', function () { - afterEach(async function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { // Ensures the db is online before running each test await firebase.database().goOnline(); + + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; }); it('throws if value is not a defined', function () { diff --git a/packages/database/e2e/onDisconnect/setWithPriority.e2e.js b/packages/database/e2e/onDisconnect/setWithPriority.e2e.js index ffb8f9d3d3..85d170e57a 100644 --- a/packages/database/e2e/onDisconnect/setWithPriority.e2e.js +++ b/packages/database/e2e/onDisconnect/setWithPriority.e2e.js @@ -25,9 +25,17 @@ describe('database().ref().onDisconnect().setWithPriority()', function () { }); describe('v8 compatibility', function () { - afterEach(async function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { // Ensures the db is online before running each test await firebase.database().goOnline(); + + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; }); it('throws if value is not a defined', function () { diff --git a/packages/database/e2e/onDisconnect/update.e2e.js b/packages/database/e2e/onDisconnect/update.e2e.js index aea53e7526..08b2b36464 100644 --- a/packages/database/e2e/onDisconnect/update.e2e.js +++ b/packages/database/e2e/onDisconnect/update.e2e.js @@ -25,9 +25,17 @@ describe('database().ref().onDisconnect().update()', function () { }); describe('v8 compatibility', function () { - afterEach(async function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { // Ensures the db is online before running each test await firebase.database().goOnline(); + + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; }); it('throws if values is not an object', async function () { diff --git a/packages/database/e2e/query/endAt.e2e.js b/packages/database/e2e/query/endAt.e2e.js index baa9e9d81e..9dac730148 100644 --- a/packages/database/e2e/query/endAt.e2e.js +++ b/packages/database/e2e/query/endAt.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().endAt()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if an value is undefined', async function () { try { await firebase.database().ref().endAt(); diff --git a/packages/database/e2e/query/equalTo.e2e.js b/packages/database/e2e/query/equalTo.e2e.js index fd0de626f1..da25cfb037 100644 --- a/packages/database/e2e/query/equalTo.e2e.js +++ b/packages/database/e2e/query/equalTo.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().equalTo()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if value is not a valid type', async function () { try { await firebase.database().ref().equalTo({ foo: 'bar' }); diff --git a/packages/database/e2e/query/isEqual.e2e.js b/packages/database/e2e/query/isEqual.e2e.js index 199d9093ff..932ff5997a 100644 --- a/packages/database/e2e/query/isEqual.e2e.js +++ b/packages/database/e2e/query/isEqual.e2e.js @@ -16,6 +16,16 @@ */ describe('database().ref().isEqual()', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if limit other param is not a query instance', async function () { try { await firebase.database().ref().isEqual('foo'); diff --git a/packages/database/e2e/query/keepSynced.e2e.js b/packages/database/e2e/query/keepSynced.e2e.js index 7873021a7f..ab6fc232bb 100644 --- a/packages/database/e2e/query/keepSynced.e2e.js +++ b/packages/database/e2e/query/keepSynced.e2e.js @@ -17,6 +17,16 @@ describe('database().ref().keepSynced()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if bool is not a valid type', async function () { try { await firebase.database().ref().keepSynced('foo'); diff --git a/packages/database/e2e/query/limitToFirst.e2e.js b/packages/database/e2e/query/limitToFirst.e2e.js index 6294d2c455..c308c0c957 100644 --- a/packages/database/e2e/query/limitToFirst.e2e.js +++ b/packages/database/e2e/query/limitToFirst.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().limitToFirst()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if limit is invalid', async function () { try { await firebase.database().ref().limitToFirst('foo'); diff --git a/packages/database/e2e/query/limitToLast.e2e.js b/packages/database/e2e/query/limitToLast.e2e.js index 61b0929863..72550f4e75 100644 --- a/packages/database/e2e/query/limitToLast.e2e.js +++ b/packages/database/e2e/query/limitToLast.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().limitToLast()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if limit is invalid', async function () { try { await firebase.database().ref().limitToLast('foo'); diff --git a/packages/database/e2e/query/on.e2e.js b/packages/database/e2e/query/on.e2e.js index 890c36a5b7..105259986a 100644 --- a/packages/database/e2e/query/on.e2e.js +++ b/packages/database/e2e/query/on.e2e.js @@ -28,6 +28,16 @@ describe('database().ref().on()', function () { await wipe(TEST_PATH); }); + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if event type is invalid', async function () { try { await firebase.database().ref().on('foo'); diff --git a/packages/database/e2e/query/once.e2e.js b/packages/database/e2e/query/once.e2e.js index d6280c355c..697f4728b0 100644 --- a/packages/database/e2e/query/once.e2e.js +++ b/packages/database/e2e/query/once.e2e.js @@ -28,6 +28,16 @@ describe('database().ref().once()', function () { return wipe(TEST_PATH); }); + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if event type is invalid', async function () { try { await firebase.database().ref().once('foo'); diff --git a/packages/database/e2e/query/orderByChild.e2e.js b/packages/database/e2e/query/orderByChild.e2e.js index 9e7fbc9c72..b7114c53f3 100644 --- a/packages/database/e2e/query/orderByChild.e2e.js +++ b/packages/database/e2e/query/orderByChild.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().orderByChild()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if path is not a string value', async function () { try { await firebase.database().ref().orderByChild({ foo: 'bar' }); diff --git a/packages/database/e2e/query/orderByKey.e2e.js b/packages/database/e2e/query/orderByKey.e2e.js index 29fdd919c8..91e361f5f3 100644 --- a/packages/database/e2e/query/orderByKey.e2e.js +++ b/packages/database/e2e/query/orderByKey.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().orderByKey()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if an orderBy call has already been set', async function () { try { await firebase.database().ref().orderByChild('foo').orderByKey(); diff --git a/packages/database/e2e/query/orderByPriority.e2e.js b/packages/database/e2e/query/orderByPriority.e2e.js index b4c5485fc5..4a02479b66 100644 --- a/packages/database/e2e/query/orderByPriority.e2e.js +++ b/packages/database/e2e/query/orderByPriority.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().orderByPriority()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if an orderBy call has already been set', async function () { try { await firebase.database().ref().orderByChild('foo').orderByPriority(); diff --git a/packages/database/e2e/query/orderByValue.e2e.js b/packages/database/e2e/query/orderByValue.e2e.js index 50e51c331a..c4708c4b84 100644 --- a/packages/database/e2e/query/orderByValue.e2e.js +++ b/packages/database/e2e/query/orderByValue.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().orderByValue()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if an orderBy call has already been set', async function () { try { await firebase.database().ref().orderByChild('foo').orderByValue(); diff --git a/packages/database/e2e/query/query.e2e.js b/packages/database/e2e/query/query.e2e.js index c252a16eda..03272ff36d 100644 --- a/packages/database/e2e/query/query.e2e.js +++ b/packages/database/e2e/query/query.e2e.js @@ -16,6 +16,16 @@ describe('DatabaseQuery/DatabaseQueryModifiers', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('should not mutate previous queries (#2691)', async function () { const queryBefore = firebase.database().ref(); queryBefore._modifiers._modifiers.length.should.equal(0); diff --git a/packages/database/e2e/query/startAt.e2e.js b/packages/database/e2e/query/startAt.e2e.js index b1eb0bb64c..bce383bb14 100644 --- a/packages/database/e2e/query/startAt.e2e.js +++ b/packages/database/e2e/query/startAt.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().startAt()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if an value is undefined', async function () { try { await firebase.database().ref().startAt(); diff --git a/packages/database/e2e/query/toJSON.e2e.js b/packages/database/e2e/query/toJSON.e2e.js index 3efb80cae8..d7ccc9e511 100644 --- a/packages/database/e2e/query/toJSON.e2e.js +++ b/packages/database/e2e/query/toJSON.e2e.js @@ -17,6 +17,16 @@ describe('database().ref().toJSON()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('returns a string version of the current query path', async function () { const res = firebase.database().ref('foo/bar/baz').toJSON(); const expected = `${firebase.database()._customUrlOrRegion}/foo/bar/baz`; diff --git a/packages/database/e2e/reference/child.e2e.js b/packages/database/e2e/reference/child.e2e.js index d729dbc862..1c6bcf546f 100644 --- a/packages/database/e2e/reference/child.e2e.js +++ b/packages/database/e2e/reference/child.e2e.js @@ -17,6 +17,16 @@ describe('database().ref().child()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if path is not a string', async function () { try { firebase.database().ref().child({ foo: 'bar' }); diff --git a/packages/database/e2e/reference/key.e2e.js b/packages/database/e2e/reference/key.e2e.js index 0ed277b6ee..33846bc67b 100644 --- a/packages/database/e2e/reference/key.e2e.js +++ b/packages/database/e2e/reference/key.e2e.js @@ -17,6 +17,16 @@ describe('database().ref().key', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('returns null when no reference path is provides', function () { const ref = firebase.database().ref(); should.equal(ref.key, null); diff --git a/packages/database/e2e/reference/onDisconnect.e2e.js b/packages/database/e2e/reference/onDisconnect.e2e.js index 8540faf7c4..5263212090 100644 --- a/packages/database/e2e/reference/onDisconnect.e2e.js +++ b/packages/database/e2e/reference/onDisconnect.e2e.js @@ -19,6 +19,16 @@ describe('database().ref().onDisconnect()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('returns a new DatabaseOnDisconnect instance', function () { const instance = firebase.database().ref().onDisconnect(); instance.constructor.name.should.eql('DatabaseOnDisconnect'); diff --git a/packages/database/e2e/reference/parent.e2e.js b/packages/database/e2e/reference/parent.e2e.js index 7dec1d8799..a0f6570aa1 100644 --- a/packages/database/e2e/reference/parent.e2e.js +++ b/packages/database/e2e/reference/parent.e2e.js @@ -17,6 +17,16 @@ describe('database().ref().parent', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('returns null when no reference path is provides', function () { const ref = firebase.database().ref(); should.equal(ref.parent, null); diff --git a/packages/database/e2e/reference/push.e2e.js b/packages/database/e2e/reference/push.e2e.js index 5dc0d73d68..c479a08543 100644 --- a/packages/database/e2e/reference/push.e2e.js +++ b/packages/database/e2e/reference/push.e2e.js @@ -21,6 +21,16 @@ const TEST_PATH = `${PATH}/push`; describe('database().ref().push()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if on complete callback is not a function', function () { try { firebase.database().ref(TEST_PATH).push('foo', 'bar'); diff --git a/packages/database/e2e/reference/remove.e2e.js b/packages/database/e2e/reference/remove.e2e.js index 4fa18e76a2..a0d0919651 100644 --- a/packages/database/e2e/reference/remove.e2e.js +++ b/packages/database/e2e/reference/remove.e2e.js @@ -21,6 +21,16 @@ const TEST_PATH = `${PATH}/remove`; describe('database().ref().remove()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if onComplete is not a function', async function () { try { await firebase.database().ref(TEST_PATH).remove('foo'); diff --git a/packages/database/e2e/reference/root.e2e.js b/packages/database/e2e/reference/root.e2e.js index 227076830c..43c1d5f93b 100644 --- a/packages/database/e2e/reference/root.e2e.js +++ b/packages/database/e2e/reference/root.e2e.js @@ -17,6 +17,16 @@ describe('database().ref().root', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('returns a root reference', function () { const ref = firebase.database().ref('foo/bar/baz'); should.equal(ref.root.key, null); diff --git a/packages/database/e2e/reference/set.e2e.js b/packages/database/e2e/reference/set.e2e.js index 3611261073..06da9cea96 100644 --- a/packages/database/e2e/reference/set.e2e.js +++ b/packages/database/e2e/reference/set.e2e.js @@ -29,6 +29,16 @@ describe('set', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if no value is provided', async function () { try { await firebase.database().ref(TEST_PATH).set(); diff --git a/packages/database/e2e/reference/setPriority.e2e.js b/packages/database/e2e/reference/setPriority.e2e.js index 616ca3c4ff..8f92153a23 100644 --- a/packages/database/e2e/reference/setPriority.e2e.js +++ b/packages/database/e2e/reference/setPriority.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().setPriority()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if priority is not a valid type', async function () { try { await firebase.database().ref().setPriority({}); diff --git a/packages/database/e2e/reference/setWithPriority.e2e.js b/packages/database/e2e/reference/setWithPriority.e2e.js index 7d357e4aae..bc70af2de8 100644 --- a/packages/database/e2e/reference/setWithPriority.e2e.js +++ b/packages/database/e2e/reference/setWithPriority.e2e.js @@ -29,6 +29,16 @@ describe('database().ref().setWithPriority()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if newVal is not defined', async function () { try { await firebase.database().ref().setWithPriority(); diff --git a/packages/database/e2e/reference/transaction.e2e.js b/packages/database/e2e/reference/transaction.e2e.js index 3c38e4d6a2..256a5d4985 100644 --- a/packages/database/e2e/reference/transaction.e2e.js +++ b/packages/database/e2e/reference/transaction.e2e.js @@ -30,6 +30,16 @@ describe('database().ref().transaction()', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if no transactionUpdate is provided', async function () { try { await firebase.database().ref(TEST_PATH).transaction(); diff --git a/packages/database/e2e/reference/update.e2e.js b/packages/database/e2e/reference/update.e2e.js index f18e1fc936..72a0302dfc 100644 --- a/packages/database/e2e/reference/update.e2e.js +++ b/packages/database/e2e/reference/update.e2e.js @@ -21,10 +21,21 @@ const TEST_PATH = `${PATH}/update`; describe('database().ref().update()', function () { after(async function () { - await firebase.database().ref(TEST_PATH).remove(); + const { getDatabase, ref } = databaseModular; + await ref(getDatabase(), TEST_PATH).remove(); }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if values is not an object', async function () { try { await firebase.database().ref(TEST_PATH).update('foo'); diff --git a/packages/database/e2e/snapshot/snapshot.e2e.js b/packages/database/e2e/snapshot/snapshot.e2e.js index 9a3bd0633a..c35220be3f 100644 --- a/packages/database/e2e/snapshot/snapshot.e2e.js +++ b/packages/database/e2e/snapshot/snapshot.e2e.js @@ -29,6 +29,16 @@ describe('database()...snapshot', function () { }); describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('returns the snapshot key', async function () { const snapshot = await firebase .database() diff --git a/packages/dynamic-links/e2e/builder.analytics.e2e.js b/packages/dynamic-links/e2e/builder.analytics.e2e.js index 4500bb8ebb..68f794d687 100644 --- a/packages/dynamic-links/e2e/builder.analytics.e2e.js +++ b/packages/dynamic-links/e2e/builder.analytics.e2e.js @@ -19,6 +19,16 @@ const { baseParams } = require('./dynamicLinks.e2e'); describe('dynamicLinks() dynamicLinkParams.analytics', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if analytics is not an object', function () { try { firebase.dynamicLinks().buildLink({ diff --git a/packages/dynamic-links/e2e/builder.android.e2e.js b/packages/dynamic-links/e2e/builder.android.e2e.js index 09ed536272..c974f0016d 100644 --- a/packages/dynamic-links/e2e/builder.android.e2e.js +++ b/packages/dynamic-links/e2e/builder.android.e2e.js @@ -19,6 +19,16 @@ const { baseParams } = require('./dynamicLinks.e2e'); describe('dynamicLinks() dynamicLinkParams.android', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if android is not an object', function () { try { firebase.dynamicLinks().buildLink({ diff --git a/packages/dynamic-links/e2e/builder.e2e.js b/packages/dynamic-links/e2e/builder.e2e.js index 7c40d79c8e..64b05dc101 100644 --- a/packages/dynamic-links/e2e/builder.e2e.js +++ b/packages/dynamic-links/e2e/builder.e2e.js @@ -17,6 +17,16 @@ describe('dynamicLinks() dynamicLinkParams', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if params are not an object', function () { try { firebase.dynamicLinks().buildLink(123); diff --git a/packages/dynamic-links/e2e/builder.ios.e2e.js b/packages/dynamic-links/e2e/builder.ios.e2e.js index 311fb7614d..b03d62e898 100644 --- a/packages/dynamic-links/e2e/builder.ios.e2e.js +++ b/packages/dynamic-links/e2e/builder.ios.e2e.js @@ -19,6 +19,16 @@ const { baseParams } = require('./dynamicLinks.e2e'); describe('dynamicLinks() dynamicLinkParams.ios', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if ios is not an object', function () { try { firebase.dynamicLinks().buildLink({ diff --git a/packages/dynamic-links/e2e/builder.itunes.e2e.js b/packages/dynamic-links/e2e/builder.itunes.e2e.js index 302345966c..751fc25300 100644 --- a/packages/dynamic-links/e2e/builder.itunes.e2e.js +++ b/packages/dynamic-links/e2e/builder.itunes.e2e.js @@ -19,6 +19,16 @@ const { baseParams } = require('./dynamicLinks.e2e'); describe('dynamicLinks() dynamicLinkParams.itunes', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if itunes is not an object', function () { try { firebase.dynamicLinks().buildLink({ diff --git a/packages/dynamic-links/e2e/builder.navigation.e2e.js b/packages/dynamic-links/e2e/builder.navigation.e2e.js index cc3ca8394c..e1d99141c4 100644 --- a/packages/dynamic-links/e2e/builder.navigation.e2e.js +++ b/packages/dynamic-links/e2e/builder.navigation.e2e.js @@ -19,6 +19,16 @@ const { baseParams } = require('./dynamicLinks.e2e'); describe('dynamicLinks() dynamicLinkParams.navigation', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if navigation is not an object', function () { try { firebase.dynamicLinks().buildLink({ diff --git a/packages/dynamic-links/e2e/builder.otherplatform.e2e.js b/packages/dynamic-links/e2e/builder.otherplatform.e2e.js index 44f83805c6..9ab10ee150 100644 --- a/packages/dynamic-links/e2e/builder.otherplatform.e2e.js +++ b/packages/dynamic-links/e2e/builder.otherplatform.e2e.js @@ -2,6 +2,16 @@ const { baseParams } = require('./dynamicLinks.e2e'); describe('dynamicLinks() dynamicLinkParams.otherPlatform', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if otherPlatform is not an object', function () { try { firebase.dynamicLinks().buildLink({ diff --git a/packages/dynamic-links/e2e/builder.social.e2e.js b/packages/dynamic-links/e2e/builder.social.e2e.js index dfce11bd01..5b46d9ebbe 100644 --- a/packages/dynamic-links/e2e/builder.social.e2e.js +++ b/packages/dynamic-links/e2e/builder.social.e2e.js @@ -19,6 +19,16 @@ const { baseParams } = require('./dynamicLinks.e2e'); describe('dynamicLinks() dynamicLinkParams.social', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + it('throws if social is not an object', function () { try { firebase.dynamicLinks().buildLink({ diff --git a/packages/dynamic-links/e2e/dynamicLinks.e2e.js b/packages/dynamic-links/e2e/dynamicLinks.e2e.js index 4b7091d61f..5c90306d06 100644 --- a/packages/dynamic-links/e2e/dynamicLinks.e2e.js +++ b/packages/dynamic-links/e2e/dynamicLinks.e2e.js @@ -61,6 +61,16 @@ module.exports.baseParams = baseParams; describe('dynamicLinks()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('namespace', function () { it('accessible from firebase.app()', function () { const app = firebase.app(); diff --git a/packages/functions/e2e/functions.e2e.js b/packages/functions/e2e/functions.e2e.js index 73aefe5431..ccc15faf97 100644 --- a/packages/functions/e2e/functions.e2e.js +++ b/packages/functions/e2e/functions.e2e.js @@ -90,6 +90,16 @@ const SAMPLE_DATA = { describe('functions() modular', function () { describe('firebase v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('namespace', function () { it('accepts passing in an FirebaseApp instance as first arg', async function () { const appName = `functionsApp${FirebaseHelpers.id}2`; @@ -407,27 +417,25 @@ describe('functions() modular', function () { describe('modular', function () { describe('getFunctions', function () { it('pass app as argument', function () { + const { getApp } = modular; const { getFunctions } = functionsModular; - - const functions = getFunctions(firebase.app()); - + const functions = getFunctions(getApp()); functions.constructor.name.should.be.equal('FirebaseFunctionsModule'); }); it('no app as argument', function () { const { getFunctions } = functionsModular; - const functions = getFunctions(); - functions.constructor.name.should.be.equal('FirebaseFunctionsModule'); }); }); it('accepts passing in an FirebaseApp instance as first arg', async function () { + const { initializeApp } = modular; const { getFunctions } = functionsModular; const appName = `functionsApp${FirebaseHelpers.id}3`; const platformAppConfig = FirebaseHelpers.app.config(); - const app = await firebase.initializeApp(platformAppConfig, appName); + const app = await initializeApp(platformAppConfig, appName); const functions = getFunctions(app); functions.app.should.equal(app); @@ -439,18 +447,19 @@ describe('functions() modular', function () { }); it('accepts passing in a region string as first arg to an app', async function () { + const { getApp } = modular; const { getFunctions } = functionsModular; const region = 'europe-west1'; - const functionsForRegion = getFunctions(firebase.app(), region); + const functionsForRegion = getFunctions(getApp(), region); functionsForRegion._customUrlOrRegion.should.equal(region); - functionsForRegion.app.should.equal(firebase.app()); - functionsForRegion.app.name.should.equal(firebase.app().name); + functionsForRegion.app.should.equal(getApp()); + functionsForRegion.app.name.should.equal(getApp().name); - firebase.app().functions(region).app.should.equal(firebase.app()); + getApp().functions(region).app.should.equal(getApp()); - firebase.app().functions(region)._customUrlOrRegion.should.equal(region); + getApp().functions(region)._customUrlOrRegion.should.equal(region); const functionRunner = functionsForRegion.httpsCallable('testFunctionCustomRegion'); @@ -459,16 +468,17 @@ describe('functions() modular', function () { }); it('accepts passing in a custom url string as first arg to an app', async function () { + const { getApp } = modular; const { getFunctions } = functionsModular; const customUrl = 'https://us-central1-react-native-firebase-testing.cloudfunctions.net'; - const functionsForCustomUrl = getFunctions(firebase.app(), customUrl); + const functionsForCustomUrl = getFunctions(getApp(), customUrl); functionsForCustomUrl._customUrlOrRegion.should.equal(customUrl); - functionsForCustomUrl.app.should.equal(firebase.app()); - functionsForCustomUrl.app.name.should.equal(firebase.app().name); + functionsForCustomUrl.app.should.equal(getApp()); + functionsForCustomUrl.app.name.should.equal(getApp().name); - functionsForCustomUrl.app.should.equal(firebase.app()); + functionsForCustomUrl.app.should.equal(getApp()); functionsForCustomUrl._customUrlOrRegion.should.equal(customUrl); @@ -480,21 +490,23 @@ describe('functions() modular', function () { describe('emulator', function () { it('configures functions emulator via deprecated method with no port', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable, connectFunctionsEmulator } = functionsModular; const region = 'us-central1'; const fnName = 'helloWorldV2'; // const functions = firebase.app().functions(region); - const functions = getFunctions(firebase.app(), region); + const functions = getFunctions(getApp(), region); connectFunctionsEmulator(functions, 'localhost', 5001); const response = await httpsCallable(functions, fnName)(); response.data.should.equal('Hello from Firebase!'); }); it('configures functions emulator via deprecated method with port', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable, connectFunctionsEmulator } = functionsModular; const region = 'us-central1'; const fnName = 'helloWorldV2'; - const functions = getFunctions(firebase.app(), region); + const functions = getFunctions(getApp(), region); connectFunctionsEmulator(functions, 'localhost', 5001); const response = await httpsCallable(functions, fnName)(); response.data.should.equal('Hello from Firebase!'); @@ -503,13 +515,14 @@ describe('functions() modular', function () { describe('httpsCallableFromUrl()', function () { it('Calls a function by URL', async function () { + const { getApp } = modular; const { getFunctions, httpsCallableFromUrl } = functionsModular; let hostname = 'localhost'; if (Platform.android) { hostname = '10.0.2.2'; } - const functions = getFunctions(firebase.app()); + const functions = getFunctions(getApp()); const functionRunner = httpsCallableFromUrl( functions, `http://${hostname}:5001/react-native-firebase-testing/us-central1/helloWorldV2`, @@ -521,73 +534,59 @@ describe('functions() modular', function () { describe('httpsCallable(fnName)(args)', function () { it('accepts primitive args: undefined', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); const response = await functionRunner(); response.data.should.equal('null'); }); it('accepts primitive args: string', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); const response = await functionRunner('hello'); response.data.should.equal('string'); }); it('accepts primitive args: number', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); const response = await functionRunner(123); response.data.should.equal('number'); }); it('accepts primitive args: boolean', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); const response = await functionRunner(true); response.data.should.equal('boolean'); }); it('accepts primitive args: null', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); const response = await functionRunner(null); response.data.should.equal('null'); }); it('accepts array args', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); const response = await functionRunner([1, 2, 3, 4]); response.data.should.equal('array'); }); it('accepts object args', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; const type = 'object'; const inputData = SAMPLE_DATA[type]; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); const { data: outputData } = await functionRunner({ type, inputData, @@ -596,13 +595,11 @@ describe('functions() modular', function () { }); it('accepts complex nested objects', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; const type = 'deepObject'; const inputData = SAMPLE_DATA[type]; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); const { data: outputData } = await functionRunner({ type, inputData, @@ -611,13 +608,11 @@ describe('functions() modular', function () { }); it('accepts complex nested arrays', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; const type = 'deepArray'; const inputData = SAMPLE_DATA[type]; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); const { data: outputData } = await functionRunner({ type, inputData, @@ -628,11 +623,9 @@ describe('functions() modular', function () { describe('HttpsError', function () { it('errors return instance of HttpsError', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); try { await functionRunner({}); @@ -649,11 +642,9 @@ describe('functions() modular', function () { it('HttpsError.details -> allows returning complex data', async function () { let type = 'deepObject'; let inputData = SAMPLE_DATA[type]; + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); try { await functionRunner({ type, @@ -690,13 +681,11 @@ describe('functions() modular', function () { }); it('HttpsError.details -> allows returning primitives', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; let type = 'number'; let inputData = SAMPLE_DATA[type]; - const functionRunner = httpsCallable( - getFunctions(firebase.app()), - 'testFunctionDefaultRegionV2', - ); + const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2'); try { await functionRunner({ type, @@ -767,8 +756,9 @@ describe('functions() modular', function () { }); it('HttpsCallableOptions.timeout will error when timeout is exceeded', async function () { + const { getApp } = modular; const { getFunctions, httpsCallable } = functionsModular; - const functions = getFunctions(firebase.app()); + const functions = getFunctions(getApp()); const functionRunner = httpsCallable(functions, 'sleeperV2', { timeout: 1000 }); try { diff --git a/packages/installations/e2e/installations.e2e.js b/packages/installations/e2e/installations.e2e.js index 34f06196b8..5e37391011 100644 --- a/packages/installations/e2e/installations.e2e.js +++ b/packages/installations/e2e/installations.e2e.js @@ -62,6 +62,16 @@ const PROJECT_ID = 448618578101; // this is "magic", it's the react-native-fireb describe('installations() modular', function () { describe('firebase v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('getId()', function () { it('returns a valid installation id', async function () { const id = await firebase.installations().getId(); diff --git a/packages/ml/e2e/ml.e2e.js b/packages/ml/e2e/ml.e2e.js index ce9af7f8e3..f9b4152769 100644 --- a/packages/ml/e2e/ml.e2e.js +++ b/packages/ml/e2e/ml.e2e.js @@ -17,6 +17,16 @@ describe('ml()', function () { describe('v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('namespace', function () { it('accessible from firebase.app()', function () { const app = firebase.app(); @@ -38,9 +48,10 @@ describe('ml()', function () { describe('modular', function () { it('supports multiple apps', function () { + const { getApp } = modular; const { getML } = mlModular; const ml = getML(); - const secondaryML = getML(firebase.app('secondaryFromNative')); + const secondaryML = getML(getApp('secondaryFromNative')); ml.app.name.should.equal('[DEFAULT]'); diff --git a/packages/ml/lib/modular/index.js b/packages/ml/lib/modular/index.js index 169d1ef343..8000bc832d 100644 --- a/packages/ml/lib/modular/index.js +++ b/packages/ml/lib/modular/index.js @@ -11,7 +11,7 @@ import { getApp } from '@react-native-firebase/app'; */ export function getML(app) { if (app) { - return getApp(app).ml(); + return getApp(app.name).ml(); } return getApp().ml(); } diff --git a/packages/perf/e2e/HttpMetric.e2e.js b/packages/perf/e2e/HttpMetric.e2e.js index 8ed99aaa60..e2e27ab7a6 100644 --- a/packages/perf/e2e/HttpMetric.e2e.js +++ b/packages/perf/e2e/HttpMetric.e2e.js @@ -19,6 +19,16 @@ const aCoolUrl = 'https://invertase.io'; describe('HttpMetric modular', function () { describe('firebase v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('start()', function () { it('correctly starts with internal flag ', async function () { const httpMetric = firebase.perf().newHttpMetric(aCoolUrl, 'GET'); diff --git a/packages/perf/e2e/Trace.e2e.js b/packages/perf/e2e/Trace.e2e.js index 5b903592f7..c461d66f19 100644 --- a/packages/perf/e2e/Trace.e2e.js +++ b/packages/perf/e2e/Trace.e2e.js @@ -17,6 +17,16 @@ describe('Trace modular', function () { describe('firebase v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('start()', function () { it('correctly starts with internal flag ', async function () { const trace = firebase.perf().newTrace('invertase'); @@ -416,36 +426,31 @@ describe('Trace modular', function () { }); it('should return an attribute string value', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.putAttribute('inver', 'tase'); - const value = trace.getAttribute('inver'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putAttribute('inver', 'tase'); + const value = traceInvertase.getAttribute('inver'); should.equal(value, 'tase'); }); - - it('errors if attribute name is not a string', async function () { - try { - const trace = firebase.perf().newTrace('invertase'); - trace.getAttribute(1337); - return Promise.reject(new Error('Did not throw')); - } catch (e) { - e.message.should.containEql('must be a string'); - return Promise.resolve(); - } - }); }); describe('putAttribute()', function () { it('sets an attribute string value', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.putAttribute('inver', 'tase'); - const value = trace.getAttribute('inver'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putAttribute('inver', 'tase'); + const value = traceInvertase.getAttribute('inver'); value.should.equal('tase'); }); it('errors if attribute name is not a string', async function () { try { - const trace = firebase.perf().newTrace('invertase'); - trace.putAttribute(1337, 'invertase'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putAttribute(1337, 'invertase'); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('must be a string'); @@ -455,8 +460,10 @@ describe('Trace modular', function () { it('errors if attribute value is not a string', async function () { try { - const trace = firebase.perf().newTrace('invertase'); - trace.putAttribute('invertase', 1337); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putAttribute('invertase', 1337); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('must be a string'); @@ -466,8 +473,10 @@ describe('Trace modular', function () { it('errors if attribute name is greater than 40 characters', async function () { try { - const trace = firebase.perf().newTrace('invertase'); - trace.putAttribute(new Array(41).fill('1').join(''), 1337); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putAttribute(new Array(41).fill('1').join(''), 1337); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('a maximum length of 40 characters'); @@ -477,8 +486,10 @@ describe('Trace modular', function () { it('errors if attribute value is greater than 100 characters', async function () { try { - const trace = firebase.perf().newTrace('invertase'); - trace.putAttribute('invertase', new Array(101).fill('1').join('')); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putAttribute('invertase', new Array(101).fill('1').join('')); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('a maximum length of 100 characters'); @@ -487,14 +498,16 @@ describe('Trace modular', function () { }); it('errors if more than 5 attributes are put', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.putAttribute('invertase1', '1337'); - trace.putAttribute('invertase2', '1337'); - trace.putAttribute('invertase3', '1337'); - trace.putAttribute('invertase4', '1337'); - trace.putAttribute('invertase5', '1337'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putAttribute('invertase1', '1337'); + traceInvertase.putAttribute('invertase2', '1337'); + traceInvertase.putAttribute('invertase3', '1337'); + traceInvertase.putAttribute('invertase4', '1337'); + traceInvertase.putAttribute('invertase5', '1337'); try { - trace.putAttribute('invertase6', '1337'); + traceInvertase.putAttribute('invertase6', '1337'); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('maximum number of attributes'); @@ -515,10 +528,12 @@ describe('Trace modular', function () { describe('removeMetric()', function () { it('errors if name not a string', async function () { - const trace = firebase.perf().newTrace('invertase'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); try { - trace.putMetric('likes', 1337); - trace.removeMetric(13377331); + traceInvertase.putMetric('likes', 1337); + traceInvertase.removeMetric(13377331); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('must be a string'); @@ -527,34 +542,42 @@ describe('Trace modular', function () { }); it('removes a metric', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.putMetric('likes', 1337); - const value = trace.getMetric('likes'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putMetric('likes', 1337); + const value = traceInvertase.getMetric('likes'); should.equal(value, 1337); - trace.removeMetric('likes'); - const value2 = trace.getMetric('likes'); + traceInvertase.removeMetric('likes'); + const value2 = traceInvertase.getMetric('likes'); should.equal(value2, 0); }); }); describe('getMetric()', function () { it('should return 0 if metric does not exist', async function () { - const trace = firebase.perf().newTrace('invertase'); - const value = trace.getMetric('likes'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + const value = traceInvertase.getMetric('likes'); should.equal(value, 0); }); it('should return an metric number value', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.putMetric('likes', 7331); - const value = trace.getMetric('likes'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putMetric('likes', 7331); + const value = traceInvertase.getMetric('likes'); should.equal(value, 7331); }); it('errors if metric name is not a string', async function () { try { - const trace = firebase.perf().newTrace('invertase'); - trace.getMetric(1337); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.getMetric(1337); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('must be a string'); @@ -565,27 +588,33 @@ describe('Trace modular', function () { describe('putMetric()', function () { it('sets a metric number value', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.putMetric('likes', 9001); - const value = trace.getMetric('likes'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putMetric('likes', 9001); + const value = traceInvertase.getMetric('likes'); value.should.equal(9001); }); it('overwrites existing metric if it exists', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.putMetric('likes', 1); - trace.incrementMetric('likes', 9000); - const value = trace.getMetric('likes'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putMetric('likes', 1); + traceInvertase.incrementMetric('likes', 9000); + const value = traceInvertase.getMetric('likes'); value.should.equal(9001); - trace.putMetric('likes', 1); - const value2 = trace.getMetric('likes'); + traceInvertase.putMetric('likes', 1); + const value2 = traceInvertase.getMetric('likes'); value2.should.equal(1); }); it('errors if metric name is not a string', async function () { try { - const trace = firebase.perf().newTrace('invertase'); - trace.putMetric(1337, 7331); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putMetric(1337, 7331); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('must be a string'); @@ -595,8 +624,10 @@ describe('Trace modular', function () { it('errors if metric value is not a number', async function () { try { - const trace = firebase.perf().newTrace('invertase'); - trace.putMetric('likes', '1337'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putMetric('likes', '1337'); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('must be a number'); @@ -607,24 +638,30 @@ describe('Trace modular', function () { describe('incrementMetric()', function () { it('increments a metric number value', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.putMetric('likes', 9000); - trace.incrementMetric('likes', 1); - const value = trace.getMetric('likes'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putMetric('likes', 9000); + traceInvertase.incrementMetric('likes', 1); + const value = traceInvertase.getMetric('likes'); value.should.equal(9001); }); it('increments a metric even if it does not already exist', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.incrementMetric('likes', 9001); - const value = trace.getMetric('likes'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.incrementMetric('likes', 9001); + const value = traceInvertase.getMetric('likes'); value.should.equal(9001); }); it('errors if metric name is not a string', async function () { try { - const trace = firebase.perf().newTrace('invertase'); - trace.incrementMetric(1337, 1); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.incrementMetric(1337, 1); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('must be a string'); @@ -634,8 +671,10 @@ describe('Trace modular', function () { it('errors if incrementBy value is not a number', async function () { try { - const trace = firebase.perf().newTrace('invertase'); - trace.incrementMetric('likes', '1'); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.incrementMetric('likes', '1'); return Promise.reject(new Error('Did not throw')); } catch (e) { e.message.should.containEql('must be a number'); @@ -645,10 +684,12 @@ describe('Trace modular', function () { }); it('getMetrics()', async function () { - const trace = firebase.perf().newTrace('invertase'); - trace.putMetric('likes', 1337); - trace.putMetric('stars', 6832); - const value = trace.getMetrics(); + const { getPerformance, trace } = perfModular; + const perf = getPerformance(); + const traceInvertase = trace(perf, 'invertase'); + traceInvertase.putMetric('likes', 1337); + traceInvertase.putMetric('stars', 6832); + const value = traceInvertase.getMetrics(); JSON.parse(JSON.stringify(value)).should.deepEqual({ likes: 1337, stars: 6832, diff --git a/packages/perf/e2e/perf.e2e.js b/packages/perf/e2e/perf.e2e.js index ec560eefd0..2be866e014 100644 --- a/packages/perf/e2e/perf.e2e.js +++ b/packages/perf/e2e/perf.e2e.js @@ -17,6 +17,16 @@ describe('perf() modular', function () { describe('firebase v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('setPerformanceCollectionEnabled()', function () { // These depend on `tests/firebase.json` having `perf_auto_collection_enabled` set to false the first time // The setting is persisted across restarts, reset to false after for local runs where prefs are sticky @@ -119,9 +129,10 @@ describe('perf() modular', function () { describe('modular', function () { describe('getPerformance', function () { it('pass app as argument', function () { + const { getApp } = modular; const { getPerformance } = perfModular; - const perf = getPerformance(firebase.app()); + const perf = getPerformance(getApp()); perf.constructor.name.should.be.equal('FirebasePerfModule'); }); @@ -137,9 +148,10 @@ describe('perf() modular', function () { describe('initializePerformance()', function () { it('call and set "dataCollectionEnabled" to `false`', async function () { + const { getApp } = modular; const { initializePerformance } = perfModular; - const perf = await initializePerformance(firebase.app(), { dataCollectionEnabled: false }); + const perf = await initializePerformance(getApp(), { dataCollectionEnabled: false }); const enabled = perf.dataCollectionEnabled; @@ -147,9 +159,10 @@ describe('perf() modular', function () { }); it('call and set "dataCollectionEnabled" to `true`', async function () { + const { getApp } = modular; const { initializePerformance } = perfModular; - const perf = await initializePerformance(firebase.app(), { dataCollectionEnabled: true }); + const perf = await initializePerformance(getApp(), { dataCollectionEnabled: true }); const enabled = perf.dataCollectionEnabled; diff --git a/packages/remote-config/e2e/config.e2e.js b/packages/remote-config/e2e/config.e2e.js index edce1f95b2..b6532511d9 100644 --- a/packages/remote-config/e2e/config.e2e.js +++ b/packages/remote-config/e2e/config.e2e.js @@ -19,6 +19,16 @@ const { updateTemplate } = require('./helpers'); describe('remoteConfig()', function () { describe('firebase v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('fetch()', function () { it('with expiration provided', async function () { const date = Date.now() - 30000; @@ -349,17 +359,19 @@ describe('remoteConfig()', function () { describe('modular', function () { describe('getRemoteConfig', function () { it('pass app as argument', function () { + const { getApp } = modular; const { getRemoteConfig } = remoteConfigModular; - const remoteConfig = getRemoteConfig(firebase.app()); + const remoteConfig = getRemoteConfig(getApp()); remoteConfig.constructor.name.should.be.equal('FirebaseConfigModule'); }); it('no app as argument', function () { + const { getApp } = modular; const { getRemoteConfig } = remoteConfigModular; - const remoteConfig = getRemoteConfig(firebase.app()); + const remoteConfig = getRemoteConfig(getApp()); remoteConfig.constructor.name.should.be.equal('FirebaseConfigModule'); }); @@ -379,7 +391,7 @@ describe('remoteConfig()', function () { await fetch(remoteConfig, 0); remoteConfig.lastFetchStatus.should.equal(firebase.remoteConfig.LastFetchStatus.SUCCESS); - should.equal(firebase.remoteConfig().fetchTimeMillis >= date, true); + should.equal(getRemoteConfig().fetchTimeMillis >= date, true); }); it('without expiration provided', function () { @@ -957,8 +969,9 @@ describe('remoteConfig()', function () { describe('setCustomSignals()', function () { it('should resolve with valid signal value; `string`, `number` or `null`', async function () { + const { getApp } = modular; const { setCustomSignals, getRemoteConfig } = remoteConfigModular; - const remoteConfig = getRemoteConfig(firebase.app()); + const remoteConfig = getRemoteConfig(getApp()); // native SDKs just ignore invalid key/values (e.g. too long) and just log warning const signals = { string: 'string', @@ -972,8 +985,9 @@ describe('remoteConfig()', function () { }); it('should reject with invalid signal value', async function () { + const { getApp } = modular; const { setCustomSignals, getRemoteConfig } = remoteConfigModular; - const remoteConfig = getRemoteConfig(firebase.app()); + const remoteConfig = getRemoteConfig(getApp()); const invalidSignals = [ { signal1: true }, diff --git a/packages/storage/e2e/StorageReference.e2e.js b/packages/storage/e2e/StorageReference.e2e.js index a7a773701d..a561087dab 100644 --- a/packages/storage/e2e/StorageReference.e2e.js +++ b/packages/storage/e2e/StorageReference.e2e.js @@ -21,6 +21,14 @@ describe('storage() -> StorageReference', function () { describe('firebase v8 compatibility', function () { before(async function () { await seed(PATH); + + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + after(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; }); describe('toString()', function () { @@ -671,24 +679,24 @@ describe('storage() -> StorageReference', function () { }); }); }); - }); - describe('put secondaryApp', function () { - it('allows valid metadata properties for upload', async function () { - const storageReference = firebase - .storage(firebase.app('secondaryFromNative')) - // .storage() - .ref(`${PATH}/metadataTest.jpeg`); - await storageReference.put(new ArrayBuffer(), { - contentType: 'image/jpg', - md5hash: '123412341234', - cacheControl: 'true', - contentDisposition: 'disposed', - contentEncoding: 'application/octet-stream', - contentLanguage: 'de', - customMetadata: { - customMetadata1: 'metadata1value', - }, + describe('put secondaryApp', function () { + it('allows valid metadata properties for upload', async function () { + const storageReference = firebase + .storage(firebase.app('secondaryFromNative')) + // .storage() + .ref(`${PATH}/metadataTest.jpeg`); + await storageReference.put(new ArrayBuffer(), { + contentType: 'image/jpg', + md5hash: '123412341234', + cacheControl: 'true', + contentDisposition: 'disposed', + contentEncoding: 'application/octet-stream', + contentLanguage: 'de', + customMetadata: { + customMetadata1: 'metadata1value', + }, + }); }); }); }); @@ -700,8 +708,9 @@ describe('storage() -> StorageReference', function () { before(async function () { await seed(PATH); + const { getApp } = modular; const { getStorage } = storageModular; - secondStorage = getStorage(firebase.app(), secondStorageBucket); + secondStorage = getStorage(getApp(), secondStorageBucket); }); describe('second storage bucket writes to Storage emulator', function () { @@ -737,12 +746,12 @@ describe('storage() -> StorageReference', function () { describe('toString()', function () { it('returns the correct bucket path to the file', function () { + const { getApp } = modular; const { getStorage, ref, toString } = storageModular; const storageReference = ref(getStorage(), `/uploadNope.jpeg`); - const app = firebase.app(); toString(storageReference).should.equal( - `gs://${app.options.storageBucket}/uploadNope.jpeg`, + `gs://${getApp().options.storageBucket}/uploadNope.jpeg`, ); }); }); @@ -768,10 +777,10 @@ describe('storage() -> StorageReference', function () { describe('bucket', function () { it('returns the storage bucket as a string', function () { + const { getApp } = modular; const { getStorage, ref } = storageModular; const storageReference = ref(getStorage(), '/foo/uploadNope.jpeg'); - const app = firebase.app(); - storageReference.bucket.should.equal(app.options.storageBucket); + storageReference.bucket.should.equal(getApp().options.storageBucket); }); }); @@ -879,6 +888,7 @@ describe('storage() -> StorageReference', function () { describe('getDownloadURL', function () { it('should return a download url for a file', async function () { + const { getApp } = modular; const { getStorage, ref, getDownloadURL } = storageModular; // This is frequently flaky in CI - but works sometimes. Skipping only in CI for now. if (!isCI) { @@ -886,7 +896,7 @@ describe('storage() -> StorageReference', function () { const downloadUrl = await getDownloadURL(storageReference); downloadUrl.should.be.a.String(); downloadUrl.should.containEql('file1.txt'); - downloadUrl.should.containEql(firebase.app().options.projectId); + downloadUrl.should.containEql(getApp().options.projectId); } else { this.skip(); } @@ -931,6 +941,7 @@ describe('storage() -> StorageReference', function () { describe('getMetadata', function () { it('should return a metadata for a file', async function () { + const { getApp } = modular; const { getStorage, ref, getMetadata } = storageModular; const storageReference = ref(getStorage(), `${PATH}/list/file1.txt`); const metadata = await getMetadata(storageReference); @@ -950,7 +961,7 @@ describe('storage() -> StorageReference', function () { metadata.contentEncoding.should.be.a.String(); metadata.contentDisposition.should.be.a.String(); metadata.contentType.should.equal('text/plain'); - metadata.bucket.should.equal(`${firebase.app().options.projectId}.appspot.com`); + metadata.bucket.should.equal(`${getApp().options.projectId}.appspot.com`); metadata.metageneration.should.be.a.String(); metadata.md5Hash.should.be.a.String(); // TODO against cloud storage cacheControl comes back null/undefined by default. Emulator has a difference @@ -1119,6 +1130,7 @@ describe('storage() -> StorageReference', function () { describe('updateMetadata', function () { it('should return the updated metadata for a file', async function () { + const { getApp } = modular; const { getStorage, ref, updateMetadata } = storageModular; const storageReference = ref(getStorage(), `${PATH}/list/file1.txt`); @@ -1150,7 +1162,7 @@ describe('storage() -> StorageReference', function () { metadata.timeCreated.should.be.a.String(); metadata.metageneration.should.be.a.String(); metadata.md5Hash.should.be.a.String(); - metadata.bucket.should.equal(`${firebase.app().options.projectId}.appspot.com`); + metadata.bucket.should.equal(`${getApp().options.projectId}.appspot.com`); // Things we just updated metadata.cacheControl.should.equals('cache-control'); @@ -1189,7 +1201,7 @@ describe('storage() -> StorageReference', function () { metadata.timeCreated.should.be.a.String(); metadata.metageneration.should.be.a.String(); metadata.md5Hash.should.be.a.String(); - metadata.bucket.should.equal(`${firebase.app().options.projectId}.appspot.com`); + metadata.bucket.should.equal(`${getApp().options.projectId}.appspot.com`); // Things that we may set (or remove) should.equal(metadata.cacheControl, undefined); diff --git a/packages/storage/e2e/StorageTask.e2e.js b/packages/storage/e2e/StorageTask.e2e.js index 10fc150440..781a1b1652 100644 --- a/packages/storage/e2e/StorageTask.e2e.js +++ b/packages/storage/e2e/StorageTask.e2e.js @@ -31,6 +31,14 @@ describe('storage() -> StorageTask', function () { describe('firebase v8 compatibility', function () { before(async function () { await seed(PATH); + + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + after(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; }); describe('writeToFile()', function () { diff --git a/packages/storage/e2e/helpers.js b/packages/storage/e2e/helpers.js index d42cd01b8b..e0eecf7f85 100644 --- a/packages/storage/e2e/helpers.js +++ b/packages/storage/e2e/helpers.js @@ -8,20 +8,20 @@ const WRITE_ONLY_NAME = 'writeOnly.jpeg'; exports.seed = async function seed(path) { let leakDetectCurrent = globalThis.RNFBDebugInTestLeakDetection; globalThis.RNFBDebugInTestLeakDetection = false; + const { getStorage, ref } = storageModular; try { // Add a write only file - await firebase.storage().ref(WRITE_ONLY_NAME).putString('Write Only'); + await ref(getStorage(), WRITE_ONLY_NAME).putString('Write Only'); // Setup list items - Future.wait not working... - await firebase - .storage() - .ref(`${path}/list/file1.txt`) - .putString('File 1', 'raw', { contentType: 'text/plain' }); - await firebase.storage().ref(`${path}/list/file2.txt`).putString('File 2'); - await firebase.storage().ref(`${path}/list/file3.txt`).putString('File 3'); - await firebase.storage().ref(`${path}/list/file4.txt`).putString('File 4'); - await firebase.storage().ref(`${path}/list/nested/file5.txt`).putString('File 5'); + await ref(getStorage(), `${path}/list/file1.txt`).putString('File 1', 'raw', { + contentType: 'text/plain', + }); + await ref(getStorage(), `${path}/list/file2.txt`).putString('File 2'); + await ref(getStorage(), `${path}/list/file3.txt`).putString('File 3'); + await ref(getStorage(), `${path}/list/file4.txt`).putString('File 4'); + await ref(getStorage(), `${path}/list/nested/file5.txt`).putString('File 5'); } catch (e) { // eslint-disable-next-line no-console console.error('unable to seed storage service with test fixtures'); @@ -32,7 +32,8 @@ exports.seed = async function seed(path) { }; exports.wipe = function wipe(path) { - return firebase.storage().ref(path).remove(); + const { getStorage, ref } = storageModular; + return ref(getStorage(), path).remove(); }; exports.PATH = PATH; diff --git a/packages/storage/e2e/storage.e2e.js b/packages/storage/e2e/storage.e2e.js index b6f006b365..6305ce88e5 100644 --- a/packages/storage/e2e/storage.e2e.js +++ b/packages/storage/e2e/storage.e2e.js @@ -18,6 +18,16 @@ const { PATH } = require('./helpers'); describe('storage() modular', function () { describe('firebase v8 compatibility', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; + }); + + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; + }); + describe('storage()', function () { describe('namespace', function () { it('accessible from firebase.app()', function () { @@ -241,9 +251,10 @@ describe('storage() modular', function () { describe('modular', function () { describe('getStorage', function () { it('pass app as argument', function () { + const { getApp } = modular; const { getStorage } = storageModular; - const storage = getStorage(firebase.app()); + const storage = getStorage(getApp()); storage.constructor.name.should.be.equal('FirebaseStorageModule'); }); diff --git a/tests/app.js b/tests/app.js index bcfd1d41fa..f0fb2ddb7a 100644 --- a/tests/app.js +++ b/tests/app.js @@ -69,7 +69,7 @@ ErrorUtils.setGlobalHandler((err, isFatal) => { function loadTests(_) { describe('React Native Firebase', function () { - if (!globalThis.RNFBDebug && !globalThis.RNFB_MODULAR_DEPRECATION_STRICT_MODE) { + if (!globalThis.RNFBDebug) { // Only retry tests if not debugging or hunting deprecated API usage locally, // otherwise it gets annoying to debug. this.retries(4); diff --git a/tests/globals.js b/tests/globals.js index c78f0d26c1..53af7dafa2 100644 --- a/tests/globals.js +++ b/tests/globals.js @@ -49,7 +49,7 @@ import shouldMatchers from 'should'; globalThis.RNFBDebug = false; // this may be used to locate modular API errors quickly -globalThis.RNFB_MODULAR_DEPRECATION_STRICT_MODE = false; +globalThis.RNFB_MODULAR_DEPRECATION_STRICT_MODE = true; // Needed for Platform.Other session storage import AsyncStorage from '@react-native-async-storage/async-storage';