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
diff options
context:
space:
mode:
Diffstat (limited to 'test/common-tap.js')
-rw-r--r--test/common-tap.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/common-tap.js b/test/common-tap.js
index a13a0a7cd..c4f3f613f 100644
--- a/test/common-tap.js
+++ b/test/common-tap.js
@@ -1,2 +1,34 @@
+var spawn = require('child_process').spawn
+
var port = exports.port = 1337
exports.registry = "http://localhost:" + port
+
+exports.run = run
+function run (cmd, t, opts, cb) {
+ if (!opts)
+ opts = {}
+ if (!Array.isArray(cmd))
+ throw new Error("cmd must be an Array")
+ if (!t || !t.end)
+ throw new Error("node-tap instance is missing")
+
+ var c = ""
+ , e = ""
+ , node = process.execPath
+ , child = spawn(node, cmd, opts)
+
+ child.stderr.on("data", function (chunk) {
+ e += chunk
+ })
+
+ child.stdout.on("data", function (chunk) {
+ c += chunk
+ })
+
+ child.stdout.on("end", function () {
+ if (cb)
+ cb(t, c, e, { cmd: cmd, opts: opts })
+ else
+ t.end()
+ })
+}