16 lines
470 B
TypeScript
16 lines
470 B
TypeScript
|
|
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}`;
|
||
|
|
},
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|