New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mockire

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockire

This library allows developers to stub and clear the `require` built-in method.

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
decreased by-63.33%
Maintainers
1
Weekly downloads
 
Created
Source

This library allows developers to stub and clear the require built-in method.

The Mockire interceptor is initialized as soon as the module is required.

Use with caution.

Methods

  • match(pattern, value): matches the module path against a regular expression.
  • exact(input, value): expects the provided path to be exactly as required.
  • clearStubs(): clears all stubs.
  • reset(): removes the monkey patch.
  • init(): initializes the interceptor.
  • clearRequireCache(): clears all modules stored in the require cache. Modules will be loaded again next time require is invoked.

Use cases:

Clearing cache before tests start

const { clearRequireCache } = require('mockire');
let server;
describe('Unit tests', () => {
    before((done) => {
        clearRequireCache();
        server = require('./MyCustomServer');
    })
} 

Loads fake dependencies

const { match } = require('mockire');
match('MyProjectDirectory/config/env/*', { port: 8000, db: { host: 'localhost', port: '27017' } });
const server = require('./MyCustomServer');

describe('Unit tests', () => {
    before((done) => {
        server.start()
    })
} 

Creates virtual dependency

const { exact, clearStubs } = require('mockire');
if (!fs.existsSync('./path/customLib)) {
    exact('./path/customLib', { something });
}
const lib = require('./path/customLib');
await lib.foo();
clearStubs();

Keywords

FAQs

Package last updated on 27 Oct 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc