
Security News
GitHub Actions Pricing Whiplash: Self-Hosted Actions Billing Change Postponed
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.
<!-- badges/ --> [](https://travis-ci.org/felixge/node-gently) [](https://www.npmjs.com/package/gently) [ {}
Dog.prototype.seeCat = function() {
this.bark('whuf, whuf');
this.run();
}
Dog.prototype.bark = function(bark) {
require('sys').puts(bark);
}
const gently = new (require('gently'))
, assert = require('assert')
, dog = new Dog();
gently.expect(dog, 'bark', function(bark) {
assert.equal(bark, 'whuf, whuf');
});
gently.expect(dog, 'run');
dog.seeCat();
You can also easily test event emitters with this, for example a simple sequence of 2 events emitted by fs.WriteStream:
const gently = new (require('gently'))
, stream = new (require('fs').WriteStream)('my_file.txt');
gently.expect(stream, 'emit', function(event) {
assert.equal(event, 'open');
});
gently.expect(stream, 'emit', function(event) {
assert.equal(event, 'drain');
});
For a full read world example, check out this test case: test-incoming-form.js (in node-formdiable).
Creates a new gently instance. It listens to the process 'exit' event to make sure all expectations have been verified.
Creates an expectation for an objects method to be called. You can optionally specify the call count you are expecting, as well as stubFn function that will run instead of the original function.
Returns a reference to the function that is getting overwritten.
Returns a function that is supposed to be executed count times, delegating any calls to the provided stubFn function. Naming your stubFn closure will help to properly diagnose errors that are being thrown:
childProcess.exec('ls', gently.expect(function lsCallback(code) {
assert.equal(0, code);
}));
Restores an object method that has been previously overwritten using gently.expect().
Returns a new require functions that catches a reference to all required modules into gently.hijacked.
To use this function, include a line like this in your 'my-module.js'.
if (global.GENTLY) require = GENTLY.hijack(require);
const sys = require('sys');
exports.hello = function() {
sys.log('world');
};
Now you can write a test for the module above:
const gently = global.GENTLY = new (require('gently'))
, myModule = require('./my-module');
gently.expect(gently.hijacked.sys, 'log', function(str) {
assert.equal(str, 'world');
});
myModule.hello();
Returns a stub class that will be used instead of the real class from the module at location with the given exportsName.
This allows to test an OOP version of the previous example, where 'my-module.js'.
if (global.GENTLY) require = GENTLY.hijack(require);
const World = require('./world');
exports.hello = function() {
const world = new World();
world.hello();
}
And world.js looks like this:
const sys = require('sys');
function World() {
}
module.exports = World;
World.prototype.hello = function() {
sys.log('world');
};
Testing 'my-module.js' can now easily be accomplished:
const gently = global.GENTLY = new (require('gently'))
, WorldStub = gently.stub('./world')
, myModule = require('./my-module')
, WORLD;
gently.expect(WorldStub, 'new', function() {
WORLD = this;
});
gently.expect(WORLD, 'hello');
myModule.hello();
An object that holds the references to all hijacked modules.
Verifies that all expectations of this gently instance have been satisfied. If not called manually, this method is called when the process 'exit' event is fired.
If msg is given, it will appear in any error that might be thrown.
Gently is licensed under the MIT license.
FAQs
<!-- badges/ --> [](https://travis-ci.org/felixge/node-gently) [](https://www.npmjs.com/package/gently) [
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
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.