Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
use common.npm instead of spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismeyersfsu authored and othiym23 committed Oct 9, 2014
1 parent c877553 commit df98525
Showing 1 changed file with 20 additions and 32 deletions.
52 changes: 20 additions & 32 deletions test/tap/prepublish.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// verify that prepublish runs on pack and publish
var common = require("../common-tap")
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")

var pkg = join(__dirname, "prepublish_package")
var tmp = join(pkg, "tmp")
var cache = join(pkg, "cache")

test("setup", function (t) {
var n = 0
cleanup()
mkdirp(pkg, then())
mkdirp(cache, then())
mkdirp(tmp, then())
Expand All @@ -38,9 +39,6 @@ test("setup", function (t) {
})

test("test", function (t) {
var spawn = require("child_process").spawn
var node = process.execPath
var npm = path.resolve(__dirname, "../../cli.js")
var env = {
"npm_config_cache" : cache,
"npm_config_tmp" : tmp,
Expand All @@ -51,27 +49,16 @@ test("test", function (t) {
if (!/^npm_config_/.test(i))
env[i] = process.env[i]
}
var child = spawn(node, [npm, "pack"], {
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 = ""
function ondata (chunk) {
c += chunk
}
function onerr (chunk) {
e += chunk
}
function onend () {
if (e) {
throw new Error("got stderr data: " + JSON.stringify("" + e))
}
c = c.trim()

common.npm([
"pack",
"--loglevel", "warn"
], { cwd: pkg, env: env }, function(err, code, stdout, stderr) {
t.equal(code, 0, "pack finished successfully")
t.ifErr(err, "pack finished successfully")

t.notOk(stderr, "got stderr data:" + JSON.stringify("" + stderr))
var c = stdout.trim()
var regex = new RegExp("" +
"> npm-test-prepublish@1.2.5 prepublish [^\\r\\n]+\\r?\\n" +
"> echo ok\\r?\\n" +
Expand All @@ -81,14 +68,15 @@ test("test", function (t) {

t.ok(c.match(regex))
t.end()
}
})
})

test("cleanup", function (t) {
rimraf(pkg, function (er) {
if (er) throw er

t.pass("cleaned up")
t.end()
})
cleanup()
t.pass("cleaned up")
t.end()
})

function cleanup() {
rimraf.sync(pkg)
}

0 comments on commit df98525

Please sign in to comment.