
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
require-inject
Advanced tools
A simple mock injector compatible needing no instrumentation in the libraries being tested
A simple mock injector compatible needing no instrumentation in the libraries being tested
var requireInject = require('require-inject');
var mymod = requireInject('mymod', {
'fs' => {
stat: function (file,cb) {
switch (file) {
case 'testfile1': return cb(null,{})
case 'testfile2': return cb(new Error('ENOENT'))
}
}
}
})
var myglobal = requireInject.installGlobally('myglobal', { … })
var mymod = requireInject( module, mocks )
module is the name of the module you want to require.
mocks is an object with keys that are the names of the modules you want *to mock and values of the mock version of the objects.
requireInject makes it so that when module is required, any of its calls to require for modules inclued in mocks will return the mocked version. It takes care to not impact any other uses of module, any calls to require for it will get a version without mocks.
var myglobal = requireInject.installGlobally( module, mocks)
As with requireInject
, except that the module and its mocks are left in
the require cache and any future requires will end up using them too. This is
helpful particularly in the case of things that defer loading.
FAQs
A simple mock injector compatible needing no instrumentation in the libraries being tested
The npm package require-inject receives a total of 23,758 weekly downloads. As such, require-inject popularity was classified as popular.
We found that require-inject 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.