[Pkg-javascript-commits] [node-tap] 55/186: Key snapshot files by the main module and root test name only

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:43 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-tap.

commit c293da888ceb921b260631332a50b80679fdb029
Author: isaacs <i at izs.me>
Date:   Tue Oct 31 21:57:32 2017 -0700

    Key snapshot files by the main module and root test name only
---
 lib/test.js                                        | 16 ++++-
 ...unit-test.js-TAP-short-output-checks-comment.js |  5 --
 ...-test.js-TAP-short-output-checks-expect-fail.js |  5 --
 ...test.js-TAP-short-output-checks-no-plan-fail.js |  6 --
 ...unit-test.js-TAP-short-output-checks-no-plan.js |  5 --
 ...it-test.js-TAP-short-output-checks-plan-fail.js |  6 --
 .../unit-test.js-TAP-short-output-checks-plan.js   |  5 --
 .../unit-test.js-TAP-short-output-checks-sub.js    | 19 ------
 .../unit-test.js-TAP-short-output-checks-todo.js   | 20 ------
 tap-snapshots/unit-test.js-TAP.js                  | 71 ++++++++++++++++++++++
 10 files changed, 84 insertions(+), 74 deletions(-)

diff --git a/lib/test.js b/lib/test.js
index 71dd71a..785cfe9 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -64,11 +64,21 @@ class Test extends Base {
     this.pool = new Pool()
     this.queue = ['TAP version 13\n']
 
-    this[_snapshot] = new Snapshot(this)
+    // snapshots are keyed off of the main file that loads the
+    // root test object. Typically, this is the TAP object.
+    // To do this, we climb the ladder and only save in the teardown
+    // of that root (parentless) test object.  This allows handling
+    // cases where the same test name can be used multiple times
+    // in a single test file, which would otherwise clobber snapshots.
     this.writeSnapshot = ownOrEnv(
       options, 'snapshot', 'TAP_SNAPSHOT', true)
-    if (this.writeSnapshot)
-      this.teardown(_ => this[_snapshot].save())
+    if (this.parent && this.parent[_snapshot])
+      this[_snapshot] = this.parent[_snapshot]
+    else {
+      this[_snapshot] = new Snapshot(this)
+      if (this.writeSnapshot)
+        this.teardown(_ => this[_snapshot].save())
+    }
 
     this.noparallel = false
     this.cb = this.domain.bind(options.cb)
diff --git a/tap-snapshots/unit-test.js-TAP-short-output-checks-comment.js b/tap-snapshots/unit-test.js-TAP-short-output-checks-comment.js
deleted file mode 100644
index ccbc561..0000000
--- a/tap-snapshots/unit-test.js-TAP-short-output-checks-comment.js
+++ /dev/null
@@ -1,5 +0,0 @@
-'use strict'
-exports[`comment_0`] = `TAP version 13
-# this is fine
-1..0
-`
diff --git a/tap-snapshots/unit-test.js-TAP-short-output-checks-expect-fail.js b/tap-snapshots/unit-test.js-TAP-short-output-checks-expect-fail.js
deleted file mode 100644
index 5fd2df7..0000000
--- a/tap-snapshots/unit-test.js-TAP-short-output-checks-expect-fail.js
+++ /dev/null
@@ -1,5 +0,0 @@
-'use strict'
-exports[`expect fail_0`] = `TAP version 13
-1..1
-ok 1 - this is fine
-`
diff --git a/tap-snapshots/unit-test.js-TAP-short-output-checks-no-plan-fail.js b/tap-snapshots/unit-test.js-TAP-short-output-checks-no-plan-fail.js
deleted file mode 100644
index bb57c07..0000000
--- a/tap-snapshots/unit-test.js-TAP-short-output-checks-no-plan-fail.js
+++ /dev/null
@@ -1,6 +0,0 @@
-'use strict'
-exports[`no plan fail_0`] = `TAP version 13
-not ok 1 - this is fine
-1..1
-# failed 1 test
-`
diff --git a/tap-snapshots/unit-test.js-TAP-short-output-checks-no-plan.js b/tap-snapshots/unit-test.js-TAP-short-output-checks-no-plan.js
deleted file mode 100644
index bc13dec..0000000
--- a/tap-snapshots/unit-test.js-TAP-short-output-checks-no-plan.js
+++ /dev/null
@@ -1,5 +0,0 @@
-'use strict'
-exports[`no plan_0`] = `TAP version 13
-ok 1 - this is fine
-1..1
-`
diff --git a/tap-snapshots/unit-test.js-TAP-short-output-checks-plan-fail.js b/tap-snapshots/unit-test.js-TAP-short-output-checks-plan-fail.js
deleted file mode 100644
index aef3857..0000000
--- a/tap-snapshots/unit-test.js-TAP-short-output-checks-plan-fail.js
+++ /dev/null
@@ -1,6 +0,0 @@
-'use strict'
-exports[`plan fail_0`] = `TAP version 13
-1..1
-not ok 1 - this is fine
-# failed 1 test
-`
diff --git a/tap-snapshots/unit-test.js-TAP-short-output-checks-plan.js b/tap-snapshots/unit-test.js-TAP-short-output-checks-plan.js
deleted file mode 100644
index 98d24f7..0000000
--- a/tap-snapshots/unit-test.js-TAP-short-output-checks-plan.js
+++ /dev/null
@@ -1,5 +0,0 @@
-'use strict'
-exports[`plan_0`] = `TAP version 13
-1..1
-ok 1 - this is fine
-`
diff --git a/tap-snapshots/unit-test.js-TAP-short-output-checks-sub.js b/tap-snapshots/unit-test.js-TAP-short-output-checks-sub.js
deleted file mode 100644
index 646496e..0000000
--- a/tap-snapshots/unit-test.js-TAP-short-output-checks-sub.js
+++ /dev/null
@@ -1,19 +0,0 @@
-'use strict'
-exports[`sub_0`] = `TAP version 13
-# Subtest: named child
-    ok 1 - this is fine
-    1..1
-ok 1 - named child # {time}
-
-# Subtest: named_function
-    1..1
-    ok 1 - also fine
-ok 2 - named_function # {time}
-
-# Subtest: promisey
-    ok 1 - i promise, it is fine
-    1..1
-ok 3 - promisey # {time}
-
-1..3
-`
diff --git a/tap-snapshots/unit-test.js-TAP-short-output-checks-todo.js b/tap-snapshots/unit-test.js-TAP-short-output-checks-todo.js
deleted file mode 100644
index f1a9b37..0000000
--- a/tap-snapshots/unit-test.js-TAP-short-output-checks-todo.js
+++ /dev/null
@@ -1,20 +0,0 @@
-'use strict'
-exports[`todo_0`] = `TAP version 13
-not ok 1 - i will do this later # TODO
-  ---
-  at:
-    line: 22
-    column: 10
-    file: unit/test.js
-    function: todo
-  source: |
-    tt.fail('i will do this later', { todo: true })
-  ...
-
-ok 2 - i will do this later # TODO
-not ok 3 - this is fine # SKIP
-ok 4 - i did not do this later # SKIP
-1..4
-# todo: 2
-# skip: 2
-`
diff --git a/tap-snapshots/unit-test.js-TAP.js b/tap-snapshots/unit-test.js-TAP.js
new file mode 100644
index 0000000..d1e90e6
--- /dev/null
+++ b/tap-snapshots/unit-test.js-TAP.js
@@ -0,0 +1,71 @@
+'use strict'
+exports[`no plan_0`] = `TAP version 13
+ok 1 - this is fine
+1..1
+`
+
+exports[`plan_0`] = `TAP version 13
+1..1
+ok 1 - this is fine
+`
+
+exports[`comment_0`] = `TAP version 13
+# this is fine
+1..0
+`
+
+exports[`todo_0`] = `TAP version 13
+not ok 1 - i will do this later # TODO
+  ---
+  at:
+    line: 22
+    column: 10
+    file: unit/test.js
+    function: todo
+  source: |
+    tt.fail('i will do this later', { todo: true })
+  ...
+
+ok 2 - i will do this later # TODO
+not ok 3 - this is fine # SKIP
+ok 4 - i did not do this later # SKIP
+1..4
+# todo: 2
+# skip: 2
+`
+
+exports[`no plan fail_0`] = `TAP version 13
+not ok 1 - this is fine
+1..1
+# failed 1 test
+`
+
+exports[`plan fail_0`] = `TAP version 13
+1..1
+not ok 1 - this is fine
+# failed 1 test
+`
+
+exports[`expect fail_0`] = `TAP version 13
+1..1
+ok 1 - this is fine
+`
+
+exports[`sub_0`] = `TAP version 13
+# Subtest: named child
+    ok 1 - this is fine
+    1..1
+ok 1 - named child # {time}
+
+# Subtest: named_function
+    1..1
+    ok 1 - also fine
+ok 2 - named_function # {time}
+
+# Subtest: promisey
+    ok 1 - i promise, it is fine
+    1..1
+ok 3 - promisey # {time}
+
+1..3
+`

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tap.git



More information about the Pkg-javascript-commits mailing list