Permalink
Browse files

fix #55 Add test names to the tap-harness results

  • Loading branch information...
1 parent cc6e4d0 commit 247fec935c690c7d765e11168566d17107aaa768 @thlorenz thlorenz committed with isaacs Sep 8, 2012
Showing with 54 additions and 2 deletions.
  1. +1 −1 lib/tap-browser-harness.js
  2. +1 −1 lib/tap-global-harness.js
  3. +2 −0 lib/tap-harness.js
  4. +50 −0 test/output-childtest-description.js
@@ -30,7 +30,7 @@ function BrowserHarness (outPipe) {
//console.error(child.results)
// write out the stuff for this child.
//console.error("child.conf", child.conf)
- output.write(child.conf.name || "(unnamed test)")
+
// maybe write some other stuff about the number of tests in this
// thing, etc. I dunno.
//console.error("child results", child.results)
@@ -34,7 +34,7 @@ function GlobalHarness () {
//console.error(child.results)
// write out the stuff for this child.
//console.error("child.conf", child.conf)
- output.write(child.conf.name || "(unnamed test)")
+
// maybe write some other stuff about the number of tests in this
// thing, etc. I dunno.
//console.error("child results", child.results)
View
@@ -140,6 +140,8 @@ Harness.prototype.childEnd = function (child) {
this._testCount ++
this._planSum += child._plan
//console.error("adding set of child.results")
+
+ this.results.add(child.conf.name || "(unnamed test)")
this.results.addSet(child.results)
this.emit("childEnd", child)
// was this planned?
@@ -0,0 +1,50 @@
+var tap = require("../")
+ , fs = require("fs")
+ , path = require('path')
+ , cp = require("child_process")
+ , nestedTests =
+ [ "var test = require('..').test"
+ , "test('parent test description', function (t) {"
+ , " t.plan(2)"
+ , " t.ok(true, 'test in parent')"
+ , " t.test('child test description', function (t) {"
+ , " t.plan(1)"
+ , " t.ok(true, 'test in child') "
+ , " })"
+ , "})"
+ ].join("\n")
+ , nestedTestsFile = path.join(__dirname, "nested-tests-fixture.js")
+
+fs.writeFileSync(nestedTestsFile, nestedTests, "utf8")
+console.log(nestedTestsFile);
+
+tap.test("nested tests, parent and child pass", function (t) {
+ /*
+ * Ensure the output includes the following lines in the right order:
+ * '# parent test description'
+ * 'ok 1 test in parent'
+ * '# child test description'
+ * 'ok 2 test in child'
+ */
+
+ t.plan(5)
+
+ cp.exec("node " + nestedTestsFile, function (err, stdo, stde) {
+ var lines = stdo.split("\n")
+ , parentDes = lines.indexOf("# parent test description")
+ , parentRes = lines.indexOf("ok 1 test in parent")
+ , childDes = lines.indexOf("# child test description")
+ , childRes = lines.indexOf("ok 2 test in child")
+
+ t.notEqual(parentDes, -1, "outputs parent description")
+ t.notEqual(childDes, -1, "outputs child description")
+
+ t.ok(parentDes < parentRes , "outputs parent description before parent result")
+ t.ok(parentRes < childDes , "outputs parent result before child description")
+ t.ok(childDes < childRes , "outputs child description before child result")
+
+ fs.unlinkSync(nestedTestsFile);
+ t.end()
+ })
+})
+

0 comments on commit 247fec9

Please sign in to comment.