From ccebab4cc22724778e358f176c7823da92cf23c9 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Fri, 20 Feb 2015 11:25:31 -0800 Subject: [PATCH] The register method should return existing modules --- .editorconfig | 13 +++++++++++++ .gitignore | 1 + lib/registry.js | 2 +- spec/lib/registry.spec.js | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e717f5e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index a1dca14..3ca5581 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules/ npm-debug.log /coverage/ +.idea/ \ No newline at end of file diff --git a/lib/registry.js b/lib/registry.js index 50cea23..fb56b1c 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -35,7 +35,7 @@ var Registry = module.exports = { register: function(module) { if (this.data[module]) { - return; + return this.data[module].module; } var pkg; diff --git a/spec/lib/registry.spec.js b/spec/lib/registry.spec.js index 8cf515b..4d77df4 100644 --- a/spec/lib/registry.spec.js +++ b/spec/lib/registry.spec.js @@ -34,5 +34,22 @@ describe("Registry", function() { } }); }); + + context("when the module already exists", function() { + it("returns the module", function() { + expect(Registry.data).to.be.eql({}); + + var result = Registry.register(path); + + // should register the module and return it + expect(result).to.be.eql(mod); + + result = Registry.register(path); + + // should just return the existing module + expect(result).to.be.eql(mod); + + }); + }); }); });