Skip to content

Commit ddeea67

Browse files
committed
Fix nuxt tests
1 parent 621a81e commit ddeea67

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎.changeset/core-extension-0-5-2.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'@powersync/react-native': patch
66
'@powersync/shared-internals': patch
77
'@powersync/tauri-plugin': patch
8+
'@powersync/nuxt': patch
89
'tauri-plugin-powersync': patch
910
---
1011

‎packages/nuxt/src/runtime/composables/usePowerSyncInspectorDiagnostics.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ref, computed, readonly, onMounted, onUnmounted } from 'vue';
1111
import { computedAsync } from '@vueuse/core';
1212
import { usePowerSyncInspector } from './usePowerSyncInspector';
1313
import type { NuxtDatabaseImplementation } from '../utils/NuxtPowerSyncDatabase';
14+
import { SyncStatusSnapshot } from '@powersync/shared-internals';
1415

1516
// queries
1617
const BUCKETS_QUERY = `
@@ -308,17 +309,21 @@ export function usePowerSyncInspectorDiagnostics(): UsePowerSyncInspectorDiagnos
308309

309310
async function refreshState() {
310311
if (db.value) {
311-
const { synced_at } = await db.value.get<{ synced_at: string | null }>(
312-
'SELECT powersync_last_synced_at() as synced_at'
312+
// FIXME: This relies on internal core extension APIs, why can't this use the
313+
// current sync status?
314+
const { status: rawStatus } = await db.value.get<{ status: string }>(
315+
'SELECT powersync_offline_sync_status() as status'
313316
);
317+
const status = new SyncStatusSnapshot(JSON.parse(rawStatus), null);
318+
const hasSyned = status.hasSynced;
314319

315-
uploadQueueStats.value = await db.value?.getUploadQueueStats(true);
320+
uploadQueueStats.value = await db.value.getUploadQueueStats(true);
316321

317-
if (synced_at != null && !syncStatus.value?.downloading) {
322+
if (hasSyned && !syncStatus.value.downloading) {
318323
// These are potentially expensive queries - do not run during initial sync
319324
bucketRows.value = await db.value.getAll(BUCKETS_QUERY);
320325
tableRows.value = await db.value.getAll(TABLES_QUERY);
321-
} else if (synced_at != null) {
326+
} else if (hasSyned) {
322327
// Busy downloading, but have already synced once
323328
bucketRows.value = await db.value.getAll(BUCKETS_QUERY_FAST);
324329
// Load tables if we haven't yet

‎packages/nuxt/tests/composables/usePowerSyncInspectorDiagnostics.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ describe('usePowerSyncInspectorDiagnostics', () => {
7777

7878
// Verify refreshState was called (it queries synced_at and bucket data)
7979
const getCalls = getSpy.mock.calls;
80-
const hasSyncedAtQuery = getCalls.some((call) => call[0]?.includes('powersync_last_synced_at'));
81-
expect(hasSyncedAtQuery).toBe(true);
80+
const hasStatusQuery = getCalls.some((call) => call[0]?.includes('powersync_offline_sync_status'));
81+
expect(hasStatusQuery).toBe(true);
8282
});
8383

8484
it('should trigger refreshState when onChangeWithCallback fires', async () => {

0 commit comments

Comments
 (0)