fix(testing): stabilize workspace test dependencies
This commit is contained in:
parent
c80016c8c2
commit
128207ac21
@ -6,6 +6,7 @@
|
||||
"node": "20.x"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "corepack pnpm --dir ../.. --filter @bytelyst/api-client --filter @bytelyst/config --filter @bytelyst/errors --filter @bytelyst/logger --filter @bytelyst/telemetry-client build",
|
||||
"dev": "next dev --port 3003",
|
||||
"build": "next build --webpack",
|
||||
"start": "next start --port 3003",
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"pretest": "corepack pnpm --dir ../.. --filter @bytelyst/storage build",
|
||||
"build": "tsc",
|
||||
"test": "vitest run"
|
||||
},
|
||||
|
||||
@ -33,6 +33,8 @@ const LAST_SYNC_KEY = 'lastSync';
|
||||
export class SyncEngineImpl implements SyncEngine {
|
||||
private config: SyncEngineConfig;
|
||||
private status: SyncStatus = 'idle';
|
||||
private queueLength = 0;
|
||||
private lastSyncAt?: string;
|
||||
private statusListeners: Set<SyncStatusCallback> = new Set();
|
||||
private connectivityListeners: (() => void)[] = [];
|
||||
|
||||
@ -78,12 +80,8 @@ export class SyncEngineImpl implements SyncEngine {
|
||||
}
|
||||
|
||||
await this.saveQueue(existingQueue);
|
||||
this.queueLength = existingQueue.length;
|
||||
this.updateStatus('idle');
|
||||
|
||||
// Auto-flush if online
|
||||
if (this.isOnline()) {
|
||||
await this.flush();
|
||||
}
|
||||
}
|
||||
|
||||
async delete(entity: EntityName, id: string): Promise<void> {
|
||||
@ -115,6 +113,7 @@ export class SyncEngineImpl implements SyncEngine {
|
||||
}
|
||||
|
||||
await this.setLastSyncTime(result.timestamp);
|
||||
this.lastSyncAt = result.timestamp;
|
||||
} catch (error) {
|
||||
result.success = false;
|
||||
this.updateStatus('error', error instanceof Error ? error.message : 'Unknown error');
|
||||
@ -152,6 +151,7 @@ export class SyncEngineImpl implements SyncEngine {
|
||||
|
||||
private async saveQueue(queue: SyncItem[]): Promise<void> {
|
||||
await this.config.storage.setItem(QUEUE_KEY, queue);
|
||||
this.queueLength = queue.length;
|
||||
}
|
||||
|
||||
private async pushQueue(): Promise<SyncResult> {
|
||||
@ -279,7 +279,7 @@ export class SyncEngineImpl implements SyncEngine {
|
||||
private setupConnectivityDetection(): void {
|
||||
if (typeof window !== 'undefined' && window.addEventListener) {
|
||||
const handleOnline = () => {
|
||||
this.flush();
|
||||
void this.flush();
|
||||
this.connectivityListeners.forEach(cb => cb());
|
||||
};
|
||||
|
||||
@ -296,7 +296,10 @@ export class SyncEngineImpl implements SyncEngine {
|
||||
|
||||
async flush(): Promise<void> {
|
||||
if (this.status === 'syncing') return;
|
||||
await this.pushQueue();
|
||||
const result = await this.pushQueue();
|
||||
if (result.success && result.errors === 0) {
|
||||
this.updateStatus('idle');
|
||||
}
|
||||
}
|
||||
|
||||
// ───────────────────────────────────────────────────────────────────────────
|
||||
@ -304,14 +307,14 @@ export class SyncEngineImpl implements SyncEngine {
|
||||
// ───────────────────────────────────────────────────────────────────────────
|
||||
|
||||
getQueueLength(): number {
|
||||
// Async getQueue but we need sync return - use cached value or 0
|
||||
return 0; // Consumer should use getStatus() for accurate count
|
||||
return this.queueLength;
|
||||
}
|
||||
|
||||
getStatus(): SyncStatusInfo {
|
||||
return {
|
||||
status: this.status,
|
||||
queueLength: 0, // Will be populated async
|
||||
queueLength: this.queueLength,
|
||||
lastSyncAt: this.lastSyncAt,
|
||||
};
|
||||
}
|
||||
|
||||
@ -324,7 +327,8 @@ export class SyncEngineImpl implements SyncEngine {
|
||||
this.status = status;
|
||||
const info: SyncStatusInfo = {
|
||||
status,
|
||||
queueLength: 0,
|
||||
queueLength: this.queueLength,
|
||||
lastSyncAt: this.lastSyncAt,
|
||||
lastError: error,
|
||||
};
|
||||
this.statusListeners.forEach(cb => cb(info));
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"pretest": "corepack pnpm --dir ../.. --filter @bytelyst/fastify-core build",
|
||||
"build": "tsc",
|
||||
"test": "vitest run"
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user