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:
authorRobert Kowalski <rok@kowalski.gd>2014-02-23 03:03:59 +0400
committerDomenic Denicola <domenic@domenicdenicola.com>2014-04-18 07:38:33 +0400
commit6ef9f9dd71620b03f039823bb082cfbeb7200416 (patch)
tree46ca09ff0ebc026ce73bd9ab4b69b313639bff04 /test/common-tap.js
parentb553c130ea41014ab8f29a22d9074e97738e86d5 (diff)
Factor test-helper out of tests
Bonus: - Fix test in `startstop.js`
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()
+ })
+}