[Pkg-javascript-commits] [node-tap] 52/186: More improvements to snapshot feature

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:42 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 7cdfc3ca6a6d4128c2123ae5e0c06651d01b94f5
Author: isaacs <i at izs.me>
Date:   Tue Oct 31 21:06:57 2017 -0700

    More improvements to snapshot feature
---
 lib/snapshot.js  |  6 +++---
 lib/test.js      | 14 +++++++++-----
 unit/snapshot.js |  6 +++---
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/snapshot.js b/lib/snapshot.js
index 40df2ac..993ccc8 100644
--- a/lib/snapshot.js
+++ b/lib/snapshot.js
@@ -18,8 +18,8 @@ class Snapshot {
     this.snapshot = null
   }
 
-  // should only ever call _one_ of match/save
-  match (data, message) {
+  // should only ever call _one_ of read/save
+  read (message) {
     // XXX test line-by-line instead of all at once
     const index = this.indexes.get(message) || 0
     this.indexes.set(message, index + 1)
@@ -32,7 +32,7 @@ class Snapshot {
         'to create snapshot files'
       )
     }
-    return this.snapshot[message + '_' + index] === data
+    return this.snapshot[message + '_' + index]
   }
 
   snap (data, message) {
diff --git a/lib/test.js b/lib/test.js
index a15a18a..71dd71a 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -60,15 +60,16 @@ class Test extends Base {
     this.pushedEnd = false
     this.jobs = ownOr(options, 'jobs', 1)
 
+    this.subtests = []
+    this.pool = new Pool()
+    this.queue = ['TAP version 13\n']
+
     this[_snapshot] = new Snapshot(this)
     this.writeSnapshot = ownOrEnv(
       options, 'snapshot', 'TAP_SNAPSHOT', true)
     if (this.writeSnapshot)
       this.teardown(_ => this[_snapshot].save())
 
-    this.subtests = []
-    this.pool = new Pool()
-    this.queue = ['TAP version 13\n']
     this.noparallel = false
     this.cb = this.domain.bind(options.cb)
     this.occupied = false
@@ -939,8 +940,11 @@ class Test extends Base {
   }
 
   get fullname () {
+    const cwd = process.cwd()
+    const main = process.argv[1]
     return (this.parent ? this.parent.fullname
-            : path.basename(process.argv[1])) +
+      : main.indexOf(cwd) === 0 ? main.substr(cwd.length + 1)
+      : path.basename(main)) +
       ' ' + (this.name || '').trim()
   }
 
@@ -958,7 +962,7 @@ class Test extends Base {
     return this.writeSnapshot
       ? this.notOk(this[_snapshot].snap(found, message),
         message, extra)
-      : this.ok(this[_snapshot].match(found, message),
+      : this.equal(found, this[_snapshot].read(message),
         message, extra)
   }
 
diff --git a/unit/snapshot.js b/unit/snapshot.js
index f582a45..b676637 100644
--- a/unit/snapshot.js
+++ b/unit/snapshot.js
@@ -19,7 +19,7 @@ t.test('actual test', t => {
 
   t.test('checking snapshot without creating throws', t => {
     const s = new Snapshot(t)
-    t.throws(_ => s.match('asdf', 'asdf'))
+    t.throws(_ => s.read('asdf', 'asdf'))
     t.end()
   })
 
@@ -31,8 +31,8 @@ t.test('actual test', t => {
 
   t.comment('now check that the snapshots are valid')
   const ss = new Snapshot(t)
-  t.ok(ss.match(fs.readFileSync(__filename, 'utf8'), 'this file'))
-  t.ok(ss.match('this is fine', 'a statement of acceptance'))
+  t.equal(fs.readFileSync(__filename, 'utf8'), ss.read('this file'))
+  t.equal('this is fine', ss.read('a statement of acceptance'))
 
   t.comment('saving without snapping anything removes the file')
   const sss = new Snapshot(t)

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