Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #24: ensure separate test cases get their own 'conf' copy

  • Loading branch information...
commit 28c998a6375464d5a8b35e6c3a20cc77a9543fb0 1 parent 725d8c8
@trentm trentm authored committed
Showing with 23 additions and 1 deletion.
  1. +7 −1 lib/tap-harness.js
  2. +16 −0 test/isolated-conf-test.js
View
8 lib/tap-harness.js
@@ -149,6 +149,12 @@ Harness.prototype.childEnd = function (child) {
}
}
+function copyObj(o) {
+ var copied = {}
+ Object.keys(o).forEach(function (k) { copied[k] = o[k] })
+ return copied
+}
+
Harness.prototype.test = function test (name, conf, cb) {
if (this._bailedOut) return
@@ -156,7 +162,7 @@ Harness.prototype.test = function test (name, conf, cb) {
if (typeof name === "object") conf = name, name = null
if (typeof name === "function") cb = name, name = null
- conf = conf || {}
+ conf = (conf ? copyObj(conf) : {})
name = name || ""
//console.error("making test", [name, conf, cb])
View
16 test/isolated-conf-test.js
@@ -0,0 +1,16 @@
+// https://github.com/isaacs/node-tap/issues/24
+
+var tap = require("../")
+ , test = tap.test
+
+var config = {foo: "bar"}
+test("one", config, function(t) {
+ t.equal(t.conf.foo, "bar")
+ t.equal(t.conf.name, "one") // before fix this would be "two"
+ t.end()
+})
+test("two", config, function(t) {
+ t.equal(t.conf.foo, "bar")
+ t.equal(t.conf.name, "two")
+ t.end()
+})
Please sign in to comment.
Something went wrong with that request. Please try again.