Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRebecca Turner <turner@mikomi.org>2014-09-05 00:28:40 +0400
committerForrest L Norvell <forrest@npmjs.com>2014-09-05 09:35:00 +0400
commita42ddddf92481174981763eb95336eae0abe062a (patch)
treea84cbb00c894acbf79794435fd85f467ab550bfc /test
parentfa794138bec8edb7b88639db25ee9c010d2f4c2b (diff)
Add tests for local fallback to registry patch
Diffstat (limited to 'test')
-rw-r--r--test/tap/cache-add-localdir-fallback.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/tap/cache-add-localdir-fallback.js b/test/tap/cache-add-localdir-fallback.js
new file mode 100644
index 000000000..7e6e0e4a3
--- /dev/null
+++ b/test/tap/cache-add-localdir-fallback.js
@@ -0,0 +1,55 @@
+var test = require("tap").test
+var npm = require("../../lib/npm.js")
+var requireInject = require('require-inject');
+
+npm.load({}, function () {
+ var cache = requireInject("../../lib/cache.js",{
+ "graceful-fs": {
+ stat: function (file, cb) {
+ process.nextTick(function() {
+ switch (file) {
+ case "named":
+ cb(new Error("ENOENT"))
+ break
+ case "file.tgz":
+ cb(null,{isDirectory:function(){return false}})
+ break
+ case "dir-no-package":
+ cb(null,{isDirectory:function(){return true}})
+ break
+ case "dir-no-package/package.json":
+ cb(new Error("ENOENT"))
+ break
+ case "dir-with-package":
+ cb(null,{isDirectory:function(){return true}})
+ break
+ case "dir-with-package/package.json":
+ cb(null,{})
+ break
+ default:
+ console.error("Unknown test file passed to stat:",file)
+ process.exit(1)
+ }
+ })
+ }
+ },
+ "../../lib/cache/add-named.js": function addNamed (name,version,data,cb) {
+ cb(null,"addNamed")
+ },
+ "../../lib/cache/add-local.js": function addLocal (name,data,cb) {
+ cb(null,"addLocal")
+ }
+ })
+
+ test("npm install localdir fallback", function(t) {
+ t.plan(4)
+ cache.add("named", null, false, function (er,which){
+ t.is(which, "addNamed", "registry package name") })
+ cache.add("file.tgz", null, false, function (er,which){
+ t.is(which, "addLocal", "local file") })
+ cache.add("dir-no-package", null, false, function (er,which){
+ t.is(which, "addNamed", "local directory w/o package.json") })
+ cache.add("dir-with-package", null, false, function (er,which){
+ t.is(which,"addLocal", "local directory w/ package.json") })
+ })
+})