Skip to content

Commit eaa8ae8

Browse files
committed
fix spec_test_runner.ts
1 parent 43aae1a commit eaa8ae8

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
localStoreReadDocument,
3434
localStoreSetIndexAutoCreationEnabled
3535
} from '../local/local_store_impl';
36-
import { Persistence } from '../local/persistence';
36+
import { Persistence, DatabaseDeletedListenerAbortResult, DatabaseDeletedListenerContinueResult } from '../local/persistence';
3737
import { Document } from '../model/document';
3838
import { DocumentKey } from '../model/document_key';
3939
import { FieldIndex } from '../model/field_index';
@@ -234,12 +234,10 @@ export async function setOfflineComponentProvider(
234234
// need to be terminated to allow the delete to succeed.
235235
offlineComponentProvider.persistence.setDatabaseDeletedListener(reason => {
236236
client.terminate();
237-
if (reason === "persistence cleared") {
238-
return { reason: `allowing another tab's "clear persistence" attempt to succeed` };
239-
} else if (reason === "site data cleared") {
240-
return { reason: `protecting against database corruption` };
241-
} else {
242-
return { reason: `unknown (code: vpfvjqeqvn)` };
237+
if (reason === "site data cleared") {
238+
return new DatabaseDeletedListenerAbortResult("protecting against database corruption");
239+
} else {
240+
return new DatabaseDeletedListenerContinueResult();
243241
}
244242
});
245243

packages/firestore/src/local/persistence.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,16 @@ export interface ReferenceDelegate {
100100

101101
export type DatabaseDeletedReason = "persistence cleared" | "site data cleared";
102102

103-
export const DatabaseDeletedListenerContinueResult: unique symbol = Symbol("DatabaseDeletedListenerContinueResult");
103+
export class DatabaseDeletedListenerContinueResult {
104+
readonly type = "continue" as const;
105+
}
104106

105-
export interface DatabaseDeletedListenerAbortResult {
106-
reason: string;
107+
export class DatabaseDeletedListenerAbortResult {
108+
readonly type = "abort" as const;
109+
constructor(readonly abortReason: string) {}
107110
}
108111

109-
export type DatabaseDeletedListenerResult = typeof DatabaseDeletedListenerContinueResult | DatabaseDeletedListenerAbortResult;
112+
export type DatabaseDeletedListenerResult = DatabaseDeletedListenerContinueResult | DatabaseDeletedListenerAbortResult;
110113

111114
export type DatabaseDeletedListener = (reason: DatabaseDeletedReason) => DatabaseDeletedListenerResult;
112115

packages/firestore/src/local/simple_db.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import {logDebug, logError, logWarn} from '../util/log';
2323
import {Deferred} from '../util/promise';
2424

2525
import {PersistencePromise} from './persistence_promise';
26-
import {
27-
type DatabaseDeletedListener,
28-
DatabaseDeletedListenerContinueResult
29-
} from './persistence';
26+
import {type DatabaseDeletedListener} from './persistence';
3027

3128
// References to `indexedDB` are guarded by SimpleDb.isAvailable() and getGlobal()
3229
/* eslint-disable no-restricted-globals */
@@ -371,11 +368,11 @@ export class SimpleDb {
371368
);
372369
if (this.databaseDeletedListener) {
373370
const listenerResult = this.databaseDeletedListener("site data cleared");
374-
if (listenerResult !== DatabaseDeletedListenerContinueResult) {
371+
if (listenerResult.type !== "continue") {
375372
throw new Error(
376373
`Refusing to open IndexedDB database after having been ` +
377374
`cleared, such as by clicking the "clear site data" button ` +
378-
`in a web browser: ${listenerResult.reason} (` +
375+
`in a web browser: ${listenerResult.abortReason} (` +
379376
`db.name=${db.name}, ` +
380377
`db.version=${db.version}, ` +
381378
`lastClosedDbVersion=${this.lastClosedDbVersion}, ` +
@@ -435,11 +432,11 @@ export class SimpleDb {
435432
);
436433
if (this.databaseDeletedListener) {
437434
const listenerResult = this.databaseDeletedListener("persistence cleared");
438-
if (listenerResult !== DatabaseDeletedListenerContinueResult) {
435+
if (listenerResult.type !== "continue") {
439436
logWarn(
440437
`Closing IndexedDB database "${db.name}" in response to ` +
441438
`"versionchange" event with newVersion===null: ` +
442-
`${listenerResult.reason}`
439+
`${listenerResult.abortReason}`
443440
);
444441
db.close();
445442
if (db === this.db) {

packages/firestore/test/unit/specs/spec_test_runner.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {
7777
SCHEMA_VERSION
7878
} from '../../../src/local/indexeddb_schema';
7979
import { SchemaConverter } from '../../../src/local/indexeddb_schema_converter';
80+
import { DatabaseDeletedListenerContinueResult } from '../../../src/local/persistence';
8081
import {
8182
DbPrimaryClientKey,
8283
DbPrimaryClientStore
@@ -365,8 +366,9 @@ abstract class TestRunner {
365366
this.eventManager.onLastRemoteStoreUnlisten =
366367
triggerRemoteStoreUnlisten.bind(null, this.syncEngine);
367368

368-
await this.persistence.setDatabaseDeletedListener(async () => {
369-
await this.shutdown();
369+
this.persistence.setDatabaseDeletedListener(() => {
370+
this.shutdown();
371+
return new DatabaseDeletedListenerContinueResult();
370372
});
371373

372374
this.started = true;

0 commit comments

Comments
 (0)