[Pkg-javascript-commits] [node-tap] 56/186: handle ` chars in snapshot data

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 b0f84f558d62f7bb5ade2427e985df3d77483a2f
Author: isaacs <i at izs.me>
Date:   Tue Oct 31 22:06:45 2017 -0700

    handle ` chars in snapshot data
---
 lib/snapshot.js                   |  6 +++++-
 tap-snapshots/unit-test.js-TAP.js | 18 ++++++++++++++++++
 unit/test.js                      |  9 +++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/lib/snapshot.js b/lib/snapshot.js
index 993ccc8..f250876 100644
--- a/lib/snapshot.js
+++ b/lib/snapshot.js
@@ -48,7 +48,11 @@ class Snapshot {
     else {
       const data = `'use strict'\n` + (
         Object.keys(this.snapshot).map(s =>
-          `exports[\`${s}\`] = \`${this.snapshot[s]}\`\n`).join('\n'))
+          `exports[\`${
+            s.replace(/\`/g, '\\\`')
+          }\`] = \`${
+            this.snapshot[s].replace(/\`/g, '\\\`')
+          }\`\n`).join('\n'))
       mkdirp.sync(path.dirname(this.file))
       writeFile.sync(this.file, data, 'utf8')
     }
diff --git a/tap-snapshots/unit-test.js-TAP.js b/tap-snapshots/unit-test.js-TAP.js
index d1e90e6..93c51d8 100644
--- a/tap-snapshots/unit-test.js-TAP.js
+++ b/tap-snapshots/unit-test.js-TAP.js
@@ -34,6 +34,24 @@ ok 4 - i did not do this later # SKIP
 # skip: 2
 `
 
+exports[`only_0`] = `TAP version 13
+# "run this with a comment" has \`only\` set but all tests run
+# Subtest: run this with a comment
+    1..0
+ok 1 - run this with a comment # {time}
+
+# Subtest: this is a child test
+    1..0
+ok 2 - this is a child test # {time}
+
+# "run this with a comment" has \`only\` set but all tests run
+# Subtest: run this with a comment
+    1..0
+ok 3 - run this with a comment # {time}
+
+1..3
+`
+
 exports[`no plan fail_0`] = `TAP version 13
 not ok 1 - this is fine
 1..1
diff --git a/unit/test.js b/unit/test.js
index 619ae7b..99ddf69 100644
--- a/unit/test.js
+++ b/unit/test.js
@@ -30,6 +30,15 @@ t.test('short output checks', t => {
       tt.end()
     },
 
+    'only': tt => {
+      tt.runOnly = false
+      tt.only('run this with a comment', tt => tt.end())
+      tt.test('this is a child test', tt => tt.end())
+      tt.test('run this with a comment', { only: true },
+              tt => tt.end())
+      tt.end()
+    },
+
     'no plan fail': tt => {
       tt.fail('this is fine', { diagnostic: false })
       tt.end()

-- 
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