[Pkg-javascript-commits] [node-tap] 72/186: Add more test tests, remove some dead code
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 1 16:40:45 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 aeb291c12c6069f8ead55b1541023ab94f642fe4
Author: isaacs <i at izs.me>
Date: Thu Nov 9 13:58:32 2017 +0000
Add more test tests, remove some dead code
---
lib/test.js | 13 +-
tap-snapshots/unit-test.js-TAP.test.js | 247 +++++++++++++++++++++++++++------
unit/test.js | 86 +++++++++++-
3 files changed, 292 insertions(+), 54 deletions(-)
diff --git a/lib/test.js b/lib/test.js
index e22bf22..e0b7a57 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -380,7 +380,7 @@ class Test extends Base {
cb()
}
- onbufferedend (p, er) {
+ onbufferedend (p) {
delete p.ondone
p.results = p.results || {}
p.readyToProcess = true
@@ -398,13 +398,11 @@ class Test extends Base {
p.options.time = p.time
if (this.occupied === p)
this.occupied = null
- if (er)
- this.threw(er)
p.deferred.resolve(this)
this.process()
}
- onindentedend (p, er) {
+ onindentedend (p) {
delete p.ondone
this.debug('onindentedend', p)
this.noparallel = false
@@ -421,8 +419,9 @@ class Test extends Base {
p.timeout()
else
p.setTimeout(false)
- this.debug('onindentedend %s(%s)', this.name, p.name, er || 'ok')
- assert(this.occupied === p)
+ this.debug('onindentedend %s(%s)', this.name, p.name)
+ if (!p.bailedOut)
+ assert.equal(this.occupied, p)
this.occupied = null
this.debug('OIE(%s) b>shift into queue', this.name, this.queue)
p.options.stack = ''
@@ -431,8 +430,6 @@ class Test extends Base {
this.printResult(p.passing(), p.name, p.options, true)
this.debug('OIE(%s) shifted into queue', this.name, this.queue)
- if (er)
- this.threw(er)
p.deferred.resolve(this)
this.process()
}
diff --git a/tap-snapshots/unit-test.js-TAP.test.js b/tap-snapshots/unit-test.js-TAP.test.js
index e449a79..cde31fe 100644
--- a/tap-snapshots/unit-test.js-TAP.test.js
+++ b/tap-snapshots/unit-test.js-TAP.test.js
@@ -469,6 +469,87 @@ not ok 1 - this is fine
`
+exports[`unit/test.js TAP short output checks fail then end no options > fail then end 1`] = `
+TAP version 13
+# Subtest: child
+ not ok 1 - this is not ok
+ ---
+ at:
+ line: #
+ column: #
+ file: unit/test.js
+ type: Test
+ function: tt.test.tt
+ stack: |
+ {STACK}
+ source: |
+ tt.fail('this is not ok')
+ ...
+
+ 1..1
+ # failed 1 test
+not ok 1 - child # {time}
+
+1..1
+# failed 1 test
+
+`
+
+exports[`unit/test.js TAP short output checks fail then end buffered > fail then end 1`] = `
+TAP version 13
+# Subtest: child
+ not ok 1 - this is not ok
+ ---
+ at:
+ line: #
+ column: #
+ file: unit/test.js
+ type: Test
+ function: tt.test.tt
+ stack: |
+ {STACK}
+ source: |
+ tt.fail('this is not ok')
+ ...
+
+ 1..1
+ # failed 1 test
+not ok 1 - child # {time}
+
+1..1
+# failed 1 test
+
+`
+
+exports[`unit/test.js TAP short output checks fail then end bailout > fail then end 1`] = `
+TAP version 13
+# Subtest: child
+ not ok 1 - this is not ok
+ ---
+ at:
+ line: #
+ column: #
+ file: unit/test.js
+ type: Test
+ function: tt.test.tt
+ stack: |
+ {STACK}
+ source: |
+ tt.fail('this is not ok')
+ ...
+
+ Bail out! # this is not ok
+BAILOUT: "# this is not ok"
+`
+
+exports[`unit/test.js TAP short output checks fail then end runOnly > fail then end 1`] = `
+TAP version 13
+ok 1 - child # SKIP filter: only
+1..1
+# skip: 1
+
+`
+
exports[`unit/test.js TAP short output checks planned skip no options > planned skip 1`] = `
TAP version 13
1..0 # skip this one
@@ -1982,60 +2063,136 @@ ok 2 - this should also end # {time}
`
-exports[` TAP assertions and weird stuff endAll > endAll 1`] = `
-TAP version 13
-# Subtest: tests that have an endall method
- # Subtest: this is the test that never ends
- # Subtest: it goes on and on my friend
- ok 1 - this is ok
- # Subtest: misbehaving child
- not ok 1 - test unfinished
- ---
- stack: |
- {STACK}
- test: misbehaving child
- at:
- line: #
- column: #
- file: unit/test.js
- function: Test.tt.test.tt
- source: |
- tt.test('misbehaving child', () => new Promise(()=>{}))
- ...
-
- 1..1
- # failed 1 test
- not ok 2 - misbehaving child # {time}
+exports[` 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
+ ok 1 - this is ok
+ # Subtest: misbehaving child
+ not ok 1 - test unfinished
+ ---
+ stack: |
+ {STACK}
+ test: misbehaving child
+ at:
+ line: #
+ column: #
+ file: unit/test.js
+ function: Test.tt.test.tt
+ source: |
+ tt.test('misbehaving child', () => new Promise(()=>{}))
+ ...
- 1..2
- # failed 1 of 2 tests
- not ok 1 - it goes on and on my friend # {time}
+ 1..1
+ # failed 1 test
+ not ok 2 - misbehaving child # {time}
- ok 2 - some queue stuff
1..2
# failed 1 of 2 tests
- not ok 1 - this is the test that never ends # {time}
+ not ok 1 - it goes on and on my friend # {time}
- 1..1
- # failed 1 test
-not ok 1 - tests that have an endall method # {time}
+ ok 2 - some queue stuff
+ 1..2
+ # failed 1 of 2 tests
+not ok 1 - this is the test that never ends # {time}
-# Subtest: endAll on a stdin
- # Subtest: /dev/stdin
- ok - but not ended
-
- not ok 2 - test unfinished
-
- 1..2
- # failed 1 of 2 tests
- not ok 1 - /dev/stdin # {time}
+1..1
+# failed 1 test
+
+`
+
+exports[` TAP assertions and weird stuff endAll with stdin > endAll with stdin 1`] = `
+TAP version 13
+# Subtest: /dev/stdin
+ ok - but not ended
- 1..1
- # failed 1 test
-not ok 2 - endAll on a stdin # {time}
+ not ok 2 - test unfinished
+
+ 1..2
+ # failed 1 of 2 tests
+not ok 1 - /dev/stdin # {time}
+
+1..1
+# failed 1 test
+
+`
+
+exports[` TAP assertions and weird stuff endAll with bailout > endAll with bailout 1`] = `
+TAP version 13
+# Subtest: child
+ not ok 1 - not fine
+ ---
+ at:
+ line: #
+ column: #
+ file: unit/test.js
+ type: Test
+ function: tt.test.tt
+ stack: |
+ {STACK}
+ source: |
+ tt.fail('not fine')
+ ...
+
+ Bail out! # not fine
+Bail out! # not fine
+
+`
+
+exports[` TAP assertions and weird stuff bailout with indented subs > bailout with indented subs 1`] = `
+TAP version 13
+# Subtest: 1
+ 1..0
+ok 1 - 1 # {time}
+
+# Subtest: 2
+Bail out! whoops
+
+`
+
+exports[` TAP assertions and weird stuff bailout with buffered subs > bailout with buffered subs 1`] = `
+TAP version 13
+ok 1 - 1 # {time} {
+ 1..0
+}
+
+Bail out! whoops
+
+`
+
+exports[` TAP assertions and weird stuff silent subs > silent subs 1`] = `
+TAP version 13
+# Subtest: child
+ 1..0
+ok 1 - child # {time}
+
+# Subtest: child 2
+ 1..0
+ok 2 - child 2 # {time}
1..2
-# failed 2 of 2 tests
+
+`
+
+exports[` TAP assertions and weird stuff beforeEach afterEach > beforeEach afterEach 1`] = `
+TAP version 13
+# Subtest: child
+ # Subtest: grandkid
+ 1..0
+ ok 1 - grandkid # {time}
+
+ 1..1
+ok 1 - child # {time}
+
+1..1
+STDERR:
+parent be child
+parent be grandkid
+child be grandkid
+in test
+child ae grandkid
+parent ae grandkid
+parent ae child
`
diff --git a/unit/test.js b/unit/test.js
index 22c0cca..0e86c1d 100644
--- a/unit/test.js
+++ b/unit/test.js
@@ -3,6 +3,7 @@ const Test = t.Test
const util = require('util')
const assert = require('assert')
const EE = require('events').EventEmitter
+const MiniPass = require('minipass')
// set this forcibly so it doesn't interfere with other tests.
process.env.TAP_DIAG === ''
@@ -82,6 +83,14 @@ t.test('short output checks', t => {
tt.fail('this is fine', { diagnostic: false })
},
+ 'fail then end': tt => {
+ tt.test('child', tt => {
+ tt.fail('this is not ok')
+ tt.end()
+ })
+ tt.end()
+ },
+
'planned skip': tt => {
tt.plan(0, 'skip this one')
},
@@ -609,6 +618,82 @@ t.test('assertions and weird stuff', t => {
t.autoend()
})
},
+
+ 'endAll with test children': tt => {
+ tt.test('this is the test that never ends', tt => {
+ tt.test('it goes on and on my friend', tt => {
+ tt.pass('this is ok')
+ tt.test('misbehaving child', () => new Promise(()=>{}))
+ })
+ tt.pass('some queue stuff')
+ })
+ tt.endAll()
+ },
+
+ 'endAll with stdin': tt => {
+ const s = new MiniPass()
+ tt.stdin({ tapStream: s })
+ s.write('TAP version 13\nok - but not ended\n')
+ tt.endAll()
+ },
+
+ 'endAll with bailout': tt => {
+ tt.on('bailout', reason => tt.endAll())
+
+ tt.test('child', { bail: true }, tt => {
+ tt.fail('not fine')
+ tt.end()
+ })
+ },
+
+ 'bailout with indented subs': tt => {
+ tt.test('1', tt => tt.end())
+ tt.test('2', tt => Promise.resolve(null))
+ tt.test('3', tt => setTimeout(() => tt.end()))
+ process.nextTick(() => tt.bailout('whoops'))
+ tt.end()
+ },
+
+ 'bailout with buffered subs': tt => {
+ const o = { buffered: true }
+ tt.test('1', o, tt => tt.end())
+ tt.test('2', o, tt => Promise.resolve(null))
+ tt.test('3', o, tt => setTimeout(() => tt.end()))
+ process.nextTick(() => tt.bailout('whoops'))
+ tt.end()
+ },
+
+ 'silent subs': tt => {
+ tt.test('child', tt => Promise.resolve(null))
+ tt.test('shhh', { silent: true }, tt => tt.end())
+ tt.test('child 2', tt => tt.end())
+ tt.end()
+ },
+
+ 'beforeEach afterEach': tt => {
+ tt.beforeEach(function (cb) {
+ console.error('parent be', this.name)
+ cb()
+ })
+ tt.afterEach(function (cb) {
+ console.error('parent ae', this.name)
+ cb()
+ })
+ tt.test('child', tt => {
+ tt.beforeEach(function (cb) {
+ console.error('child be', this.name)
+ cb()
+ })
+ tt.afterEach(function (cb) {
+ console.error('child ae', this.name)
+ cb()
+ })
+ tt.test('grandkid', tt => Promise.resolve(console.error('in test')))
+ tt.end()
+ })
+ tt.end()
+ },
+
}
const keys = Object.keys(cases)
@@ -669,7 +754,6 @@ t.test('addAssert', t => {
return t.end()
})
-t.test('endAll')
t.test('snapshots')
t.test('spawn')
t.test('stdin')
--
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