-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn instead of throw for idb errors in core app (#6480)
- Loading branch information
Showing
4 changed files
with
117 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@firebase/app': patch | ||
--- | ||
|
||
Prevent core app from throwing if IndexedDB heartbeat functions throw. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import '../test/setup'; | ||
import { match, stub } from 'sinon'; | ||
import { | ||
readHeartbeatsFromIndexedDB, | ||
writeHeartbeatsToIndexedDB | ||
} from './indexeddb'; | ||
import { FirebaseApp } from './public-types'; | ||
import { AppError } from './errors'; | ||
import { HeartbeatsInIndexedDB } from './types'; | ||
|
||
/** | ||
* Mostly testing failure cases. heartbeatService.test.ts tests read-write | ||
* more extensively. | ||
*/ | ||
|
||
describe('IndexedDB functions', () => { | ||
it('readHeartbeatsFromIndexedDB warns if IndexedDB.open() throws', async () => { | ||
const warnStub = stub(console, 'warn'); | ||
if (typeof window !== 'undefined') { | ||
// Ensure that indexedDB.open() fails in browser. It will always fail in Node. | ||
stub(window.indexedDB, 'open').throws(new Error('abcd')); | ||
await readHeartbeatsFromIndexedDB({ | ||
name: 'testname', | ||
options: { appId: 'test-app-id' } | ||
} as FirebaseApp); | ||
expect(warnStub).to.be.calledWith(match.any, match(AppError.IDB_GET)); | ||
} else { | ||
await readHeartbeatsFromIndexedDB({ | ||
name: 'testname', | ||
options: { appId: 'test-app-id' } | ||
} as FirebaseApp); | ||
expect(warnStub).to.be.calledWith(match.any, match(AppError.IDB_GET)); | ||
} | ||
}); | ||
it('writeHeartbeatsToIndexedDB warns if IndexedDB.open() throws', async () => { | ||
const warnStub = stub(console, 'warn'); | ||
if (typeof window !== 'undefined') { | ||
// Ensure that indexedDB.open() fails in browser. It will always fail in Node. | ||
stub(window.indexedDB, 'open').throws(new Error('abcd')); | ||
await writeHeartbeatsToIndexedDB( | ||
{ | ||
name: 'testname', | ||
options: { appId: 'test-app-id' } | ||
} as FirebaseApp, | ||
{} as HeartbeatsInIndexedDB | ||
); | ||
expect(warnStub).to.be.calledWith(match.any, match(AppError.IDB_WRITE)); | ||
} else { | ||
await writeHeartbeatsToIndexedDB( | ||
{ | ||
name: 'testname', | ||
options: { appId: 'test-app-id' } | ||
} as FirebaseApp, | ||
{} as HeartbeatsInIndexedDB | ||
); | ||
expect(warnStub).to.be.calledWith(match.any, match(AppError.IDB_WRITE)); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters