DEV: Resolve and prevent user fixture changes leaking between tests (#23898)

- Introduces a `deepFreeze` helper to block any mutations to the current-user fixture

- Add `cloneJSON` to any places which were previously causing mutations
This commit is contained in:
David Taylor
2023-10-11 13:46:06 +01:00
committed by GitHub
parent b77b0ee1c8
commit 6970c7dc13
5 changed files with 31 additions and 5 deletions

View File

@ -59,3 +59,19 @@ export function deepEqual(obj1, obj2) {
export function cloneJSON(obj) {
return JSON.parse(JSON.stringify(obj));
}
export function deepFreeze(object) {
// Retrieve the property names defined on object
const propNames = Reflect.ownKeys(object);
// Freeze properties before freezing self
for (const name of propNames) {
const value = object[name];
if ((value && typeof value === "object") || typeof value === "function") {
deepFreeze(value);
}
}
return Object.freeze(object);
}