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

dependable

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dependable - npm Package Compare versions

Comparing version 0.0.3 to 0.2.0

18

index.js

@@ -84,9 +84,7 @@ // Generated by CoffeeScript 1.3.3

get = function(name, overrides, visited) {
var dependencies, factory;
if (overrides == null) {
overrides = {};
}
var dependencies, factory, instance, isOverridden;
if (visited == null) {
visited = [];
}
isOverridden = overrides != null;
if (haveVisited(visited, name)) {

@@ -100,8 +98,8 @@ throw new Error("circular dependency with '" + name + "'");

}
if (factory.instance != null) {
if ((factory.instance != null) && !isOverridden) {
return factory.instance;
}
dependencies = factory.required.map(function(name) {
if (overrides[name] != null) {
return overrides[name];
if ((overrides != null ? overrides[name] : void 0) != null) {
return overrides != null ? overrides[name] : void 0;
} else {

@@ -111,3 +109,7 @@ return get(name, overrides, visited);

});
return factory.instance = factory.func.apply(factory, dependencies);
instance = factory.func.apply(factory, dependencies);
if (!isOverridden) {
factory.instance = instance;
}
return instance;
};

@@ -114,0 +116,0 @@ haveVisited = function(visited, name) {

{
"name": "dependable",
"version": "0.0.3",
"version": "0.2.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "author": "Sean Hess",

@@ -105,4 +105,25 @@ # Dependable

You can load files or directories instead of registering by hand. See below.
You can load files or directories instead of registering by hand. See [Reference](#reference)
### Overriding Dependencies for Testing
When testing, you usually want most dependencies loaded normally, but to mock others. You can use overrides for this. In the example below, `User` depends on `Friends.getInfo` for it's `getFriends` call. By setting `Friends` to `MockFriends` we can stub the dependency, but any other dependencies `User` has will be passed in normally.
# boostrap.coffee
deps = container()
deps.register "Friends", require('./Friends')
deps.register "User", require('./User')
# test.coffee
describe 'User', ->
it 'should get friends plus info', (done) ->
MockFriends =
getInfo: (id, cb) -> cb null, {some:"info"}
User = deps.get "User", {Friends: MockFriends}
User.getFriends "userId", (err, friends) ->
# assertions
done()
## Reference

@@ -114,3 +135,3 @@

`container.get(name)` - returns a module by name, with all dependencies injected
`container.get(name, overrides = {})` - returns a module by name, with all dependencies injected. If you specify overrides, the dependency will be given those overrides instead of those registerd.

@@ -117,0 +138,0 @@ `container.resolve(cb)` - calls cb like a dependency function, injecting any dependencies found in the signature

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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