mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 00:41:16 +08:00
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:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user