]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/cache-add-localdir-fallback.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / cache-add-localdir-fallback.js
1 var path = require("path")
2 var test = require("tap").test
3 var npm = require("../../lib/npm.js")
4 var requireInject = require("require-inject")
5
6 var realizePackageSpecifier = requireInject("realize-package-specifier", {
7   "fs": {
8     stat: function (file, cb) {
9       process.nextTick(function () {
10         switch (file) {
11         case path.resolve("named"):
12           cb(new Error("ENOENT"))
13           break
14         case path.resolve("file.tgz"):
15           cb(null, { isDirectory: function () { return false } })
16           break
17         case path.resolve("dir-no-package"):
18           cb(null, { isDirectory: function () { return true } })
19           break
20         case path.resolve("dir-no-package/package.json"):
21           cb(new Error("ENOENT"))
22           break
23         case path.resolve("dir-with-package"):
24           cb(null, { isDirectory: function () { return true } })
25           break
26         case path.resolve("dir-with-package/package.json"):
27           cb(null, {})
28           break
29         case path.resolve(__dirname, "dir-with-package"):
30           cb(null, { isDirectory: function () { return true } })
31           break
32         case path.join(__dirname, "dir-with-package", "package.json"):
33           cb(null, {})
34           break
35         case path.resolve(__dirname, "file.tgz"):
36           cb(null, { isDirectory: function () { return false } })
37           break
38         default:
39           throw new Error("Unknown test file passed to stat: " + file)
40         }
41       })
42     }
43   }
44 })
45
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) {
50       cb(null, "addNamed")
51     },
52     "../../lib/cache/add-local.js": function addLocal (name, data, cb) {
53       cb(null, "addLocal")
54     }
55   })
56
57   test("npm install localdir fallback", function (t) {
58     t.plan(12)
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")
62     })
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")
66     })
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")
70     })
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")
74     })
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")
78     })
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")
82     })
83   })
84 })