{"name":"gently","version":"1.0.0","directories":{"lib":"./lib/gently"},"main":"./lib/gently/index","repository":{"type":"git","url":"git+https://github.com/felixge/node-gently.git"},"dependencies":{},"devDependencies":{},"engines":{"node":"*"},"optionalDependencies":{},"gitHead":"b54d98695ace53baa5507bcf8afa18a5d6b0e110","description":"<!-- badges/ --> [![Build Status](https://travis-ci.org/felixge/node-gently.svg?branch=master)](https://travis-ci.org/felixge/node-gently) [![npm](https://img.shields.io/npm/v/gently.svg)](https://www.npmjs.com/package/gently)  [![Dependency Status](https","bugs":{"url":"https://github.com/felixge/node-gently/issues"},"homepage":"https://github.com/felixge/node-gently#readme","_id":"gently@1.0.0","_nodeVersion":"15.9.0","_npmVersion":"7.7.6","dist":{"integrity":"sha512-r9yS38X5t+sAAG5VJ+yUpoXfSevgSXS7eaSNpmZQwlm7dw8Ein2mdEvVkpe7ZKv3DJYhsiZEb1/mKcdp8gz3qA==","shasum":"ea6a53700e055b2d8ae7748e24df3a96c4dc5b18","tarball":"http://registry-npm.ywwl.com/gently/download/gently-1.0.0.tgz","fileCount":11,"unpackedSize":21510,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgp3MPCRA9TVsSAnZWagAASnsP/jAWbeso0xpf+DTS7aFc\nAGkk/Bbc1E1WsHF5D+j1+XKK5CEE2dcFEXzpvXktP+8AecQ7Uu90ZuCY+AEf\n6mDXbRBmFIfLZuLT7PGsQhGafWla8UKmXJ3JNUsRwFtJnEgnFKrtwxFqbNpY\nKfVbfh6laqnlRoBbdvOvO5m81oz/HfQQ5D1ioHg/LVheFEBWN0CHsdCu5A0d\nK4QGerRmZbi07xl9D27nFhuNMJ26rcDyQDQPB+MJQa2zf3YKW34IVji06Tck\ne55OW4eqrA0LU4Au0pgJOtIpbV6fBjwOeZtk4bJITRBLejdkZAQI+wNXSh8L\nVp4zrlKoHz5ynjOzNs0G9rqMJZfgNOMIbjcom1SemRgmUpO9diYjr+RFkH5t\nmC0reEXkYlaWT5s2TPMffJyDn1ygoP2wCBNfythB5q6O0dcDTvKAjEpa3LkK\ncfS/xFU3y//qz7mpYBXiEW6pci52EQ+lZzevXmGBwVHPhW5IMI2PLUcbmbGB\nvF7Q+qjoqDI244fYlac276l7ruJn9pr5imYYnzh/4MHJ9Iqk4YQYcZMh7Cpn\n0wPw5OAFXEKZTn+17fWZBTcMGEWRTOSgU4N4Qc58ZqVxU4uOcjo8mgEn25e8\n13TENoI8BlGvcg/6NRlQYnRYsJAmBsLOrtOyerzLnc5sKTp0XKui13PfTmkv\nsL+T\r\n=FoWz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE+Uk04lrYC8GFY8eBIrBdcbQA1bUC87SyQ3VSTUWEJwAiEAxUfoVJcM3uixmo87X4kjhn4XjvKt8Fill+TL/reO7mc="}],"size":5994,"noattachment":false,"key":"/gently/-/gently-1.0.0.tgz"},"_npmUser":{"name":"juliangruber","email":"julian@juliangruber.com"},"maintainers":[{"name":"felixge","email":"felix@debuggable.com"},{"name":"juliangruber","email":"julian@juliangruber.com"},{"name":"kvz","email":"kevin@vanzonneveld.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gently_1.0.0_1621586703137_0.12008859294651919"},"_hasShrinkwrap":false,"readme":"# Gently\n\n<!-- badges/ -->\n[![Build Status](https://travis-ci.org/felixge/node-gently.svg?branch=master)](https://travis-ci.org/felixge/node-gently)\n[![npm](https://img.shields.io/npm/v/gently.svg)](https://www.npmjs.com/package/gently) \n[![Dependency Status](https://david-dm.org/felixge/node-gently.svg?theme=shields.io)](https://david-dm.org/felixge/node-gently)\n[![Development Dependency Status](https://david-dm.org/felixge/node-gently/dev-status.svg?theme=shields.io)](https://david-dm.org/felixge/node-gently#info=devDependencies)\n<!-- /badges -->\n\n## Purpose\n\nA node.js module that helps with stubbing and behavior verification. It allows you to test the most remote and nested corners of your code while keeping being fully unobtrusive.\n\n## Features\n\n* Overwrite and stub individual object functions\n* Verify that all expected calls have been made in the expected order\n* Restore stubbed functions to their original behavior\n* Detect object / class names from obj.constructor.name and obj.toString()\n* Hijack any required module function or class constructor\n\n## Installation\n\nVia [npm](http://github.com/isaacs/npm):\n\n    npm install gently@latest\n\n## Example\n\nMake sure your dog is working properly:\n```javascript\nfunction Dog() {}\n\nDog.prototype.seeCat = function() {\n  this.bark('whuf, whuf');\n  this.run();\n}\n\nDog.prototype.bark = function(bark) {\n  require('sys').puts(bark);\n}\n\nconst gently = new (require('gently'))\n  , assert = require('assert')\n  , dog = new Dog();\n\ngently.expect(dog, 'bark', function(bark) {\n  assert.equal(bark, 'whuf, whuf');\n});\ngently.expect(dog, 'run');\n\ndog.seeCat();\n```\nYou can also easily test event emitters with this, for example a simple sequence of 2 events emitted by `fs.WriteStream`:\n```javascript\nconst gently = new (require('gently'))\n  , stream = new (require('fs').WriteStream)('my_file.txt');\n\ngently.expect(stream, 'emit', function(event) {\n  assert.equal(event, 'open');\n});\n\ngently.expect(stream, 'emit', function(event) {\n  assert.equal(event, 'drain');\n});\n```\nFor a full read world example, check out this test case: [test-incoming-form.js](http://github.com/felixge/node-formidable/blob/master/test/simple/test-incoming-form.js) (in [node-formdiable](http://github.com/felixge/node-formidable)).\n\n## API\n\n### Gently\n\n#### new Gently()\n\nCreates a new gently instance. It listens to the process `'exit'` event to make sure all expectations have been verified.\n\n#### gently.expect(obj, method, [[count], stubFn])\n\nCreates 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.\n\nReturns a reference to the function that is getting overwritten.\n\n#### gently.expect([count], stubFn)\n\nReturns 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:\n```javascript\nchildProcess.exec('ls', gently.expect(function lsCallback(code) {\n  assert.equal(0, code);\n}));\n```\n#### gently.restore(obj, method)\n\nRestores an object method that has been previously overwritten using `gently.expect()`.\n\n#### gently.hijack(realRequire)\n\nReturns a new require functions that catches a reference to all required modules into `gently.hijacked`.\n\nTo use this function, include a line like this in your `'my-module.js'`.\n```javascript\nif (global.GENTLY) require = GENTLY.hijack(require);\n\nconst sys = require('sys');\nexports.hello = function() {\n  sys.log('world');\n};\n```\nNow you can write a test for the module above:\n```javascript\nconst gently = global.GENTLY = new (require('gently'))\n  , myModule = require('./my-module');\n\ngently.expect(gently.hijacked.sys, 'log', function(str) {\n  assert.equal(str, 'world');\n});\n\nmyModule.hello();\n```\n#### gently.stub(location, [exportsName])\n\nReturns a stub class that will be used instead of the real class from the module at `location` with the given `exportsName`.\n\nThis allows to test an OOP version of the previous example, where `'my-module.js'`.\n```javascript\nif (global.GENTLY) require = GENTLY.hijack(require);\n\nconst World = require('./world');\n\nexports.hello = function() {\n  const world = new World();\n  world.hello();\n}\n```\nAnd `world.js` looks like this:\n```javascript\nconst sys = require('sys');\n\nfunction World() {\n\n}\nmodule.exports = World;\n\nWorld.prototype.hello = function() {\n  sys.log('world');\n};\n```\nTesting `'my-module.js'` can now easily be accomplished:\n```javascript\nconst gently = global.GENTLY = new (require('gently'))\n  , WorldStub = gently.stub('./world')\n  , myModule = require('./my-module')\n  , WORLD;\n\ngently.expect(WorldStub, 'new', function() {\n  WORLD = this;\n});\n\ngently.expect(WORLD, 'hello');\n\nmyModule.hello();\n```\n#### gently.hijacked\n\nAn object that holds the references to all hijacked modules.\n\n#### gently.verify([msg])\n\nVerifies 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.\n\nIf `msg` is given, it will appear in any error that might be thrown.\n\n## License\n\nGently is licensed under the MIT license.\n","publish_time":1621586703302,"_cnpm_publish_time":1621586703302,"dist-tags":{"latest":"1.0.0"}}