Permalink
Browse files

Convert shrinkwrap test script from bash to Node.

Works better on Windows.
  • Loading branch information...
1 parent ad0f64d commit bbb5741cf5f93dd65bb56b6c41d01af5d206d72a @domenic domenic committed Oct 29, 2012
@@ -8,6 +8,6 @@
"minimatch": "~0.1.0"
},
"scripts": {
- "test": "bash test.sh"
+ "test": "node test.js"
}
}
@@ -0,0 +1,19 @@
+var path = require("path")
+var assert = require("assert")
+
+process.env.npm_config_prefix = process.cwd()
+delete process.env.npm_config_global
+delete process.env.npm_config_depth
+
+var npm = path.resolve(process.env.npm_config_prefix, "../../npm")
+
+require("child_process").exec(npm + " ls --json", {
+ stdio: "pipe", env: process.env, cwd: process.cwd() },
+ function (err, stdout, stderr) {
+ if (err) throw err
+
+ var actual = JSON.parse(stdout).dependencies
+ var expected = require("./npm-shrinkwrap.json").dependencies
+
+ assert.deepEqual(actual, expected)
+})
@@ -1,20 +0,0 @@
-#!/bin/bash
-
-# ensure that we get the npm being tested, not some global thing.
-npmbin=$npm_config_prefix/bin/npm
-npm () {
- node $npmbin "$@"
-}
-
-# work around the weird env we're in, as part of npm's test
-export npm_config_prefix=$PWD
-unset npm_config_global
-unset npm_config_depth
-
-out=$(diff <(npm ls --json) npm-shrinkwrap.json)
-if [ "$out" != "" ]; then
- echo "Didn't get expected packages" >&2
- echo "$out" >&2
- exit 1
-fi
-echo "ok"

0 comments on commit bbb5741

Please sign in to comment.