Skip to content

[Auth] Disable the console.info in connectAuthEmulator() when disableWarnings is passed in #5564

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 2 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 2 additions & 6 deletions packages/auth/src/core/auth/emulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,12 @@ describe('core/auth/emulator', () => {
);
});

it('logs out the warning but has no banner if disableBanner true', () => {
it('skips console info and has no banner if warnings disabled', () => {
sinon.stub(console, 'info');
connectAuthEmulator(auth, 'http://localhost:2020', {
disableWarnings: true
});
expect(console.info).to.have.been.calledWith(
'WARNING: You are using the Auth Emulator,' +
' which is intended for local testing only. Do not use with' +
' production credentials.'
);
expect(console.info).not.to.have.been.called;
if (typeof document !== 'undefined') {
expect(document.querySelector('.firebase-emulator-warning')).to.be.null;
}
Expand Down
9 changes: 5 additions & 4 deletions packages/auth/src/core/auth/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export function connectAuthEmulator(
options: Object.freeze({ disableWarnings })
});

emitEmulatorWarning(disableWarnings);
if (!disableWarnings) {
emitEmulatorWarning();
}
}

function extractProtocol(url: string): string {
Expand Down Expand Up @@ -114,7 +116,7 @@ function parsePort(portStr: string): number | null {
return port;
}

function emitEmulatorWarning(disableBanner: boolean): void {
function emitEmulatorWarning(): void {
function attachBanner(): void {
const el = document.createElement('p');
const sty = el.style;
Expand Down Expand Up @@ -143,8 +145,7 @@ function emitEmulatorWarning(disableBanner: boolean): void {
}
if (
typeof window !== 'undefined' &&
typeof document !== 'undefined' &&
!disableBanner
typeof document !== 'undefined'
) {
if (document.readyState === 'loading') {
window.addEventListener('DOMContentLoaded', attachBanner);
Expand Down