UNPKG

@fast-check/poisoning

Version:

Set of utilities to ease detection and revert of poisoning

37 lines 1.56 kB
//#region src/main.d.ts /** * Some extra options for {@link restoreGlobals} and {@link assertNoPoisoning} */ type ExtraOptions = { /** * Discard any changes occuring on any root matching the regex or any of its children. * Elements being child of several roots must have all their roots ignored not be tracked. * * eg.: If pattern is /^_/ then any change of globalThis._ignored or children of it will be omitted. * Except changes on prop if globalThis._ignored.prop === globalThis.nonIgnored.prop as prop is part of a tracked root too. * * Remark: a root is a property directly accessible from globalThis */ ignoredRootRegex?: RegExp; }; /** * Restore all globals as they were when first importing this package. * * Remark: At least, it attempts to do so */ declare function restoreGlobals(options?: ExtraOptions): void; /** * Check whether or not some globlas have been poisoned by some code. * * Poisoned being one of the following changes: * - a new entity is accessible directly or indirectly from `globalThis` * - an entity referenced directly or indirectly on `globalThis` has been altered * - an entity referenced directly or indirectly on `globalThis` has been dropped * * Here are some examples of such changes: * - someone added a new global on `window` (browser case) or `global` (node case) or modern `globalThis` (everywhere) * - someone changed `Array.prototype.map` into another function */ declare function assertNoPoisoning(options?: ExtraOptions): void; //#endregion export { ExtraOptions, assertNoPoisoning, restoreGlobals };