node/deps/npm/test/packages/npm-test-shrinkwrap/test.js

36 lines
922 B
JavaScript
Raw Normal View History

2012-12-13 06:41:28 +08:00
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
2013-01-19 04:12:07 +08:00
var npm = process.env.npm_execpath
2012-12-13 06:41:28 +08:00
2013-02-07 00:39:27 +08:00
require("child_process").execFile(process.execPath, [npm, "ls", "--json"], {
2012-12-13 06:41:28 +08:00
stdio: "pipe", env: process.env, cwd: process.cwd() },
function (err, stdout, stderr) {
if (err) throw err
2013-01-19 04:12:07 +08:00
var actual = JSON.parse(stdout)
var expected = require("./npm-shrinkwrap.json")
rmFrom(actual)
actual = actual.dependencies
rmFrom(expected)
expected = expected.dependencies
console.error(JSON.stringify(actual, null, 2))
console.error(JSON.stringify(expected, null, 2))
2012-12-13 06:41:28 +08:00
assert.deepEqual(actual, expected)
})
2013-01-19 04:12:07 +08:00
function rmFrom (obj) {
for (var i in obj) {
if (i === "from")
delete obj[i]
else if (i === "dependencies")
for (var j in obj[i])
rmFrom(obj[i][j])
}
}