Skip to content

Commit 6ef484a

Browse files
sam-gcFeiyang1
andauthored
Rename all v9 modular useEmulator functions to connectEmulator (#5179)
* Update useEmulator function names * update function name Co-authored-by: Feiyang1 <[email protected]>
1 parent 7028c11 commit 6ef484a

File tree

30 files changed

+95
-82
lines changed

30 files changed

+95
-82
lines changed

common/api-review/auth-exp.api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ export interface ConfirmationResult {
173173
// @public
174174
export function confirmPasswordReset(auth: Auth, oobCode: string, newPassword: string): Promise<void>;
175175

176+
// @public
177+
export function connectAuthEmulator(auth: Auth, url: string, options?: {
178+
disableWarnings: boolean;
179+
}): void;
180+
176181
// @public
177182
export function createUserWithEmailAndPassword(auth: Auth, email: string, password: string): Promise<UserCredential>;
178183

@@ -644,11 +649,6 @@ export function updateProfile(user: User, { displayName, photoURL: photoUrl }: {
644649
photoURL?: string | null;
645650
}): Promise<void>;
646651

647-
// @public
648-
export function useAuthEmulator(auth: Auth, url: string, options?: {
649-
disableWarnings: boolean;
650-
}): void;
651-
652652
// @public
653653
export function useDeviceLanguage(auth: Auth): void;
654654

common/api-review/database.api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import { FirebaseApp } from '@firebase/app';
1010
// @public
1111
export function child(parent: Reference, path: string): Reference;
1212

13+
// @public
14+
export function connectDatabaseEmulator(db: FirebaseDatabase, host: string, port: number, options?: {
15+
mockUserToken?: EmulatorMockTokenOptions;
16+
}): void;
17+
1318
// @public
1419
export class DataSnapshot {
1520
child(path: string): DataSnapshot;
@@ -229,10 +234,5 @@ export type Unsubscribe = () => void;
229234
// @public
230235
export function update(ref: Reference, values: object): Promise<void>;
231236

232-
// @public
233-
export function useDatabaseEmulator(db: FirebaseDatabase, host: string, port: number, options?: {
234-
mockUserToken?: EmulatorMockTokenOptions;
235-
}): void;
236-
237237

238238
```

common/api-review/functions-exp.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import { FirebaseApp } from '@firebase/app-exp';
88
import { FirebaseError } from '@firebase/util';
99

10+
// @public
11+
export function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void;
12+
1013
// @public
1114
export interface Functions {
1215
app: FirebaseApp;
@@ -42,8 +45,5 @@ export interface HttpsCallableResult<ResponseData = unknown> {
4245
readonly data: ResponseData;
4346
}
4447

45-
// @public
46-
export function useFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void;
47-
4848

4949
```

common/api-review/storage.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import { Provider } from '@firebase/component';
1515
import { Subscribe } from '@firebase/util';
1616
import { Unsubscribe } from '@firebase/util';
1717

18+
// @public
19+
export function connectStorageEmulator(storage: StorageService, host: string, port: number): void;
20+
1821
// @public
1922
export function deleteObject(ref: StorageReference): Promise<void>;
2023

@@ -254,8 +257,5 @@ export interface UploadTaskSnapshot {
254257
totalBytes: number;
255258
}
256259

257-
// @public
258-
export function useStorageEmulator(storage: StorageService, host: string, port: number): void;
259-
260260

261261
```

packages-exp/auth-compat-exp/src/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class Auth
127127
return this._delegate.signOut();
128128
}
129129
useEmulator(url: string, options?: { disableWarnings: boolean }): void {
130-
exp.useAuthEmulator(this._delegate, url, options);
130+
exp.connectAuthEmulator(this._delegate, url, options);
131131
}
132132
applyActionCode(code: string): Promise<void> {
133133
return exp.applyActionCode(this._delegate, code);

packages-exp/auth-exp/src/core/auth/emulator.test.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as fetch from '../../../test/helpers/mock_fetch';
2828
import { Endpoint } from '../../api';
2929
import { UserInternal } from '../../model/user';
3030
import { _castAuth } from './auth_impl';
31-
import { useAuthEmulator } from './emulator';
31+
import { connectAuthEmulator } from './emulator';
3232

3333
use(sinonChai);
3434
use(chaiAsPromised);
@@ -67,48 +67,49 @@ describe('core/auth/emulator', () => {
6767
}
6868
});
6969

70-
context('useAuthEmulator', () => {
70+
context('connectAuthEmulator', () => {
7171
it('fails if a network request has already been made', async () => {
7272
await user.delete();
73-
expect(() => useAuthEmulator(auth, 'http://localhost:2020')).to.throw(
73+
expect(() => connectAuthEmulator(auth, 'http://localhost:2020')).to.throw(
7474
FirebaseError,
7575
'auth/emulator-config-failed'
7676
);
7777
});
7878

7979
it('updates the endpoint appropriately', async () => {
80-
useAuthEmulator(auth, 'http://localhost:2020');
80+
connectAuthEmulator(auth, 'http://localhost:2020');
8181
await user.delete();
8282
expect(normalEndpoint.calls.length).to.eq(0);
8383
expect(emulatorEndpoint.calls.length).to.eq(1);
8484
});
8585

8686
it('updates the endpoint appropriately with trailing slash', async () => {
87-
useAuthEmulator(auth, 'http://localhost:2020/');
87+
connectAuthEmulator(auth, 'http://localhost:2020/');
8888
await user.delete();
8989
expect(normalEndpoint.calls.length).to.eq(0);
9090
expect(emulatorEndpoint.calls.length).to.eq(1);
9191
});
9292

9393
it('checks the scheme properly', () => {
94-
expect(() => useAuthEmulator(auth, 'http://localhost:2020')).not.to.throw;
94+
expect(() => connectAuthEmulator(auth, 'http://localhost:2020')).not.to
95+
.throw;
9596
delete auth.config.emulator;
96-
expect(() => useAuthEmulator(auth, 'https://localhost:2020')).not.to
97+
expect(() => connectAuthEmulator(auth, 'https://localhost:2020')).not.to
9798
.throw;
9899
delete auth.config.emulator;
99-
expect(() => useAuthEmulator(auth, 'ssh://localhost:2020')).to.throw(
100+
expect(() => connectAuthEmulator(auth, 'ssh://localhost:2020')).to.throw(
100101
FirebaseError,
101102
'auth/invalid-emulator-scheme'
102103
);
103104
delete auth.config.emulator;
104-
expect(() => useAuthEmulator(auth, 'localhost:2020')).to.throw(
105+
expect(() => connectAuthEmulator(auth, 'localhost:2020')).to.throw(
105106
FirebaseError,
106107
'auth/invalid-emulator-scheme'
107108
);
108109
});
109110

110111
it('attaches a banner to the DOM', () => {
111-
useAuthEmulator(auth, 'http://localhost:2020');
112+
connectAuthEmulator(auth, 'http://localhost:2020');
112113
if (typeof document !== 'undefined') {
113114
const el = document.querySelector('.firebase-emulator-warning')!;
114115
expect(el).not.to.be.null;
@@ -121,7 +122,7 @@ describe('core/auth/emulator', () => {
121122

122123
it('logs out a warning to the console', () => {
123124
sinon.stub(console, 'info');
124-
useAuthEmulator(auth, 'http://localhost:2020');
125+
connectAuthEmulator(auth, 'http://localhost:2020');
125126
expect(console.info).to.have.been.calledWith(
126127
'WARNING: You are using the Auth Emulator,' +
127128
' which is intended for local testing only. Do not use with' +
@@ -131,7 +132,9 @@ describe('core/auth/emulator', () => {
131132

132133
it('logs out the warning but has no banner if disableBanner true', () => {
133134
sinon.stub(console, 'info');
134-
useAuthEmulator(auth, 'http://localhost:2020', { disableWarnings: true });
135+
connectAuthEmulator(auth, 'http://localhost:2020', {
136+
disableWarnings: true
137+
});
135138
expect(console.info).to.have.been.calledWith(
136139
'WARNING: You are using the Auth Emulator,' +
137140
' which is intended for local testing only. Do not use with' +
@@ -143,7 +146,7 @@ describe('core/auth/emulator', () => {
143146
});
144147

145148
it('sets emulatorConfig on the Auth object', async () => {
146-
useAuthEmulator(auth, 'http://localhost:2020');
149+
connectAuthEmulator(auth, 'http://localhost:2020');
147150
expect(auth.emulatorConfig).to.eql({
148151
protocol: 'http',
149152
host: 'localhost',
@@ -153,7 +156,7 @@ describe('core/auth/emulator', () => {
153156
});
154157

155158
it('sets disableWarnings in emulatorConfig accordingly', async () => {
156-
useAuthEmulator(auth, 'https://127.0.0.1', { disableWarnings: true });
159+
connectAuthEmulator(auth, 'https://127.0.0.1', { disableWarnings: true });
157160
expect(auth.emulatorConfig).to.eql({
158161
protocol: 'https',
159162
host: '127.0.0.1',
@@ -163,7 +166,7 @@ describe('core/auth/emulator', () => {
163166
});
164167

165168
it('quotes IPv6 address in emulatorConfig', async () => {
166-
useAuthEmulator(auth, 'http://[::1]:2020/');
169+
connectAuthEmulator(auth, 'http://[::1]:2020/');
167170
expect(auth.emulatorConfig).to.eql({
168171
protocol: 'http',
169172
host: '[::1]',
@@ -181,9 +184,9 @@ describe('core/auth/emulator', () => {
181184
});
182185

183186
it('also stringifies the current user', () => {
184-
auth.currentUser = ({
187+
auth.currentUser = {
185188
toJSON: (): object => ({ foo: 'bar' })
186-
} as unknown) as UserInternal;
189+
} as unknown as UserInternal;
187190
expect(JSON.stringify(auth)).to.eq(
188191
'{"apiKey":"test-api-key","authDomain":"localhost",' +
189192
'"appName":"test-app","currentUser":{"foo":"bar"}}'

packages-exp/auth-exp/src/core/auth/emulator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { _castAuth } from './auth_impl';
3131
*
3232
* @example
3333
* ```javascript
34-
* useAuthEmulator(auth, 'http://127.0.0.1:9099', { disableWarnings: true });
34+
* connectAuthEmulator(auth, 'http://127.0.0.1:9099', { disableWarnings: true });
3535
* ```
3636
*
3737
* @param auth - The Auth instance.
@@ -40,7 +40,7 @@ import { _castAuth } from './auth_impl';
4040
*
4141
* @public
4242
*/
43-
export function useAuthEmulator(
43+
export function connectAuthEmulator(
4444
auth: Auth,
4545
url: string,
4646
options?: { disableWarnings: boolean }

packages-exp/auth-exp/src/core/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function _debugErrorMap(): ErrorMap<AuthErrorCode> {
169169
[AuthErrorCode.EMULATOR_CONFIG_FAILED]:
170170
'Auth instance has already been used to make a network call. Auth can ' +
171171
'no longer be configured to use the emulator. Try calling ' +
172-
'"useAuthEmulator()" sooner.',
172+
'"connectAuthEmulator()" sooner.',
173173
[AuthErrorCode.EXPIRED_OOB_CODE]: 'The action code has expired.',
174174
[AuthErrorCode.EXPIRED_POPUP_REQUEST]:
175175
'This operation has been cancelled due to another conflicting popup being opened.',

packages-exp/auth-exp/src/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export function signOut(auth: Auth): Promise<void> {
150150
}
151151

152152
export { initializeAuth } from './auth/initialize';
153-
export { useAuthEmulator } from './auth/emulator';
153+
export { connectAuthEmulator } from './auth/emulator';
154154

155155
// credentials
156156
export { AuthCredential } from './credentials';

packages-exp/auth-exp/test/helpers/integration/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as sinon from 'sinon';
1919
import { deleteApp, initializeApp } from '@firebase/app-exp';
2020
import { Auth, User } from '../../../src/model/public_types';
2121

22-
import { getAuth, useAuthEmulator } from '../../../'; // Use browser OR node dist entrypoint depending on test env.
22+
import { getAuth, connectAuthEmulator } from '../../../'; // Use browser OR node dist entrypoint depending on test env.
2323
import { _generateEventId } from '../../../src/core/util/event_id';
2424
import { getAppConfig, getEmulatorUrl } from './settings';
2525
import { resetEmulator } from './emulator_rest_helpers';
@@ -42,7 +42,7 @@ export function getTestInstance(requireEmulator = false): Auth {
4242

4343
if (emulatorUrl) {
4444
const stub = stubConsoleToSilenceEmulatorWarnings();
45-
useAuthEmulator(auth, emulatorUrl, { disableWarnings: true });
45+
connectAuthEmulator(auth, emulatorUrl, { disableWarnings: true });
4646
stub.restore();
4747
} else if (requireEmulator) {
4848
/* Emulator wasn't configured but test must use emulator */

packages-exp/auth-exp/test/integration/webdriver/static/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import * as popup from './popup';
2222
import * as email from './email';
2323
import * as persistence from './persistence';
2424
import { initializeApp } from '@firebase/app-exp';
25-
import { getAuth, useAuthEmulator } from '@firebase/auth-exp';
25+
import { getAuth, connectAuthEmulator } from '@firebase/auth-exp';
2626

2727
window.core = core;
2828
window.anonymous = anonymous;
@@ -39,7 +39,7 @@ window.legacyAuth = null;
3939
window.startAuth = async () => {
4040
const app = initializeApp(firebaseConfig);
4141
const auth = getAuth(app);
42-
useAuthEmulator(auth, emulatorUrl);
42+
connectAuthEmulator(auth, emulatorUrl);
4343
window.auth = auth;
4444
};
4545

packages-exp/functions-compat/src/service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Firebase Functions > Service', () => {
3131
let httpsCallableStub: SinonStub = stub();
3232

3333
before(() => {
34-
functionsEmulatorStub = stub(functionsExp, 'useFunctionsEmulator');
34+
functionsEmulatorStub = stub(functionsExp, 'connectFunctionsEmulator');
3535
httpsCallableStub = stub(functionsExp, 'httpsCallable');
3636
});
3737

packages-exp/functions-compat/src/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { FirebaseFunctions, HttpsCallable } from '@firebase/functions-types';
1919
import {
2020
httpsCallable as httpsCallableExp,
21-
useFunctionsEmulator as useFunctionsEmulatorExp,
21+
connectFunctionsEmulator as useFunctionsEmulatorExp,
2222
HttpsCallableOptions,
2323
Functions as FunctionsServiceExp
2424
} from '@firebase/functions-exp';

packages-exp/functions-exp/src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Functions, HttpsCallableOptions, HttpsCallable } from './public-types';
2323
import {
2424
FunctionsService,
2525
DEFAULT_REGION,
26-
useFunctionsEmulator as _useFunctionsEmulator,
26+
connectFunctionsEmulator as _connectFunctionsEmulator,
2727
httpsCallable as _httpsCallable
2828
} from './service';
2929
import { getModularInstance } from '@firebase/util';
@@ -62,12 +62,12 @@ export function getFunctions(
6262
* @param port - The emulator port (ex: 5001)
6363
* @public
6464
*/
65-
export function useFunctionsEmulator(
65+
export function connectFunctionsEmulator(
6666
functionsInstance: Functions,
6767
host: string,
6868
port: number
6969
): void {
70-
_useFunctionsEmulator(
70+
_connectFunctionsEmulator(
7171
getModularInstance<FunctionsService>(functionsInstance as FunctionsService),
7272
host,
7373
port

packages-exp/functions-exp/src/service.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
import { assert } from 'chai';
1818
import { createTestService } from '../test/utils';
19-
import { FunctionsService, useFunctionsEmulator } from './service';
19+
import { FunctionsService, connectFunctionsEmulator } from './service';
2020

2121
describe('Firebase Functions > Service', () => {
2222
describe('simple constructor', () => {
@@ -41,7 +41,7 @@ describe('Firebase Functions > Service', () => {
4141

4242
it('can use emulator', () => {
4343
service = createTestService(app);
44-
useFunctionsEmulator(service, 'localhost', 5005);
44+
connectFunctionsEmulator(service, 'localhost', 5005);
4545
assert.equal(
4646
service._url('foo'),
4747
'http://localhost:5005/my-project/us-central1/foo'
@@ -58,7 +58,7 @@ describe('Firebase Functions > Service', () => {
5858

5959
it('correctly sets region with emulator', () => {
6060
service = createTestService(app, 'my-region');
61-
useFunctionsEmulator(service, 'localhost', 5005);
61+
connectFunctionsEmulator(service, 'localhost', 5005);
6262
assert.equal(
6363
service._url('foo'),
6464
'http://localhost:5005/my-project/my-region/foo'
@@ -72,7 +72,7 @@ describe('Firebase Functions > Service', () => {
7272

7373
it('prefers emulator to custom domain', () => {
7474
const service = createTestService(app, 'https://mydomain.com');
75-
useFunctionsEmulator(service, 'localhost', 5005);
75+
connectFunctionsEmulator(service, 'localhost', 5005);
7676
assert.equal(
7777
service._url('foo'),
7878
'http://localhost:5005/my-project/us-central1/foo'

packages-exp/functions-exp/src/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class FunctionsService implements _FirebaseService {
147147
* @param port The emulator port (ex: 5001)
148148
* @public
149149
*/
150-
export function useFunctionsEmulator(
150+
export function connectFunctionsEmulator(
151151
functionsInstance: FunctionsService,
152152
host: string,
153153
port: number

packages-exp/functions-exp/test/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
2121
import { FirebaseMessagingName } from '@firebase/messaging-types';
2222
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
2323
import { FunctionsService } from '../src/service';
24-
import { useFunctionsEmulator } from '../src/api';
24+
import { connectFunctionsEmulator } from '../src/api';
2525
import nodeFetch from 'node-fetch';
2626

2727
export function makeFakeApp(options: FirebaseOptions = {}): FirebaseApp {
@@ -71,7 +71,7 @@ export function createTestService(
7171
const useEmulator = !!process.env.FIREBASE_FUNCTIONS_EMULATOR_ORIGIN;
7272
if (useEmulator) {
7373
const url = new URL(process.env.FIREBASE_FUNCTIONS_EMULATOR_ORIGIN!);
74-
useFunctionsEmulator(
74+
connectFunctionsEmulator(
7575
functions,
7676
url.hostname,
7777
Number.parseInt(url.port, 10)

0 commit comments

Comments
 (0)