[Pkg-javascript-commits] [node-tap] 17/186: Add t.todo() and t.skip() methods

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:39 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 a8b592a38bc7608f35125d4cea839e1740bb45d2
Author: isaacs <i at izs.me>
Date:   Sun Aug 13 11:33:12 2017 -0700

    Add t.todo() and t.skip() methods
---
 lib/base.js       | 15 ++++++++-------
 lib/test.js       | 16 ++++++++++++++--
 test/test-test.js | 28 ++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/lib/base.js b/lib/base.js
index d7afe30..c818291 100644
--- a/lib/base.js
+++ b/lib/base.js
@@ -40,15 +40,15 @@ class Base extends MiniPass {
     this.omitVersion = !!options.omitVersion
     this.preserveWhitespace = ownOr(options, 'preserveWhitespace', true)
     this.jobs = +ownOrEnv(options, 'jobs', 'TAP_JOBS') || 0
-    this.skip = ownOr(options, 'skip', false)
-    this.todo = ownOr(options, 'todo', false)
     this.runOnly = ownOr(options, 'runOnly', false)
     this.setupParser(options)
     this.finished = false
     this.output = ''
     this.results = null
     this.bailedOut = false
-    if (this.skip || this.todo)
+    const skip = ownOr(options, 'skip', false)
+    const todo = ownOr(options, 'todo', false)
+    if (skip || todo)
       this.main = Base.prototype.main
 
     domain.create().add(this)
@@ -199,9 +199,9 @@ class Base extends MiniPass {
       queue: this.queue,
       subtests: this.subtests,
       output: this.output,
-      skip: this.skip,
-      todo: this.todo,
-      only: this.only,
+      skip: ownOr(this.options, 'skip', false),
+      todo: ownOr(this.options, 'todo', false),
+      only: ownOr(this.options, 'only', false),
       results: this.results,
       options: [
         'autoend',
@@ -217,7 +217,8 @@ class Base extends MiniPass {
         'at',
         'skip',
         'todo',
-        'only'
+        'only',
+        'runOnly'
       ].filter(k => this.options[k] !== undefined)
         .reduce((s, k) => (s[k] = this.options[k], s), {})
     })
diff --git a/lib/test.js b/lib/test.js
index 2c48356..5b16a65 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -153,6 +153,18 @@ class Test extends Base {
     return d.promise
   }
 
+  todo (name, extra, cb) {
+    extra = parseTestArgs(name, extra, cb)
+    extra.todo = true
+    return this.sub(Test, extra, Test.prototype.todo)
+  }
+
+  skip (name, extra, cb) {
+    extra = parseTestArgs(name, extra, cb)
+    extra.skip = true
+    return this.sub(Test, extra, Test.prototype.skip)
+  }
+
   only (name, extra, cb) {
     extra = parseTestArgs(name, extra, cb)
     extra.only = true
@@ -536,8 +548,8 @@ class Test extends Base {
     // Cannot get any tests after a trailing plan, or a plan of 0
     const ending = this.count !== 0 || n === 0
 
-    if (n === 0)
-      this.skip = comment || true
+    if (n === 0 && comment && !this.options.skip)
+      this.options.skip = comment
 
     this.planEnd = n
     comment = comment ? ' # ' + comment.trim() : ''
diff --git a/test/test-test.js b/test/test-test.js
index 621c81f..6f2ddec 100644
--- a/test/test-test.js
+++ b/test/test-test.js
@@ -156,3 +156,31 @@ t.test('test-point', function (t) {
 
   t.end()
 })
+
+t.test('t.only', t => {
+  const tt = new Test({ runOnly: true })
+  tt.setEncoding('utf8')
+  tt.test('1', ttt => { ttt.fail('no'); ttt.end() })
+  tt.only('2', ttt => { ttt.pass('this is fine'); ttt.end() })
+  tt.test('3', ttt => { ttt.fail('not this either'); ttt.end() })
+  tt.end()
+  const output = tt.read()
+  t.match(output, /\nok 1 - 1 # SKIP filter: only\n/)
+  t.match(output, /\n    ok 1 - this is fine\n/)
+  t.match(output, /\nok 3 - 3 # SKIP filter: only\n/)
+  t.end()
+})
+
+t.test('t.skip and t.todo', t => {
+  const tt = new Test()
+  tt.setEncoding('utf8')
+  tt.skip('1', ttt => { ttt.fail('no'); ttt.end() })
+  tt.test('2', ttt => { ttt.pass('this is fine'); ttt.end() })
+  tt.todo('3', ttt => { ttt.fail('not this either'); ttt.end() })
+  tt.end()
+  const output = tt.read()
+  t.match(output, /\nok 1 - 1 # SKIP\n/)
+  t.match(output, /\nok 3 - 3 # TODO\n/)
+  t.match(output, /\n    ok 1 - this is fine\n/)
+  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