jest-leak-detector
Advanced tools
Comparing version 29.1.2 to 29.2.0
@@ -12,3 +12,3 @@ /** | ||
private _isReferenceBeingHeld; | ||
private _finalizationRegistry?; | ||
private readonly _finalizationRegistry?; | ||
constructor(value: unknown); | ||
@@ -15,0 +15,0 @@ isLeaking(): Promise<boolean>; |
@@ -7,53 +7,37 @@ 'use strict'; | ||
exports.default = void 0; | ||
function _util() { | ||
const data = require('util'); | ||
_util = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _v() { | ||
const data = require('v8'); | ||
_v = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _vm() { | ||
const data = require('vm'); | ||
_vm = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestGetType() { | ||
const data = require('jest-get-type'); | ||
_jestGetType = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _prettyFormat() { | ||
const data = require('pretty-format'); | ||
_prettyFormat = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
/** | ||
@@ -66,8 +50,7 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
/// <reference lib="es2021.WeakRef" /> | ||
const tick = (0, _util().promisify)(setImmediate); | ||
class LeakDetector { | ||
_isReferenceBeingHeld; | ||
_finalizationRegistry; | ||
constructor(value) { | ||
@@ -83,32 +66,32 @@ if ((0, _jestGetType().isPrimitive)(value)) { | ||
); | ||
} // When `_finalizationRegistry` is GCed the callback we set will no longer be called, | ||
} | ||
// When `_finalizationRegistry` is GCed the callback we set will no longer be called, | ||
this._finalizationRegistry = new FinalizationRegistry(() => { | ||
this._isReferenceBeingHeld = false; | ||
}); | ||
this._finalizationRegistry.register(value, undefined); | ||
this._isReferenceBeingHeld = true; | ||
this._isReferenceBeingHeld = true; // Ensure value is not leaked by the closure created by the "weak" callback. | ||
// Ensure value is not leaked by the closure created by the "weak" callback. | ||
value = null; | ||
} | ||
async isLeaking() { | ||
this._runGarbageCollector(); // wait some ticks to allow GC to run properly, see https://github.com/nodejs/node/issues/34636#issuecomment-669366235 | ||
this._runGarbageCollector(); | ||
// wait some ticks to allow GC to run properly, see https://github.com/nodejs/node/issues/34636#issuecomment-669366235 | ||
for (let i = 0; i < 10; i++) { | ||
await tick(); | ||
} | ||
return this._isReferenceBeingHeld; | ||
} | ||
_runGarbageCollector() { | ||
// @ts-expect-error: not a function on `globalThis` | ||
const isGarbageCollectorHidden = globalThis.gc == null; // GC is usually hidden, so we have to expose it before running. | ||
const isGarbageCollectorHidden = globalThis.gc == null; | ||
// GC is usually hidden, so we have to expose it before running. | ||
(0, _v().setFlagsFromString)('--expose-gc'); | ||
(0, _vm().runInNewContext)('gc')(); // The GC was not initially exposed, so let's hide it again. | ||
(0, _vm().runInNewContext)('gc')(); | ||
// The GC was not initially exposed, so let's hide it again. | ||
if (isGarbageCollectorHidden) { | ||
@@ -119,3 +102,2 @@ (0, _v().setFlagsFromString)('--no-expose-gc'); | ||
} | ||
exports.default = LeakDetector; |
{ | ||
"name": "jest-leak-detector", | ||
"version": "29.1.2", | ||
"version": "29.2.0", | ||
"repository": { | ||
@@ -20,4 +20,4 @@ "type": "git", | ||
"dependencies": { | ||
"jest-get-type": "^29.0.0", | ||
"pretty-format": "^29.1.2" | ||
"jest-get-type": "^29.2.0", | ||
"pretty-format": "^29.2.0" | ||
}, | ||
@@ -30,3 +30,3 @@ "engines": { | ||
}, | ||
"gitHead": "3c31dd619e8c022cde53f40fa12ea2a67f4752ce" | ||
"gitHead": "ee5b37a4f4433afcfffb0356cea47739d8092287" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5576
109
Updatedjest-get-type@^29.2.0
Updatedpretty-format@^29.2.0