Registry / testing / fake
library0.8jsnpmunverified

This package, `fake` (version 0.2.2), is an early JavaScript utility designed for creating test doubles, specifically 'faking' dependencies to isolate units under test. Released for very old Node.js environments (requiring Node.js >=0.4.0), it predates most modern testing frameworks and mocking libraries. The project appears to be abandoned, with its last release dating back to a period when Node.js was in its infancy. It provides basic mechanisms for stubbing or mocking parts of an application's dependencies, allowing developers to focus on the logic of a single component without external side effects. Given its age and lack of updates, it is not suitable for contemporary JavaScript development and lacks features prevalent in current mocking solutions like Jest or Sinon.js. Its release cadence is effectively nonexistent due to its abandonment.

npm install fake
INSTALL
IMPORT
SIG · FAKE
F
fake
testingjavascriptv0.8
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.

Fake
const Fake = require('fake');
import Fake from 'fake'; import { Fake } from 'fake';
The 'fake' package exports its 'Fake' constructor function directly via CommonJS `module.exports`. ES Module (ESM) `import` syntax is not supported and will result in runtime errors.
Fake.prototype.run()
const Fake = require('fake'); const target = { method: () => 'original' }; const f = new Fake(target, 'method', () => 'faked'); f.run(); // Applies the fake method to target.method // ... test execution ...
After instantiating 'Fake', call the `run()` method on the instance to replace the target object's method with your faked implementation.
Fake.prototype.restore()
const Fake = require('fake'); const target = { method: () => 'original' }; const f = new Fake(target, 'method', () => 'faked'); f.run(); // ... test execution ... f.restore(); // Reverts target.method to its original state
Crucially, call `restore()` on the `Fake` instance after your test or block to revert the faked method, preventing test pollution and ensuring a clean state for subsequent operations.

This quickstart demonstrates the core lifecycle of faking a method: creating a Fake instance, applying the fake with `run()`, and cleaning up by restoring the original method with `restore()`, crucial for isolated unit testing in older Node.js environments.

const Fake = require('fake'); const myService = { getData: () => 'Real data from DB', process: (input) => `Processing: ${input}` }; console.log('--- Before Faking ---'); console.log('getData:', myService.getData()); console.log('process:', myService.process('initial input')); // 1. Create a fake for 'getData' const fakeGetData = new Fake(myService, 'getData', () => 'Mocked data from fakeGetData'); // 2. Apply the fake fakeGetData.run(); console.log('\n--- During Faking (Test Context) ---'); console.log('getData:', myService.getData()); // Expected: 'Mocked data from fakeGetData' console.log('process:', myService.process('input during fake')); // Still original // 3. Create another fake for 'process' const fakeProcess = new Fake(myService, 'process', (input) => `Faked process for: ${input.toUpperCase()}`); fakeProcess.run(); console.log('\n--- With Multiple Fakes ---'); console.log('getData:', myService.getData()); // Still 'Mocked data from fakeGetData' console.log('process:', myService.process('another test input')); // Expected: 'Faked process for: ANOTHER TEST INPUT' // 4. Restore all fakes after the test fakeGetData.restore(); fakeProcess.restore(); console.log('\n--- After Restoring ---'); console.log('getData:', myService.getData()); // Expected: 'Real data from DB' console.log('process:', myService.process('final input')); // Expected: 'Processing: final input'
Debug
Known issues
deprecatedThe 'fake' package (v0.2.2) is considered abandoned. It has not been updated since early Node.js versions (requiring Node.js >=0.4.0) and lacks ongoing maintenance, security patches, and modern features. For new projects, use actively maintained mocking libraries like Jest (for its built-in mocks), Sinon.js, or Testdouble.js.
fix
Migrate your testing setup to a modern, actively maintained testing framework or mocking library. If you must use this package, proceed with extreme caution and be aware of potential compatibility and security vulnerabilities.
affects: >=0.2.2
breakingThis package is strictly CommonJS and does not support ES Modules (ESM) syntax ('import'). Attempting to use 'import' will result in a 'SyntaxError: Cannot use import statement outside a module' or 'TypeError: require is not a function'.
fix
Ensure your project uses CommonJS (`require`) for importing this package. If your project is ESM-first, you might need a CommonJS wrapper or, preferably, a different mocking library.
affects: >=0.2.2
breakingThe package's declared engine `node: >=0.4.0` signifies it was built for very old Node.js runtimes. Running it on modern Node.js versions (e.g., Node.js 14+) might lead to unexpected behavior, deprecation warnings, or crashes due to significant API changes or removal of global functions.
fix
It is strongly advised against using this package in modern Node.js environments. If indispensable, thoroughly test its compatibility with your specific Node.js version, recognizing that maintaining it will be a significant challenge.
affects: >=0.2.2
gotchaThe 'Fake' constructor directly modifies the target object's method in place. Failing to call `fakeInstance.restore()` after a test can lead to global state pollution, affecting subsequent tests, other modules, or application behavior outside the intended test scope. This is a common source of flaky and hard-to-debug tests.
fix
Always ensure `fakeInstance.restore()` is called in a `finally` block or your test runner's `afterEach` hook to guarantee proper cleanup and isolation between tests.
affects: >=0.2.2
gotchaThis library offers only basic method replacement. It lacks advanced mocking features such as spies (to record calls), argument capturing, defining different return values based on arguments, or asserting call counts, which are standard in modern mocking frameworks.
fix
For complex mocking scenarios requiring introspection, conditional faking, or detailed assertions, consider migrating to a feature-rich library like Sinon.js or leveraging the robust built-in mocking capabilities of Jest.
affects: >=0.2.2
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use ES Module 'import' syntax (e.g., `import Fake from 'fake';`) with this CommonJS-only package.
fix
Replace `import` statements with CommonJS `require()`: `const Fake = require('fake');`. Ensure your file is treated as CommonJS.
TypeError: Fake is not a constructor
Calling `require('fake')` directly as a function, or attempting to use the `Fake` export without the `new` keyword to instantiate it.
fix
The 'fake' package exports a constructor function. You must use `new Fake(...)` to create an instance: `const Fake = require('fake'); const myFake = new Fake(target, 'method', newMethod);`
Error: Cannot find module 'fake'
The 'fake' package is not installed or not resolvable in the current Node.js environment or project.
fix
Install the package using npm: `npm install fake` or `npm install --save-dev fake`.
(node:XXXX) Warning: Accessing non-existent property 'foo' of module exports inside of a require call (or similar Node.js runtime warnings)
This and similar warnings (e.g., related to deprecated APIs or internal module loader behavior) can occur when running a very old, unmaintained package like 'fake' on modern Node.js runtimes.
fix
There is no direct fix for the 'fake' package itself. This warning is a symptom of severe compatibility issues. The only robust solution is to migrate away from this abandoned library to a modern alternative.
Upgrade
Version history
0.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
fake — npm install fake · libregistry