1 var path = require("path")
2 var test = require("tap").test
3 var npm = require("../../lib/npm.js")
4 var requireInject = require("require-inject")
6 var realizePackageSpecifier = requireInject("realize-package-specifier", {
8 stat: function (file, cb) {
9 process.nextTick(function () {
11 case path.resolve("named"):
12 cb(new Error("ENOENT"))
14 case path.resolve("file.tgz"):
15 cb(null, { isDirectory: function () { return false } })
17 case path.resolve("dir-no-package"):
18 cb(null, { isDirectory: function () { return true } })
20 case path.resolve("dir-no-package/package.json"):
21 cb(new Error("ENOENT"))
23 case path.resolve("dir-with-package"):
24 cb(null, { isDirectory: function () { return true } })
26 case path.resolve("dir-with-package/package.json"):
29 case path.resolve(__dirname, "dir-with-package"):
30 cb(null, { isDirectory: function () { return true } })
32 case path.join(__dirname, "dir-with-package", "package.json"):
35 case path.resolve(__dirname, "file.tgz"):
36 cb(null, { isDirectory: function () { return false } })
39 throw new Error("Unknown test file passed to stat: " + file)
46 npm.load({loglevel : "silent"}, function () {
47 var cache = requireInject("../../lib/cache.js", {
48 "realize-package-specifier": realizePackageSpecifier,
49 "../../lib/cache/add-named.js": function addNamed (name, version, data, cb) {
52 "../../lib/cache/add-local.js": function addLocal (name, data, cb) {
57 test("npm install localdir fallback", function (t) {
59 cache.add("named", null, null, false, function (er, which) {
60 t.ifError(er, "named was cached")
61 t.is(which, "addNamed", "registry package name")
63 cache.add("file.tgz", null, null, false, function (er, which) {
64 t.ifError(er, "file.tgz was cached")
65 t.is(which, "addLocal", "local file")
67 cache.add("dir-no-package", null, null, false, function (er, which) {
68 t.ifError(er, "local directory was cached")
69 t.is(which, "addNamed", "local directory w/o package.json")
71 cache.add("dir-with-package", null, null, false, function (er, which) {
72 t.ifError(er, "local directory with package was cached")
73 t.is(which,"addLocal", "local directory with package.json")
75 cache.add("file:./dir-with-package", null, __dirname, false, function (er, which) {
76 t.ifError(er, "local directory (as URI) with package was cached")
77 t.is(which, "addLocal", "file: URI to local directory with package.json")
79 cache.add("file:./file.tgz", null, __dirname, false, function (er, which) {
80 t.ifError(er, "local file (as URI) with package was cached")
81 t.is(which, "addLocal", "file: URI to local file with package.json")