-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
163 lines (136 loc) · 4.18 KB
/
test.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*!
* dush-tap-reporter <https://github.com/tunnckoCore/dush-tap-reporter>
*
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var test = require('mukla')
var dush = require('dush')
var extend = require('extend-shallow')
var reporter = require('./index')
var failing = {
title: 'some failing test',
index: 23,
reason: new Error('abc quxie')
}
function fixture (opts) {
var app = dush()
app.output = ''
return app
.use(reporter(extend({
writeLine: function () {
var args = [].slice.call(arguments)
app.output += args.join(' ') + '\n'
}
}, opts)))
}
test('should handle start event', function (done) {
var app = fixture()
app.emit('start')
test.strictEqual(app.output.trim(), 'TAP version 13')
done()
})
test('should handle passing test', function (done) {
var app = fixture()
app.emit('pass', app, {
title: 'foo bar',
index: 2
})
test.strictEqual(/# :\) foo bar/.test(app.output), true)
test.strictEqual(/ok 2 - foo bar/.test(app.output), true)
done()
})
test('should handle main errors', function (done) {
var app = fixture()
app.emit('fail', app, failing)
test.strictEqual(/# :\( some failing test/.test(app.output), true)
test.strictEqual(/name: Error/.test(app.output), true)
test.strictEqual(/message: abc quxie/.test(app.output), true)
test.strictEqual(/ {2}at: Object/.test(app.output), true)
test.strictEqual(/test\.js:20:11/.test(app.output), true)
test.strictEqual(/ {2}---/.test(app.output), true)
done()
})
test('should not output "message" if empty', function (done) {
var app = fixture()
var err = new Error('')
app.emit('fail', app, extend(failing, { reason: err }))
var result = [
'# :( some failing test',
'not ok 23 - some failing test',
' ---',
' name: Error',
' at: Object.<anonymous> (test.js:70:13)',
' ...',
''
].join('\n')
test.strictEqual(app.output, result)
done()
})
test('should output "expected" when err.expected exist', function (done) {
var error = new Error('sasa bar')
error.expected = 'barry123zeta'
var app = fixture()
app.emit('fail', app, extend(failing, {
reason: error
}))
test.strictEqual(/name: Error/.test(app.output), true)
test.strictEqual(/message: sasa bar/.test(app.output), true)
test.strictEqual(/expected: 'barry123zeta'/.test(app.output), true)
test.strictEqual(/actual:/.test(app.output), false)
done()
})
test('should output "actual" if exist', function (done) {
var app = fixture()
var err = new Error("123 === 'baz'")
err.actual = 123
err.expected = 'baz'
app.emit('fail', app, extend(failing, { reason: err }))
test.strictEqual(/ {2}actual: 123/.test(app.output), true)
test.strictEqual(/ {2}expected: 'baz'/.test(app.output), true)
test.strictEqual(/ {2}message: 123 === 'baz'/.test(app.output), true)
done()
})
test('should output "stack" with relative paths if opts.showStack: true', function (done) {
var app = fixture({
showStack: true
})
app.emit('fail', app, failing)
test.strictEqual(/ {2}stack:/.test(app.output), true)
test.strictEqual(/ {4}at Object\.tryCatch/.test(app.output), true)
test.strictEqual(/ {4}at Object\.tryCatch/.test(app.output), true)
test.strictEqual(/test.js:/.test(app.output), true)
done()
})
test('should handle failing test suite with finish event', function (done) {
var app = fixture({
stats: {
count: 4,
pass: 3,
fail: 1
}
})
app.emit('finish', app)
test.strictEqual(/1\.\.4/.test(app.output), true)
test.strictEqual(/# tests 4/.test(app.output), true)
test.strictEqual(/# pass 3/.test(app.output), true)
test.strictEqual(/# fail 1/.test(app.output), true)
test.strictEqual(/# ok/.test(app.output), false)
done()
})
test('should output passing test suite', function (done) {
var app = fixture()
app.stats = {
count: 3,
pass: 3,
fail: 0
}
app.emit('finish', app)
test.strictEqual(/# tests 3/.test(app.output), true)
test.strictEqual(/# pass 3/.test(app.output), true)
test.strictEqual(/# ok/.test(app.output), true)
test.strictEqual(/# fail/.test(app.output), false)
done()
})