Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
global-leaks-finder
Advanced tools
A mocha-based testing tool to help find tests which are leaking globals.
The aim is to help catch and avoid tests with unexpected side-effects.
It does add significant time to the job so best run only occasionally. See below for explanation how it works.
Take this example. Before each test the browser
is set and after it is reset. However we do not know what the value was before this unit test ran or if false
is a reliable value for later tests. This is an example of a global leakage and is easily missed.
beforeEach(() => {
process.browser = true;
});
afterEach(() => {
process.browser = false; // BAD
});
Running the tool on this test would throw an error to the console Error: Global has changed
on the test spec which has leaked, allowing you to catch and manage the problem.
The test has now been improved.
let cached;
beforeEach(() => {
cached = process.browser;
process.browser = true;
});
afterEach(() => {
process.browser = cached; // BETTER
});
Ideally its best to use something like Sinon.js Sandboxing, but it is not always possible.
Does not require any additional dependencies, just itself.
npm install global-leaks-finder
mocha --check-leaks node_modules/global-leaks-finder/index.js <your test files here>
I recommend running in conjunction with Mocha's check-leaks
flag. It compares against a small list of non-enumerable globals (i.e. global.newVariable = 'some-value';
would be caught) but would not catch something like process.execPath = 'GLOBAL LEAK';
which this tool would catch.
It runs a global beforeEach
and afterEach
.
For each test it hashes the globals at the start, hashes the globals at the end, and compares the 2 failing if the hash has changed. Hence why it has a hefty performance hit, but hopefully does its job.
Please feel free to contact or email me if there are any issues.
FAQs
Manage your tests side-effects
The npm package global-leaks-finder receives a total of 0 weekly downloads. As such, global-leaks-finder popularity was classified as not popular.
We found that global-leaks-finder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.