[Pkg-javascript-commits] [node-tap] 79/186: t.matchSnapshot tests. 100% lib/test.js coverage!

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:46 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 d3378638c460bc13f16613f57803302a49bd81d3
Author: isaacs <i at izs.me>
Date:   Fri Nov 10 10:49:29 2017 -0800

    t.matchSnapshot tests. 100% lib/test.js coverage!
---
 lib/test.js                            |  3 +-
 tap-snapshots/unit-test.js-TAP.test.js | 60 +++++++++++++++++++++++++---------
 unit/test.js                           | 35 +++++++++++++++++---
 3 files changed, 75 insertions(+), 23 deletions(-)

diff --git a/lib/test.js b/lib/test.js
index 1599873..85ae72a 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -111,9 +111,8 @@ class Test extends Base {
   }
 
   spawn (cmd, args, options, name) {
-    if (typeof args === 'string') {
+    if (typeof args === 'string')
       args = [ args ]
-    }
 
     args = args || []
 
diff --git a/tap-snapshots/unit-test.js-TAP.test.js b/tap-snapshots/unit-test.js-TAP.test.js
index 51403f9..ec13883 100644
--- a/tap-snapshots/unit-test.js-TAP.test.js
+++ b/tap-snapshots/unit-test.js-TAP.test.js
@@ -2041,7 +2041,7 @@ not ok 2 - fail
 
 `
 
-exports[` TAP assertions and weird stuff fullname without main > fullname without main 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff fullname without main > fullname without main 1`] = `
 TAP version 13
 # Subtest: child
     ok 1 - child
@@ -2053,14 +2053,14 @@ ok 2
 
 `
 
-exports[` TAP assertions and weird stuff comment after end > comment after end 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff comment after end > comment after end 1`] = `
 TAP version 13
 1..0
 # this is fine
 
 `
 
-exports[` TAP assertions and weird stuff grep > grep 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff grep > grep 1`] = `
 TAP version 13
 # Subtest: parent
     ok 1 - do not run this # SKIP filter: /x$/
@@ -2095,7 +2095,7 @@ ok 1 - parent # {time}
 
 `
 
-exports[` TAP assertions and weird stuff grepInvert > grepInvert 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff grepInvert > grepInvert 1`] = `
 TAP version 13
 # Subtest: parent
     ok 1 - do not run this x # SKIP filter out: /x$/
@@ -2130,7 +2130,7 @@ ok 1 - parent # {time}
 
 `
 
-exports[` TAP assertions and weird stuff autoEnd > autoEnd 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff autoEnd > autoEnd 1`] = `
 TAP version 13
 # Subtest: this should automatically end
     ok 1 - this is fine
@@ -2177,7 +2177,7 @@ not ok 6 - cannot create subtest after parent test end # {time}
 
 `
 
-exports[` TAP assertions and weird stuff endAll with test children > endAll with test children 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff endAll with test children > endAll with test children 1`] = `
 TAP version 13
 # Subtest: this is the test that never ends
     # Subtest: it goes on and on my friend
@@ -2215,7 +2215,7 @@ not ok 1 - this is the test that never ends # {time}
 
 `
 
-exports[` TAP assertions and weird stuff endAll with stdin > endAll with stdin 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff endAll with stdin > endAll with stdin 1`] = `
 TAP version 13
 # Subtest: /dev/stdin
     ok - but not ended
@@ -2231,7 +2231,7 @@ not ok 1 - /dev/stdin # {time}
 
 `
 
-exports[` TAP assertions and weird stuff endAll with bailout > endAll with bailout 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff endAll with bailout > endAll with bailout 1`] = `
 TAP version 13
 # Subtest: child
     not ok 1 - not fine
@@ -2253,7 +2253,7 @@ Bail out! # not fine
 
 `
 
-exports[` TAP assertions and weird stuff bailout with indented subs > bailout with indented subs 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff bailout with indented subs > bailout with indented subs 1`] = `
 TAP version 13
 # Subtest: 1
     1..0
@@ -2264,7 +2264,7 @@ Bail out! whoops
 
 `
 
-exports[` TAP assertions and weird stuff bailout with buffered subs > bailout with buffered subs 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff bailout with buffered subs > bailout with buffered subs 1`] = `
 TAP version 13
 ok 1 - 1 # {time} {
     1..0
@@ -2274,7 +2274,7 @@ Bail out! whoops
 
 `
 
-exports[` TAP assertions and weird stuff silent subs > silent subs 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff silent subs > silent subs 1`] = `
 TAP version 13
 # Subtest: child
     1..0
@@ -2288,7 +2288,7 @@ ok 2 - child 2 # {time}
 
 `
 
-exports[` TAP assertions and weird stuff beforeEach afterEach > beforeEach afterEach 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff beforeEach afterEach > beforeEach afterEach 1`] = `
 TAP version 13
 # Subtest: child
     # Subtest: grandkid
@@ -2310,7 +2310,7 @@ parent ae child
 
 `
 
-exports[` TAP assertions and weird stuff timeout expiration > timeout expiration 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff timeout expiration > timeout expiration 1`] = `
 TAP version 13
 # Subtest: get lost buf=false
     not ok 1 - timeout!
@@ -2352,7 +2352,7 @@ not ok 2 - get lost buf=true # {time}
 
 `
 
-exports[` TAP assertions and weird stuff timeout with subs > timeout with subs 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff timeout with subs > timeout with subs 1`] = `
 TAP version 13
 # Subtest: get lost buf=false
     # Subtest: carry on
@@ -2402,7 +2402,7 @@ not ok 2 - get lost buf=true # {time}
 
 `
 
-exports[` TAP assertions and weird stuff timeout at the last tick > timeout at the last tick 1`] = `
+exports[`unit/test.js TAP assertions and weird stuff timeout at the last tick > timeout at the last tick 1`] = `
 TAP version 13
 # Subtest: work it harder buf=false
     1..1
@@ -2437,7 +2437,7 @@ not ok 4 - timeout!
 
 `
 
-exports[` TAP addAssert > using the custom isUrl assertion 1`] = `
+exports[`unit/test.js TAP addAssert > using the custom isUrl assertion 1`] = `
 TAP version 13
 not ok 1 - expect a valid http/https url
   ---
@@ -2478,3 +2478,31 @@ ok 3 - expect a valid http/https url # SKIP
 # skip: 1
 
 `
+
+exports[`unit/test.js TAP snapshots > saving the snapshot 1`] = `
+TAP version 13
+# Subtest: child test
+    ok 1 - an object
+    ok 2 - string
+    ok 3 - must match snapshot # TODO later
+    1..3
+    # todo: 1
+ok 1 - child test # {time}
+
+1..1
+
+`
+
+exports[`unit/test.js TAP snapshots > verifying the snapshot 1`] = `
+TAP version 13
+# Subtest: child test
+    ok 1 - an object
+    ok 2 - string
+    ok 3 - must match snapshot # TODO later
+    1..3
+    # todo: 1
+ok 1 - child test # {time}
+
+1..1
+
+`
diff --git a/unit/test.js b/unit/test.js
index 20776dd..abfd6c0 100644
--- a/unit/test.js
+++ b/unit/test.js
@@ -1,4 +1,6 @@
 const t = require('../')
+const fs = require('fs')
+const path = require('path')
 const Test = t.Test
 const util = require('util')
 const assert = require('assert')
@@ -564,13 +566,13 @@ t.test('assertions and weird stuff', t => {
 
     'fullname without main': tt => {
       const main = process.argv[1]
-      tt.teardown(() => process.argv[1] = main)
       process.argv[1] = ''
       tt.test('child', tt => {
         tt.pass(tt.fullname)
         tt.end()
       })
       tt.pass(tt.fullname)
+      process.argv[1] = main
       tt.end()
     },
 
@@ -751,7 +753,6 @@ t.test('assertions and weird stuff', t => {
       const buf = [ false, true ]
       buf.forEach(buf => {
         t.test('work it harder buf=' + buf, { buffered: buf, timeout: 1 }, t => {
-          const fs = require('fs')
           t.plan(1)
           const start = Date.now()
           const finish = start + 10
@@ -826,8 +827,6 @@ t.test('addAssert', t => {
 })
 
 t.test('spawn', t => {
-  const fs = require('fs')
-  const path = require('path')
   const okjs = path.resolve(__dirname, '../__ok.js')
   t.teardown(() => fs.unlinkSync(okjs))
   fs.writeFileSync(okjs, "require('./').pass('this is fine')\n")
@@ -846,4 +845,30 @@ t.test('spawn', t => {
   t.end()
 })
 
-t.test('snapshots')
+t.test('snapshots', t => {
+  const Snapshot = require('../lib/snapshot.js')
+  const snap = [ true, false ]
+  const outputs = snap.map(snap => {
+    const tt = new Test({
+      snapshot: snap,
+      name: 'deleteme',
+      buffered: true
+    })
+    tt.test('child test', { snapshot: snap }, tt => {
+      tt.matchSnapshot({ foo: 'bar' }, 'an object')
+      tt.matchSnapshot('some string \\ \` ${process.env.FOO}', 'string')
+      tt.matchSnapshot('do this eventually', { todo: 'later' })
+      tt.end()
+    })
+    tt.emit('teardown')
+    tt.end()
+    return tt.output
+  })
+
+  t.matchSnapshot(clean(outputs[0]), 'saving the snapshot')
+  t.matchSnapshot(clean(outputs[1]), 'verifying the snapshot')
+  fs.unlinkSync(path.resolve(__dirname, '..',
+    'tap-snapshots', 'unit-test.js-deleteme.test.js'))
+
+  t.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