This commit is contained in:
parent
7a9bf3199a
commit
c294e2e9ae
5702 changed files with 465039 additions and 34 deletions
22
node_modules/jest-leak-detector/LICENSE
generated
vendored
Normal file
22
node_modules/jest-leak-detector/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
Copyright Contributors to the Jest project.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
29
node_modules/jest-leak-detector/README.md
generated
vendored
Normal file
29
node_modules/jest-leak-detector/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# jest-leak-detector
|
||||
|
||||
Module for verifying whether an object has been garbage collected or not.
|
||||
|
||||
Internally creates a weak reference to the object, and forces garbage collection to happen. If the reference is gone, it meant no one else was pointing to the object.
|
||||
|
||||
## Example
|
||||
|
||||
```javascript
|
||||
(async function () {
|
||||
let reference = {};
|
||||
let isLeaking;
|
||||
|
||||
const detector = new LeakDetector(reference, {
|
||||
shouldGenerateV8HeapSnapshot: true,
|
||||
});
|
||||
|
||||
// Reference is held in memory.
|
||||
isLeaking = await detector.isLeaking();
|
||||
console.log(isLeaking); // true
|
||||
|
||||
// We destroy the only reference to the object.
|
||||
reference = null;
|
||||
|
||||
// Reference is gone.
|
||||
isLeaking = await detector.isLeaking();
|
||||
console.log(isLeaking); // false
|
||||
})();
|
||||
```
|
||||
22
node_modules/jest-leak-detector/build/index.d.ts
generated
vendored
Normal file
22
node_modules/jest-leak-detector/build/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
declare class LeakDetector {
|
||||
private _isReferenceBeingHeld;
|
||||
private _shouldGenerateV8HeapSnapshot;
|
||||
private readonly _finalizationRegistry?;
|
||||
constructor(value: unknown, opt?: LeakDetectorOptions);
|
||||
isLeaking(): Promise<boolean>;
|
||||
private _runGarbageCollector;
|
||||
}
|
||||
export default LeakDetector;
|
||||
|
||||
declare interface LeakDetectorOptions {
|
||||
shouldGenerateV8HeapSnapshot: boolean;
|
||||
}
|
||||
|
||||
export {};
|
||||
123
node_modules/jest-leak-detector/build/index.js
generated
vendored
Normal file
123
node_modules/jest-leak-detector/build/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/*!
|
||||
* /**
|
||||
* * Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* *
|
||||
* * This source code is licensed under the MIT license found in the
|
||||
* * LICENSE file in the root directory of this source tree.
|
||||
* * /
|
||||
*/
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ "use strict";
|
||||
var __webpack_exports__ = {};
|
||||
// This entry needs to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
|
||||
(() => {
|
||||
var exports = __webpack_exports__;
|
||||
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({
|
||||
value: true
|
||||
}));
|
||||
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 _getType() {
|
||||
const data = require("@jest/get-type");
|
||||
_getType = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _prettyFormat() {
|
||||
const data = require("pretty-format");
|
||||
_prettyFormat = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
/// <reference lib="es2021.WeakRef" />
|
||||
|
||||
const tick = (0, _util().promisify)(setImmediate);
|
||||
class LeakDetector {
|
||||
_isReferenceBeingHeld;
|
||||
_shouldGenerateV8HeapSnapshot;
|
||||
_finalizationRegistry;
|
||||
constructor(value, opt) {
|
||||
if ((0, _getType().isPrimitive)(value)) {
|
||||
throw new TypeError(['Primitives cannot leak memory.', `You passed a ${typeof value}: <${(0, _prettyFormat().format)(value)}>`].join(' '));
|
||||
}
|
||||
|
||||
// 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._shouldGenerateV8HeapSnapshot = opt?.shouldGenerateV8HeapSnapshot ?? true;
|
||||
|
||||
// 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
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await tick();
|
||||
}
|
||||
if (this._isReferenceBeingHeld) {
|
||||
if (this._shouldGenerateV8HeapSnapshot) {
|
||||
// Triggering a heap snapshot is more aggressive than just calling `global.gc()`,
|
||||
// but it's also quite slow. Only do it if we still think we're leaking.
|
||||
// See: https://github.com/nodejs/node/pull/48510#issuecomment-1719289759
|
||||
(0, _v().getHeapSnapshot)();
|
||||
}
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await tick();
|
||||
}
|
||||
}
|
||||
return this._isReferenceBeingHeld;
|
||||
}
|
||||
_runGarbageCollector() {
|
||||
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.
|
||||
if (isGarbageCollectorHidden) {
|
||||
(0, _v().setFlagsFromString)('--no-expose-gc');
|
||||
}
|
||||
}
|
||||
}
|
||||
exports["default"] = LeakDetector;
|
||||
})();
|
||||
|
||||
module.exports = __webpack_exports__;
|
||||
/******/ })()
|
||||
;
|
||||
3
node_modules/jest-leak-detector/build/index.mjs
generated
vendored
Normal file
3
node_modules/jest-leak-detector/build/index.mjs
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import cjsModule from './index.js';
|
||||
|
||||
export default cjsModule.default;
|
||||
35
node_modules/jest-leak-detector/package.json
generated
vendored
Normal file
35
node_modules/jest-leak-detector/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name": "jest-leak-detector",
|
||||
"version": "30.3.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jestjs/jest.git",
|
||||
"directory": "packages/jest-leak-detector"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "./build/index.js",
|
||||
"types": "./build/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./build/index.d.ts",
|
||||
"require": "./build/index.js",
|
||||
"import": "./build/index.mjs",
|
||||
"default": "./build/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@jest/get-type": "30.1.0",
|
||||
"pretty-format": "30.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "efb59c2e81083f8dc941f20d6d20a3af2dc8d068"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue