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