42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
|
|
import type { PlanStateStore } from '../../src/scenario/engine/IndexedDbPlanStore.js';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* In-memory PlanStateStore that survives across RudderClient instances — lets a
|
||
|
|
* test simulate a page reload: drive scenario A on one client, construct a fresh
|
||
|
|
* client sharing the same `backing`, call `scenarios.restore()`, and assert the
|
||
|
|
* run resumed mid-DAG.
|
||
|
|
*/
|
||
|
|
export function createMemoryPlanStore(backing: { value: string | null } = { value: null }): PlanStateStore {
|
||
|
|
return {
|
||
|
|
get state() {
|
||
|
|
return backing.value;
|
||
|
|
},
|
||
|
|
set state(v: string | null) {
|
||
|
|
backing.value = v;
|
||
|
|
},
|
||
|
|
async load() {
|
||
|
|
/* state already in `backing` */
|
||
|
|
},
|
||
|
|
async save(s: string | null) {
|
||
|
|
backing.value = s;
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Deterministic, collision-free crypto.randomUUID() stub for scenario run IDs. */
|
||
|
|
export function stubDeterministicUuid(): void {
|
||
|
|
let n = 0;
|
||
|
|
const existing = (globalThis as { crypto?: Crypto }).crypto ?? ({} as Crypto);
|
||
|
|
Object.defineProperty(globalThis, 'crypto', {
|
||
|
|
configurable: true,
|
||
|
|
value: {
|
||
|
|
...existing,
|
||
|
|
randomUUID: () => {
|
||
|
|
n += 1;
|
||
|
|
const hex = n.toString(16).padStart(12, '0');
|
||
|
|
return `00000000-0000-4000-a000-${hex}` as `${string}-${string}-${string}-${string}-${string}`;
|
||
|
|
},
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|