Skip to content

Commit

Permalink
[Auth] Disable the console.info in connectAuthEmulator() when disable…
Browse files Browse the repository at this point in the history
…Warnings is passed in (#5564)

* Disable the console.info when disableWarnings is set

* Add changeset
  • Loading branch information
sam-gc committed Oct 1, 2021
1 parent f7d8324 commit 1b0e7af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-bugs-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/auth": patch
---

Calls to `connectAuthEmulator` with the `disableWarnings` flag set to true will no longer cause a `console.info` warning to be printed
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

0 comments on commit 1b0e7af

Please sign in to comment.