You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.0 KiB

11 years ago
// verify that prepublish runs on pack and publish
var test = require("tap").test
var fs = require("graceful-fs")
var join = require("path").join
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
var path = require("path")
11 years ago
var pkg = join(__dirname, "prepublish_package")
var tmp = join(pkg, "tmp")
var cache = join(pkg, "cache")
test("setup", function (t) {
11 years ago
var n = 0
mkdirp(pkg, then())
mkdirp(cache, then())
mkdirp(tmp, then())
function then () {
n++
11 years ago
return function (er) {
if (er) throw er
if (--n === 0) next()
11 years ago
}
}
function next () {
fs.writeFile(join(pkg, "package.json"), JSON.stringify({
name: "npm-test-prepublish",
version: "1.2.5",
scripts: { prepublish: "echo ok" }
}), "ascii", function (er) {
if (er) throw er
t.pass("setup done")
11 years ago
t.end()
})
}
})
test("test", function (t) {
var spawn = require("child_process").spawn
11 years ago
var node = process.execPath
var npm = path.resolve(__dirname, "../../cli.js")
11 years ago
var env = {
"npm_config_cache" : cache,
"npm_config_tmp" : tmp,
"npm_config_prefix" : pkg,
"npm_config_global" : "false"
11 years ago
}
for (var i in process.env) {
if (!/^npm_config_/.test(i))
env[i] = process.env[i]
}
var child = spawn(node, [npm, "pack"], {
11 years ago
cwd: pkg,
env: env
})
child.stdout.setEncoding("utf8")
child.stderr.on("data", onerr)
child.stdout.on("data", ondata)
child.on("close", onend)
var c = ""
, e = ""
11 years ago
function ondata (chunk) {
c += chunk
}
function onerr (chunk) {
e += chunk
}
11 years ago
function onend () {
if (e) {
throw new Error("got stderr data: " + JSON.stringify("" + e))
}
11 years ago
c = c.trim()
var regex = new RegExp("" +
"> npm-test-prepublish@1.2.5 prepublish [^\\r\\n]+\\r?\\n" +
"> echo ok\\r?\\n" +
"\\r?\\n" +
"ok\\r?\\n" +
"npm-test-prepublish-1.2.5.tgz", "ig")
t.ok(c.match(regex))
11 years ago
t.end()
}
})
test("cleanup", function (t) {
rimraf(pkg, function (er) {
if (er) throw er
t.pass("cleaned up")
11 years ago
t.end()
})
})