Skip to content

Make the emulator API match for auth-exp #3925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages-exp/auth-compat-exp/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export class Auth implements compat.FirebaseAuth, Wrapper<externs.Auth> {
signOut(): Promise<void> {
return this.auth.signOut();
}

useEmulator(url: string): void {
this.auth.useEmulator(url);
}
applyActionCode(code: string): Promise<void> {
return impl.applyActionCode(this.auth, code);
}
Expand Down
3 changes: 1 addition & 2 deletions packages-exp/auth-exp/src/api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ describe('api/_performApiRequest', () => {

it('works properly with an emulated environment', () => {
(auth.config as ConfigInternal).emulator = {
hostname: 'localhost',
port: 5000
url: 'http://localhost:5000'
};
expect(_getFinalTarget(auth, 'host', '/path', 'query=test')).to.eq(
'http://localhost:5000/host/path?query=test'
Expand Down
4 changes: 2 additions & 2 deletions packages-exp/auth-exp/src/core/auth/auth_impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ describe('core/auth/auth_impl useEmulator', () => {
context('useEmulator', () => {
it('fails if a network request has already been made', async () => {
await user.delete();
expect(() => auth.useEmulator('localhost', 2020)).to.throw(
expect(() => auth.useEmulator('http://localhost:2020')).to.throw(
FirebaseError,
'auth/emulator-config-failed'
);
});

it('updates the endpoint appropriately', async () => {
auth.useEmulator('localhost', 2020);
auth.useEmulator('http://localhost:2020');
await user.delete();
expect(normalEndpoint.calls.length).to.eq(0);
expect(emulatorEndpoint.calls.length).to.eq(1);
Expand Down
8 changes: 2 additions & 6 deletions packages-exp/auth-exp/src/core/auth/auth_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,12 @@ export class AuthImpl implements Auth, _FirebaseService {
this.languageCode = _getUserLanguage();
}

useEmulator(hostname: string, port: number): void {
useEmulator(url: string): void {
assert(this._canInitEmulator, AuthErrorCode.EMULATOR_CONFIG_FAILED, {
appName: this.name
});

this.config.emulator = {
hostname,
port
};

this.config.emulator = { url };
this.settings.appVerificationDisabledForTesting = true;
}

Expand Down
5 changes: 2 additions & 3 deletions packages-exp/auth-exp/src/core/util/emulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import { _emulatorUrl } from './emulator';
describe('core/util/emulator', () => {
const config: ConfigInternal = {
emulator: {
hostname: 'localhost',
port: 4000
url: 'http://localhost:4000'
}
} as ConfigInternal;

it('builds the proper URL with no path', () => {
expect(_emulatorUrl(config)).to.eq('http://localhost:4000');
expect(_emulatorUrl(config)).to.eq('http://localhost:4000/');
});

it('builds the proper URL with a path', () => {
Expand Down
9 changes: 4 additions & 5 deletions packages-exp/auth-exp/src/core/util/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import { debugAssert } from './assert';

export function _emulatorUrl(config: ConfigInternal, path?: string): string {
debugAssert(config.emulator, 'Emulator should always be set here');
const { hostname, port } = config.emulator;
const { url } = config.emulator;
const emulatorHost = new URL(url).toString();

const base = `http://${hostname}:${port}`;
if (!path) {
return base;
return emulatorHost;
}

const sep = path.startsWith('/') ? '' : '/';
return `${base}${sep}${path}`;
return `${emulatorHost}${path.startsWith('/') ? path.slice(1) : path}`;
}
3 changes: 1 addition & 2 deletions packages-exp/auth-exp/src/model/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export type AuthDomain = string;

export interface ConfigInternal extends externs.Config {
emulator?: {
hostname: string;
port: number;
url: string;
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages-exp/auth-types-exp/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export interface Auth {
readonly currentUser: User | null;
updateCurrentUser(user: User | null): Promise<void>;
useDeviceLanguage(): void;
useEmulator(hostname: string, port: number): void;
useEmulator(url: string): void;
signOut(): Promise<void>;
}

Expand Down