feat: add new rule for floating promise (#2726)

Co-authored-by: Himself65 <himself65@outlook.com>
This commit is contained in:
Peng Xiao 2023-06-08 17:54:25 +08:00 committed by GitHub
parent fda89b05e7
commit bedf838fe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 221 additions and 134 deletions

View File

@ -119,7 +119,7 @@ export function createApplicationMenu() {
{
label: 'Open log file',
click: async () => {
revealLogFile();
await revealLogFile();
},
},
{

View File

@ -62,7 +62,7 @@ test('on applyUpdate (from renderer), will trigger update', async () => {
db.update$.subscribe(onUpdate);
const sub = dbSubjects.externalUpdate.subscribe(onExternalUpdate);
db.applyUpdate(getTestUpdates(), 'renderer');
expect(onUpdate).toHaveBeenCalled(); // not yet updated
expect(onUpdate).toHaveBeenCalled();
sub.unsubscribe();
await db.destroy();
});

View File

@ -11,6 +11,7 @@ import {
merge,
} from 'rxjs';
import {
concatMap,
distinctUntilChanged,
filter,
ignoreElements,
@ -126,10 +127,8 @@ function startPollingSecondaryDB(db: WorkspaceSQLiteDB) {
switchMap(secondaryDB => {
return interval(300000).pipe(
startWith(0),
concatMap(() => secondaryDB.pull()),
tap({
next: () => {
secondaryDB.pull();
},
error: err => {
logger.error(`[ensureSQLiteDB] polling secondary db error`, err);
},

View File

@ -93,6 +93,7 @@ export class SecondaryWorkspaceSQLiteDB extends BaseSQLiteAdapter {
return await fn();
} catch (err) {
logger.error(err);
throw err;
} finally {
this.runCounter--;
if (this.runCounter === 0) {
@ -115,10 +116,10 @@ export class SecondaryWorkspaceSQLiteDB extends BaseSQLiteAdapter {
}
};
const onSelfUpdate = (update: Uint8Array, origin: YOrigin) => {
const onSelfUpdate = async (update: Uint8Array, origin: YOrigin) => {
// for self update from upstream, we need to push it to external DB
if (origin === 'upstream' && this.db) {
this.addUpdateToUpdateQueue(this.db, update);
await this.addUpdateToUpdateQueue(this.db, update);
}
if (origin === 'self') {
@ -135,12 +136,18 @@ export class SecondaryWorkspaceSQLiteDB extends BaseSQLiteAdapter {
this.yDoc.off('update', onSelfUpdate);
});
this.run(async () => {
this.run(() => {
// apply all updates from upstream
const upstreamUpdate = this.upstream.getDocAsUpdates();
// to initialize the yDoc, we need to apply all updates from the db
this.applyUpdate(upstreamUpdate, 'upstream');
});
})
.then(() => {
logger.debug('run success');
})
.catch(err => {
logger.error('run error', err);
});
}
applyUpdate = (data: Uint8Array, origin: YOrigin = 'upstream') => {

View File

@ -79,19 +79,19 @@ export class WorkspaceSQLiteDB extends BaseSQLiteAdapter {
};
override async addBlob(key: string, value: Uint8Array) {
const res = await super.addBlob(key, value);
this.update$.next();
const res = await super.addBlob(key, value);
return res;
}
override async deleteBlob(key: string) {
super.deleteBlob(key);
this.update$.next();
await super.deleteBlob(key);
}
override async addUpdateToSQLite(db: SqliteConnection, data: Uint8Array[]) {
super.addUpdateToSQLite(db, data);
this.update$.next();
await super.addUpdateToSQLite(db, data);
}
}

View File

@ -320,7 +320,7 @@ export async function moveDBFile(
filePath: newFilePath,
};
} catch (err) {
db?.destroy();
await db?.destroy();
logger.error('[moveDBFile]', err);
return {
error: 'UNKNOWN_ERROR',

View File

@ -50,7 +50,7 @@ export async function savePDFFileAs(
});
});
shell.openPath(filePath);
await shell.openPath(filePath);
return { filePath };
} catch (err) {
logger.error('savePDFFileAs', err);

View File

@ -29,7 +29,9 @@ if (!isSingleInstance) {
}
app.on('second-instance', () => {
restoreOrCreateWindow();
restoreOrCreateWindow().catch(e =>
console.error('Failed to restore or create window:', e)
);
});
app.on('open-url', async (_, _url) => {

View File

@ -28,10 +28,12 @@ export const getExchangeTokenParams = (code: string) => {
};
export function getGoogleOauthCode() {
shell.openExternal(oauthEndpoint);
return new Promise<ReturnType<typeof getExchangeTokenParams>>(
(resolve, reject) => {
shell.openExternal(oauthEndpoint).catch(e => {
logger.error('Failed to open external url', e);
reject(e);
});
const handleOpenUrl = async (_: any, url: string) => {
const mainWindow = BrowserWindow.getAllWindows().find(
w => !w.isDestroyed()

View File

@ -67,7 +67,9 @@ export const registerUpdater = async () => {
// register events for checkForUpdatesAndNotify
_autoUpdater.on('update-available', info => {
if (allowAutoUpdate) {
_autoUpdater?.downloadUpdate();
_autoUpdater?.downloadUpdate().catch(e => {
logger.error('Failed to download update', e);
});
logger.info('Update available, downloading...', info);
}
updaterSubjects.updateAvailable.next({

View File

@ -46,7 +46,9 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
});
setEditorFlags(blockSuiteWorkspace);
if (config.enablePreloading) {
initPageWithPreloading(page);
initPageWithPreloading(page).catch(err => {
logger.error('init page with preloading failed', err);
});
} else {
initEmptyPage(page);
}

View File

@ -67,7 +67,7 @@ export class AffineErrorBoundary extends Component<
pageId: error.workspace.meta.pageMetas[0].id,
},
})
.then(() => {
.finally(() => {
this.setState({ error: null });
});
}}

View File

@ -95,7 +95,7 @@ export const WorkspaceSettingDetail: React.FC<
const workspaceId = workspace.id;
useEffect(() => {
if (isAffine && isOwner) {
preload([QueryKey.getMembers, workspaceId], fetcher);
preload([QueryKey.getMembers, workspaceId], fetcher).catch(console.error);
}
}, [isAffine, isOwner, workspaceId]);
const containerRef = useRef<HTMLDivElement | null>(null);

View File

@ -46,8 +46,8 @@ const PublishPanelAffine: React.FC<PublishPanelAffineProps> = ({
const shareUrl = origin + '/public-workspace/' + workspace.id;
const t = useAFFiNEI18N();
const publishWorkspace = useToggleWorkspacePublish(workspace);
const copyUrl = useCallback(() => {
navigator.clipboard.writeText(shareUrl);
const copyUrl = useCallback(async () => {
await navigator.clipboard.writeText(shareUrl);
toast(t['Copied link to clipboard']());
}, [shareUrl, t]);

View File

@ -16,12 +16,12 @@ export const usePageHelper = (blockSuiteWorkspace: BlockSuiteWorkspace) => {
const createPageAndOpen = () => {
const page = createPage();
openPage(blockSuiteWorkspace.id, page.id);
return openPage(blockSuiteWorkspace.id, page.id);
};
const createEdgelessAndOpen = () => {
const page = createPage();
setPreferredMode(page.id, 'edgeless');
openPage(blockSuiteWorkspace.id, page.id);
return openPage(blockSuiteWorkspace.id, page.id);
};
const importFileAndOpen = async () => {
const { showImportModal } = await import('@blocksuite/blocks');

View File

@ -10,7 +10,9 @@ export const EditPage = () => {
const { jumpToPage } = useRouterHelper(router);
const onClickPage = useCallback(() => {
if (workspaceId && pageId) {
jumpToPage(workspaceId, pageId);
jumpToPage(workspaceId, pageId).catch(error => {
console.error(error);
});
}
}, [jumpToPage, pageId, workspaceId]);
return (

View File

@ -9,7 +9,7 @@ const LanguageMenuContent: FC = () => {
const i18n = useI18N();
const changeLanguage = useCallback(
(event: string) => {
i18n.changeLanguage(event);
void i18n.changeLanguage(event);
},
[i18n]
);

View File

@ -96,8 +96,8 @@ const LocalHeaderShareMenu: React.FC<BaseHeaderProps> = props => {
onClose={() => {
setOpen(false);
}}
onConform={() => {
onTransformWorkspace(
onConform={async () => {
await onTransformWorkspace(
WorkspaceFlavour.LOCAL,
WorkspaceFlavour.AFFINE,
props.workspace as LocalWorkspace

View File

@ -138,17 +138,14 @@ export const SyncUser = () => {
workspace as LocalWorkspace
);
// fixme(himself65): refactor this
router
.replace({
pathname: `/workspace/[workspaceId]/all`,
query: {
workspaceId: id,
},
})
.then(() => {
router.reload();
});
await router.replace({
pathname: `/workspace/[workspaceId]/all`,
query: {
workspaceId: id,
},
});
setOpen(false);
router.reload();
}}
/>
</>

View File

@ -63,9 +63,10 @@ export const TrashButtonGroup = () => {
workspaceId: workspace.id,
},
})
.then(() => {
blockSuiteWorkspace.removePage(pageId);
.catch(error => {
console.error(error);
});
blockSuiteWorkspace.removePage(pageId);
}}
onCancel={() => {
setOpen(false);

View File

@ -43,7 +43,7 @@ export const MessageCenter: FC = memo(function MessageCenter() {
})
.catch(() => {
setPopup(false);
onLogout();
return onLogout();
});
} else {
toast(Messages[event.detail.code].message);

View File

@ -64,9 +64,11 @@ export const PublishedResults: FC<PublishedResultsProps> = ({
<Command.Item
key={result.id}
onSelect={() => {
router.push(
`/public-workspace/${router.query.workspaceId}/${result.id}`
);
router
.push(
`/public-workspace/${router.query.workspaceId}/${result.id}`
)
.catch(err => console.error(err));
onClose();
}}
value={result.id}

View File

@ -71,7 +71,9 @@ export const Results: FC<ResultsProps> = ({
value={page.id}
onSelect={() => {
onClose();
jumpToPage(blockSuiteWorkspace.id, page.id);
jumpToPage(blockSuiteWorkspace.id, page.id).catch(
console.error
);
}}
>
<StyledListItem>
@ -95,7 +97,7 @@ export const Results: FC<ResultsProps> = ({
value={link.title}
onSelect={() => {
onClose();
router.push(link.href);
router.push(link.href).catch(console.error);
}}
>
<StyledListItem>
@ -133,7 +135,9 @@ export const Results: FC<ResultsProps> = ({
onSelect={() => {
onClose();
assertExists(blockSuiteWorkspace.id);
jumpToPage(blockSuiteWorkspace.id, result.id);
jumpToPage(blockSuiteWorkspace.id, result.id).catch(error =>
console.error(error)
);
}}
value={result.id}
>

View File

@ -1,8 +1,11 @@
import { DebugLogger } from '@affine/debug';
import type { BlobManager } from '@blocksuite/store';
import { useEffect, useMemo, useRef, useState } from 'react';
import type { BlockSuiteWorkspace } from '../shared';
const logger = new DebugLogger('useWorkspaceBlob');
export function useWorkspaceBlob(
blockSuiteWorkspace: BlockSuiteWorkspace
): BlobManager {
@ -21,14 +24,19 @@ export function useWorkspaceBlobImage(
setBlob(null);
return;
}
blobManager?.get(key).then(blob => {
if (controller.signal.aborted) {
return;
}
if (blob) {
setBlob(blob);
}
});
blobManager
?.get(key)
.then(blob => {
if (controller.signal.aborted) {
return;
}
if (blob) {
setBlob(blob);
}
})
.catch(err => {
logger.error('Failed to get blob', err);
});
return () => {
controller.abort();
};

View File

@ -204,7 +204,9 @@ export const WorkspaceLayout: FC<PropsWithChildren> =
useEffect(() => {
document.documentElement.lang = i18n.language;
// todo(himself65): this is a hack, we should use a better way to set the language
setUpLanguage(i18n);
setUpLanguage(i18n)?.catch(error => {
console.error(error);
});
}, [i18n]);
useTrackRouterHistoryEffect();
const currentWorkspaceId = useAtomValue(rootCurrentWorkspaceIdAtom);
@ -247,7 +249,9 @@ export const WorkspaceLayout: FC<PropsWithChildren> =
logger.info('mount first data:', items);
}
fetch();
fetch().catch(e => {
logger.error('fetch error:', e);
});
return () => {
controller.abort();
logger.info('unmount');

View File

@ -34,7 +34,7 @@ export const NotfoundPage = () => {
<Button
shape="round"
onClick={() => {
router.push('/');
router.push('/').catch(err => console.error(err));
}}
>
{t['Back Home']()}

View File

@ -44,7 +44,7 @@ const InvitePage: NextPageWithLayout = () => {
inviteData.workspace_id,
WorkspaceSubPath.ALL,
RouteLogic.REPLACE
);
).catch(err => console.error(err));
}}
>
Go to Workspace
@ -64,7 +64,7 @@ const InvitePage: NextPageWithLayout = () => {
<Button
shape="round"
onClick={() => {
router.replace(`/`);
router.replace(`/`).catch(err => console.error(err));
}}
>
Back to Home

View File

@ -26,7 +26,7 @@ const AllPage: NextPageWithLayout = () => {
if (newTab) {
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
} else {
jumpToPage(currentWorkspace.id, pageId);
jumpToPage(currentWorkspace.id, pageId).catch(console.error);
}
},
[currentWorkspace, jumpToPage]

View File

@ -23,7 +23,7 @@ const SharedPages: NextPageWithLayout = () => {
if (newTab) {
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
} else {
jumpToPage(currentWorkspace.id, pageId);
jumpToPage(currentWorkspace.id, pageId).catch(console.error);
}
},
[currentWorkspace, jumpToPage]

View File

@ -24,7 +24,9 @@ const TrashPage: NextPageWithLayout = () => {
if (newTab) {
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
} else {
jumpToPage(currentWorkspace.id, pageId);
jumpToPage(currentWorkspace.id, pageId).catch(error => {
console.error(error);
});
}
},
[currentWorkspace, jumpToPage]

View File

@ -129,7 +129,9 @@ export const AllWorkspaceModals = (): ReactElement => {
workspace => {
setOpenWorkspacesModal(false);
setCurrentWorkspaceId(workspace.id);
jumpToSubPath(workspace.id, WorkspaceSubPath.ALL);
jumpToSubPath(workspace.id, WorkspaceSubPath.ALL).catch(error => {
console.error(error);
});
},
[jumpToSubPath, setCurrentWorkspaceId, setOpenWorkspacesModal]
)}
@ -137,7 +139,11 @@ export const AllWorkspaceModals = (): ReactElement => {
workspace => {
setOpenWorkspacesModal(false);
setCurrentWorkspaceId(workspace.id);
jumpToSubPath(workspace.id, WorkspaceSubPath.SETTING);
jumpToSubPath(workspace.id, WorkspaceSubPath.SETTING).catch(
error => {
console.error(error);
}
);
},
[jumpToSubPath, setCurrentWorkspaceId, setOpenWorkspacesModal]
)}

View File

@ -26,9 +26,13 @@ function rpcToObservable<
subscriber.complete();
return () => {};
}
handler?.().then(t => {
subscriber.next(t);
});
handler?.()
.then(t => {
subscriber.next(t);
})
.catch(err => {
subscriber.error(err);
});
return event(t => {
subscriber.next(t);
});

View File

@ -92,20 +92,25 @@ const BlockSuiteEditorImpl = (props: EditorProps): ReactElement => {
return;
}
if (page.awarenessStore.getFlag('enable_block_hub')) {
editor.createBlockHub().then(blockHub => {
if (blockHubRef.current) {
blockHubRef.current.remove();
}
blockHubRef.current = blockHub;
const toolWrapper = document.querySelector('#toolWrapper');
if (!toolWrapper) {
console.warn(
'toolWrapper not found, block hub feature will not be available.'
);
} else {
toolWrapper.appendChild(blockHub);
}
});
editor
.createBlockHub()
.then(blockHub => {
if (blockHubRef.current) {
blockHubRef.current.remove();
}
blockHubRef.current = blockHub;
const toolWrapper = document.querySelector('#toolWrapper');
if (!toolWrapper) {
console.warn(
'toolWrapper not found, block hub feature will not be available.'
);
} else {
toolWrapper.appendChild(blockHub);
}
})
.catch(err => {
console.error(err);
});
}
container.appendChild(editor);

View File

@ -52,8 +52,8 @@ export const AffineSharePage: FC<ShareMenuProps> = props => {
const onClickCreateLink = useCallback(() => {
setIsPublic(true);
}, [setIsPublic]);
const onClickCopyLink = useCallback(() => {
navigator.clipboard.writeText(sharingUrl);
const onClickCopyLink = useCallback(async () => {
await navigator.clipboard.writeText(sharingUrl);
toast(t['Copied link to clipboard']());
}, [sharingUrl, t]);
const onDisablePublic = useCallback(() => {

View File

@ -32,8 +32,8 @@ describe('GraphQL fetcher', () => {
const gql = gqlFetcherFactory('https://example.com/graphql');
it('should send POST request to given endpoint', () => {
gql(
it('should send POST request to given endpoint', async () => {
await gql(
// @ts-expect-error variables is actually optional
{ query }
);
@ -44,8 +44,8 @@ describe('GraphQL fetcher', () => {
expect(ctx.method).toBe('POST');
});
it('should send with correct graphql JSON body', () => {
gql({
it('should send with correct graphql JSON body', async () => {
await gql({
query,
// @ts-expect-error forgive the fake variables
variables: { a: 1, b: '2', c: { d: false } },
@ -63,8 +63,8 @@ describe('GraphQL fetcher', () => {
`);
});
it('should correctly ignore nil variables', () => {
gql({
it('should correctly ignore nil variables', async () => {
await gql({
query,
// @ts-expect-error forgive the fake variables
variables: { a: false, b: null, c: undefined },
@ -74,7 +74,7 @@ describe('GraphQL fetcher', () => {
'"{\\"query\\":\\"query { field }\\",\\"variables\\":{\\"a\\":false,\\"b\\":null},\\"operationName\\":\\"query\\"}"'
);
gql({
await gql({
query,
// @ts-expect-error forgive the fake variables
variables: { a: false, b: null, c: undefined },

View File

@ -68,15 +68,23 @@ const standardizeLocale = (language: string) => {
export const createI18n = () => {
const i18n = i18next.createInstance();
i18n.use(initReactI18next).init({
lng: 'en',
fallbackLng,
debug: false,
resources,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
});
i18n
.use(initReactI18next)
.init({
lng: 'en',
fallbackLng,
debug: false,
resources,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
})
.then(() => {
console.info('i18n init success');
})
.catch(() => {
console.error('i18n init failed');
});
i18n.on('languageChanged', lng => {
localStorage.setItem(STORAGE_KEY, lng);

View File

@ -47,9 +47,9 @@ const getBaseTranslations = async (baseLanguage: { tag: string }) => {
const main = async () => {
try {
fs.access(RES_DIR);
await fs.access(RES_DIR);
} catch (error) {
fs.mkdir(RES_DIR);
fs.mkdir(RES_DIR).catch(console.error);
console.log('Create directory', RES_DIR);
}
console.log('Loading project languages...');
@ -149,4 +149,7 @@ const main = async () => {
console.log('Done');
};
main();
main().catch(e => {
console.error(e);
process.exit(1);
});

View File

@ -152,4 +152,7 @@ const main = async () => {
// TODO send notification
};
main();
main().catch(e => {
console.error(e);
process.exit(1);
});

View File

@ -40,7 +40,10 @@ export function definePlugin<ID extends string>(
blockSuiteAdapter
.load()
.then(({ default: adapter }) => updateAdapter(adapter));
.then(({ default: adapter }) => updateAdapter(adapter))
.catch(err => {
pluginLogger.error('[definePlugin] blockSuiteAdapter error', err);
});
if (import.meta.webpackHot) {
blockSuiteAdapter.hotModuleReload(async _ => {
@ -64,7 +67,10 @@ export function definePlugin<ID extends string>(
uiAdapterLoader
.load()
.then(({ default: adapter }) => updateAdapter(adapter));
.then(({ default: adapter }) => updateAdapter(adapter))
.catch(err => {
pluginLogger.error('[definePlugin] blockSuiteAdapter error', err);
});
if (import.meta.webpackHot) {
uiAdapterLoader.hotModuleReload(async _ => {

View File

@ -37,6 +37,9 @@ fetch(new URL('@affine-test/fixtures/large-image.png', import.meta.url))
},
frameId
);
})
.catch(err => {
console.error('Failed to load large-image.png', err);
});
export const Default = () => {

View File

@ -54,6 +54,10 @@ fetch(new URL('@affine-test/fixtures/smile.png', import.meta.url))
new Blob([buffer], { type: 'image/png' })
);
avatarBlockSuiteWorkspace.meta.setAvatar(id);
})
.catch(() => {
// just ignore
console.error('Failed to load smile.png');
});
export const BlobExample: StoryFn<WorkspaceAvatarProps> = props => {

View File

@ -1,3 +1,4 @@
import { DebugLogger } from '@affine/debug';
import type { BlobStorage } from '@blocksuite/store';
import { createIndexeddbStorage } from '@blocksuite/store';
import { openDB } from 'idb';
@ -19,6 +20,8 @@ interface AffineBlob extends DBSchema {
// todo: migrate blob storage from `createIndexeddbStorage`
}
const logger = new DebugLogger('affine:blob');
export const createAffineBlobStorage = (
workspaceId: string,
workspaceApis: ReturnType<typeof createWorkspaceApis>
@ -29,19 +32,25 @@ export const createAffineBlobStorage = (
db.createObjectStore('uploading', { keyPath: 'key' });
},
});
dbPromise.then(async db => {
const t = db.transaction('uploading', 'readwrite').objectStore('uploading');
await t.getAll().then(blobs =>
blobs.map(({ arrayBuffer, type }) =>
workspaceApis.uploadBlob(workspaceId, arrayBuffer, type).then(key => {
const t = db
.transaction('uploading', 'readwrite')
.objectStore('uploading');
return t.delete(key);
})
)
);
});
dbPromise
.then(async db => {
const t = db
.transaction('uploading', 'readwrite')
.objectStore('uploading');
await t.getAll().then(blobs =>
blobs.map(({ arrayBuffer, type }) =>
workspaceApis.uploadBlob(workspaceId, arrayBuffer, type).then(key => {
const t = db
.transaction('uploading', 'readwrite')
.objectStore('uploading');
return t.delete(key);
})
)
);
})
.catch(err => {
logger.error('[createAffineBlobStorage] dbPromise error', err);
});
return {
crud: {
get: async key => {
@ -60,19 +69,21 @@ export const createAffineBlobStorage = (
.transaction('uploading', 'readwrite')
.objectStore('uploading');
let uploaded = false;
t.put({
await t.put({
key,
arrayBuffer,
type: value.type,
}).then(() => {
// delete the uploading blob after uploaded
if (uploaded) {
const t = db
.transaction('uploading', 'readwrite')
.objectStore('uploading');
t.delete(key);
}
});
// delete the uploading blob after uploaded
if (uploaded) {
const t = db
.transaction('uploading', 'readwrite')
.objectStore('uploading');
// don't await here, we don't care if it's deleted
t.delete(key).catch(err => {
logger.error('[createAffineBlobStorage] delete error', err);
});
}
await Promise.all([
storage.crud.set(key, value),
workspaceApis

View File

@ -28,7 +28,7 @@ describe('crud', () => {
});
test('delete not exist', async () => {
expect(async () =>
await expect(async () =>
CRUD.delete({
id: 'not_exist',
flavour: WorkspaceFlavour.LOCAL,

View File

@ -197,7 +197,7 @@ describe('indexeddb provider', () => {
test('cleanup when connecting', async () => {
const provider = createIndexedDBProvider(workspace.id, workspace.doc);
provider.connect();
expect(() => provider.cleanup()).rejects.toThrowError(
await expect(() => provider.cleanup()).rejects.toThrowError(
CleanupWhenConnectingError
);
await provider.whenSynced;
@ -259,7 +259,7 @@ describe('indexeddb provider', () => {
yDoc.getMap().set('foo', 'bar');
const persistence = new IndexeddbPersistence('test', yDoc);
await persistence.whenSynced;
persistence.destroy();
await persistence.destroy();
}
{
const yDoc = new Doc();
@ -274,7 +274,7 @@ describe('indexeddb provider', () => {
indexedDB.databases = vi.fn(async () => {
throw new Error('not supported');
});
expect(indexedDB.databases).rejects.toThrow('not supported');
await expect(indexedDB.databases).rejects.toThrow('not supported');
const yDoc = new Doc();
expect(indexedDB.databases).toBeCalledTimes(1);
const provider = createIndexedDBProvider('test', yDoc);

View File

@ -286,7 +286,7 @@ export const createIndexedDBProvider = (
if (connected) {
throw new CleanupWhenConnectingError();
}
(await dbPromise).delete('workspace', id);
await (await dbPromise).delete('workspace', id);
},
whenSynced: Promise.resolve(),
get connected() {