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:
authorisaacs <i@izs.me>2014-03-27 11:37:13 +0400
committerisaacs <i@izs.me>2014-04-10 03:35:40 +0400
commit7c49109996a9845e823e0f33983fbcb9fee3e38a (patch)
tree7fdd3969864fbeb42cf8cc96836c0da3f9612237 /test
parent3b0870fb2f40358b3051abdab6be4319d196b99d (diff)
test: test that cache loading doesn't mangle shasum
Diffstat (limited to 'test')
-rw-r--r--test/tap/cache-shasum.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/tap/cache-shasum.js b/test/tap/cache-shasum.js
new file mode 100644
index 000000000..460f2ee3f
--- /dev/null
+++ b/test/tap/cache-shasum.js
@@ -0,0 +1,60 @@
+var npm = require.resolve("../../")
+var test = require("tap").test
+var path = require("path")
+var fs = require("fs")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var mr = require("npm-registry-mock")
+var common = require("../common-tap.js")
+var cache = path.resolve(__dirname, "cache-shasum")
+var spawn = require("child_process").spawn
+var sha = require("sha")
+var server
+
+test("mock reg", function(t) {
+ rimraf.sync(cache)
+ mkdirp.sync(cache)
+ mr(common.port, function (s) {
+ server = s
+ t.pass("ok")
+ t.end()
+ })
+})
+
+test("npm cache add request", function(t) {
+ var c = spawn(process.execPath, [
+ npm, "cache", "add", "request@2.27.0",
+ "--cache=" + cache,
+ "--registry=" + common.registry,
+ "--loglevel=quiet"
+ ])
+ c.stderr.pipe(process.stderr)
+
+ c.stdout.on("data", function(d) {
+ t.fail("Should not get data on stdout: " + d)
+ })
+
+ c.on("close", function(code) {
+ t.notOk(code, "exit ok")
+ t.end()
+ })
+})
+
+test("compare", function(t) {
+ var d = path.resolve(__dirname, "cache-shasum/request")
+ var p = path.resolve(d, "2.27.0/package.tgz")
+ var r = require(path.resolve(d, ".cache.json"))
+ var rshasum = r.versions['2.27.0'].dist.shasum
+ sha.get(p, function (er, pshasum) {
+ if (er)
+ throw er
+ t.equal(pshasum, rshasum)
+ t.end()
+ })
+})
+
+test("cleanup", function(t) {
+ server.close()
+ rimraf.sync(cache)
+ t.end()
+})