File: test.js

package info (click to toggle)
node-tap 12.0.1+ds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,916 kB
  • sloc: makefile: 84; sh: 75
file content (107 lines) | stat: -rw-r--r-- 2,328 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var t = require('../')
var loop = require('./')
var obj = {}

t.test('basic passing operation', function (t) {
  var i = 0
  loop(obj, [
    function (cb) {
      t.equal(this, obj, 'this is correct 1')
      t.equal(i, 0, '0')
      cb()
      i++
    },
    function () {
      t.equal(this, obj, 'this is correct 2')
      t.equal(i++, 1, '1')
      return Promise.resolve(true)
    },
    function (cb) {
      t.equal(this, obj, 'this is correct 3')
      t.equal(i++, 2, '2')
      setTimeout(cb)
    },
    function (cb) {
      t.equal(this, obj, 'this is correct 4')
      t.equal(i++, 3, '3')
      process.nextTick(cb)
    }
  ], function () {
    t.equal(this, obj, 'this is correct 5')
    t.equal(i++, 4, '4')
    t.end()
  }, function (er) {
    throw er
  })
  t.equal(i, 2, '2, after loop() call')
})

t.test('throws', function (t) {
  loop(obj, [
    function (cb) {
      t.equal(this, obj, 'this is correct')
      throw new Error('foo')
    },
    function () {
      t.fail('should not get here')
    }
  ], function () {
    t.fail('should not get here')
  }, function (er) {
    t.match(er, { message: 'foo' })
    t.end()
  })
})

t.test('all sync', function (t) {
  var i = 0
  loop(obj, [
    function (cb) { t.equal(i++, 0); cb() },
    function (cb) { t.equal(i++, 1); cb() },
    function (cb) { t.equal(i++, 2); cb() },
    function (cb) { t.equal(i++, 3); cb() },
    function (cb) { t.equal(i++, 4); cb() }
  ], function () {
    t.equal(i++, 5)
  }, function (er) {
    throw er
  })
  t.equal(i, 6)
  t.end()
})

t.test('broken promise', function (t) {
  loop(obj, [
    function (cb) {
      t.equal(this, obj, 'this is correct')
      return Promise.reject(new Error('foo'))
    },
    function () {
      t.fail('should not get here')
    }
  ], function () {
    t.fail('should not get here')
  }, function (er) {
    t.equal(this, obj, 'this is correct')
    t.match(er, { message: 'foo' })
    t.end()
  })
})

t.test('cb err', function (t) {
  loop(obj, [
    function (cb) {
      t.equal(this, obj, 'this is correct')
      cb(new Error('foo'))
    },
    function () {
      t.fail('should not get here')
    }
  ], function () {
    t.fail('should not get here')
  }, function (er) {
    t.equal(this, obj, 'this is correct')
    t.match(er, { message: 'foo' })
    t.end()
  })
})