|
| 1 | +/** |
| 2 | + * ObjectQL LocalStorage Driver TCK Tests |
| 3 | + * Copyright (c) 2026-present ObjectStack Inc. |
| 4 | + * |
| 5 | + * This source code is licensed under the MIT license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * LocalStorage Driver TCK (Technology Compatibility Kit) Tests |
| 11 | + * |
| 12 | + * This test suite verifies that the LocalStorage driver passes all TCK requirements. |
| 13 | + */ |
| 14 | + |
| 15 | +import { runDriverTCK } from '@objectql/driver-tck'; |
| 16 | +import { LocalStorageDriver } from '../src'; |
| 17 | + |
| 18 | +// Mock localStorage for Node.js environment |
| 19 | +class LocalStorageMock { |
| 20 | + private store: Map<string, string> = new Map(); |
| 21 | + |
| 22 | + getItem(key: string): string | null { |
| 23 | + return this.store.get(key) || null; |
| 24 | + } |
| 25 | + |
| 26 | + setItem(key: string, value: string): void { |
| 27 | + this.store.set(key, value); |
| 28 | + } |
| 29 | + |
| 30 | + removeItem(key: string): void { |
| 31 | + this.store.delete(key); |
| 32 | + } |
| 33 | + |
| 34 | + clear(): void { |
| 35 | + this.store.clear(); |
| 36 | + } |
| 37 | + |
| 38 | + get length(): number { |
| 39 | + return this.store.size; |
| 40 | + } |
| 41 | + |
| 42 | + key(index: number): string | null { |
| 43 | + const keys = Array.from(this.store.keys()); |
| 44 | + return keys[index] || null; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +describe('LocalStorageDriver TCK Compliance', () => { |
| 49 | + let driver: LocalStorageDriver; |
| 50 | + let mockStorage: LocalStorageMock; |
| 51 | + |
| 52 | + runDriverTCK( |
| 53 | + () => { |
| 54 | + mockStorage = new LocalStorageMock(); |
| 55 | + (global as any).localStorage = mockStorage; |
| 56 | + |
| 57 | + driver = new LocalStorageDriver({ |
| 58 | + namespace: 'tck_test' |
| 59 | + }); |
| 60 | + return driver; |
| 61 | + }, |
| 62 | + { |
| 63 | + skip: { |
| 64 | + aggregations: true, // LocalStorage driver doesn't support aggregations |
| 65 | + transactions: true, // LocalStorage doesn't support transactions |
| 66 | + joins: true, // LocalStorage doesn't support joins |
| 67 | + }, |
| 68 | + timeout: 30000, |
| 69 | + hooks: { |
| 70 | + beforeEach: async () => { |
| 71 | + // Clear localStorage |
| 72 | + if (mockStorage) { |
| 73 | + mockStorage.clear(); |
| 74 | + } |
| 75 | + }, |
| 76 | + afterEach: async () => { |
| 77 | + // Cleanup handled in beforeEach |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + ); |
| 82 | +}); |
0 commit comments