Registry / testing / mocks
library0.0.15jsnpmunverified

The `mocks` package (npm: `mocks`), version 0.0.15, is an abandoned Node.js library initially created to provide basic mock implementations for the built-in `fs` (file system) and `http` modules for unit testing. Last published in August 2013, this package targets extremely old Node.js versions (specifically `>= 0.6.5`), which corresponds to Node.js releases from 2011-2012. The API provided is a very limited subset of the actual Node.js `fs` and `http` functionalities, having been developed primarily to support the testing needs of `Testacular` (now known as Karma). Given its lack of updates for over a decade, it does not support modern JavaScript features like ESM, contemporary Node.js APIs, or TypeScript type definitions. Developers should consider modern, actively maintained alternatives such as `mock-fs` for file system mocking, `node-mocks-http` or `nock` for HTTP requests, and general-purpose testing frameworks with robust mocking capabilities.

npm install mocks
INSTALL
IMPORT
SIG · MOCKS
M
mocks
testingjavascriptv0.0.15
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mocks
const mocks = require('mocks');
import mocks from 'mocks';
This package is CommonJS-only and does not support ES Modules. Using `import` will result in a runtime error.
mocks.fs
const fs = require('mocks').fs;
const fs = require('fs'); // This loads the real fs module unless patched differently
Access the mocked `fs` module directly from the `mocks` object. The package does not automatically monkey-patch the global `fs` module.
mocks.http
const http = require('mocks').http;
const http = require('http'); // This loads the real http module
Access the mocked `http` module directly from the `mocks` object. It provides `ServerRequest` and `ServerResponse` constructors.

This quickstart demonstrates how to use the `mocks` package to set up a mock file system (using `_set` and `readFileSync`) and create mock HTTP request/response objects for basic unit testing scenarios in a legacy Node.js environment.

const mocks = require('mocks'); const fs = mocks.fs; // Get the mocked fs module const http = mocks.http; // Get the mocked http module // Configure the mock file system with files and directories fs._set('/app/data/config.json', JSON.stringify({ version: '1.0.0', enabled: true })); fs._set('/app/logs', {}); // Mock an empty directory fs._set('/app/src/main.js', 'console.log("Hello from mocked file!");'); console.log('--- Mocking File System ---'); // Simulate reading a file synchronously try { const configContent = fs.readFileSync('/app/data/config.json', 'utf8'); console.log('Read config.json:', configContent); const config = JSON.parse(configContent); console.log('Parsed config version:', config.version); } catch (e) { console.error('Error reading config.json:', e.message); } // Simulate reading a non-existent file try { fs.readFileSync('/app/data/nonexistent.txt'); } catch (e) { console.log('Expected error for non-existent file:', e.message); } console.log('\n--- Mocking HTTP Request/Response ---'); // Mock an HTTP server request and response for testing a handler const mockRequest = new http.ServerRequest({ url: '/api/items/123', method: 'GET', headers: { 'Accept': 'application/json', 'User-Agent': 'MockTest' } }); const mockResponse = new http.ServerResponse(); mockResponse.statusCode = 200; mockResponse.setHeader('Content-Type', 'application/json'); mockResponse.end(JSON.stringify({ id: '123', name: 'Mock Item' })); console.log('Mock HTTP Request URL:', mockRequest.url); console.log('Mock HTTP Request Method:', mockRequest.method); console.log('Mock HTTP Response Status Code:', mockResponse.statusCode); console.log('Mock HTTP Response Headers:', mockResponse.getHeaders()); console.log('Mock HTTP Response Body:', mockResponse._getData().toString()); // _getData() retrieves the buffered response
Debug
Known issues
breakingThe `mocks` package is officially abandoned and has not been updated since August 2013. It is not compatible with modern Node.js versions or ES Modules, and its APIs are severely outdated and incomplete compared to current Node.js built-ins.
fix
Migrate to actively maintained mocking libraries like `mock-fs` (for file system), `nock` or `node-mocks-http` (for HTTP), or general testing frameworks (e.g., Jest, Sinon.js) for robust and current testing solutions.
affects: >=0.0.15
gotchaThe mock `fs` and `http` modules provided by this package implement only a very small subset of the actual Node.js APIs. Many common `fs` or `http` methods will be missing or have incomplete implementations, leading to unexpected runtime errors during testing.
fix
Review the source code or limited documentation on the GitHub page to understand exactly which methods are supported. For broader API coverage, consider alternative libraries.
affects: >=0.0.1
gotchaThis package is written exclusively in CommonJS and does not provide ES Module (ESM) entry points. Attempting to `import` it will result in a `SyntaxError` in ESM contexts.
fix
Use CommonJS `require()` syntax (`const mocks = require('mocks');`) to import the package. If your project is ESM-only, you will need to use a different mocking library.
affects: >=0.0.1
gotchaThere are no TypeScript type definitions available for the `mocks` package. Using it in a TypeScript project will result in type errors and lack of autocomplete, requiring manual type declarations.
fix
Either create custom declaration files (`.d.ts`) or, preferably, migrate to a modern mocking library that offers built-in TypeScript support.
affects: >=0.0.1
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use ES Module `import` syntax with the CommonJS-only `mocks` package.
fix
Change `import mocks from 'mocks';` to `const mocks = require('mocks');` and ensure your environment supports CommonJS.
TypeError: fs.someUnsupportedMethod is not a function
Attempting to call an `fs` or `http` method that is not implemented by the `mocks` package.
fix
Consult the `mocks` package's GitHub repository for the limited list of supported methods. For broader API support, consider modern alternatives like `mock-fs` or `nock`.
Error: Cannot find module 'mocks'
The package is not installed or the Node.js runtime cannot resolve its path.
fix
Ensure the package is installed via `npm install mocks` or `yarn add mocks` and that your Node.js resolution paths are correctly configured. Verify that `node_modules` is accessible.
Upgrade
Version history
0.0.15latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
mocks — npm install mocks · libregistry