/
doc.spec.js
214 lines (206 loc) · 6.8 KB
/
doc.spec.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
'use strict';
var reporters = require('../../').reporters;
var Doc = reporters.Doc;
describe('Doc reporter', function () {
var stdout;
var stdoutWrite;
var runner;
beforeEach(function () {
stdout = [];
runner = {};
stdoutWrite = process.stdout.write;
process.stdout.write = function (string) {
stdout.push(string);
};
});
describe('on suite', function () {
describe('if suite root does not exist', function () {
var expectedTitle = 'expectedTitle';
var unescapedTitle = '<div>' + expectedTitle + '</div>';
var suite = {
root: false,
title: expectedTitle
};
it('should log html with indents and expected title', function () {
runner.on = runner.once = function (event, callback) {
if (event === 'suite') {
callback(suite);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <section class="suite">\n',
' <h1>' + expectedTitle + '</h1>\n',
' <dl>\n'
];
expect(stdout).to.eql(expectedArray);
});
it('should escape title where necessary', function () {
var suite = {
root: false,
title: unescapedTitle
};
expectedTitle = '<div>' + expectedTitle + '</div>';
runner.on = runner.once = function (event, callback) {
if (event === 'suite') {
callback(suite);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <section class="suite">\n',
' <h1>' + expectedTitle + '</h1>\n',
' <dl>\n'
];
expect(stdout).to.eql(expectedArray);
});
});
describe('if suite root does exist', function () {
var suite = {
root: true
};
it('should not log any html', function () {
runner.on = runner.once = function (event, callback) {
if (event === 'suite') {
callback(suite);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
expect(stdout).to.be.empty();
});
});
});
describe('on suite end', function () {
describe('if suite root does not exist', function () {
var suite = {
root: false
};
it('should log expected html with indents', function () {
runner.on = runner.once = function (event, callback) {
if (event === 'suite end') {
callback(suite);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' </dl>\n', '</section>\n'
];
expect(stdout).to.eql(expectedArray);
});
});
describe('if suite root does exist', function () {
var suite = {
root: true
};
it('should not log any html', function () {
runner.on = runner.once = function (event, callback) {
if (event === 'suite end') {
callback(suite);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
expect(stdout).to.be.empty();
});
});
});
describe('on pass', function () {
var expectedTitle = 'some tite';
var expectedBody = 'some body';
var test = {
title: expectedTitle,
body: expectedBody,
slow: function () {
return '';
}
};
it('should log html with indents and expected title and body', function () {
runner.on = runner.once = function (event, callback) {
if (event === 'pass') {
callback(test);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <dt>' + expectedTitle + '</dt>\n',
' <dd><pre><code>' + expectedBody + '</code></pre></dd>\n'
];
expect(stdout).to.eql(expectedArray);
});
it('should escape title and body where necessary', function () {
var unescapedTitle = '<div>' + expectedTitle + '</div>';
var unescapedBody = '<div>' + expectedBody + '</div>';
test.title = unescapedTitle;
test.body = unescapedBody;
var expectedEscapedTitle = '<div>' + expectedTitle + '</div>';
var expectedEscapedBody = '<div>' + expectedBody + '</div>';
runner.on = runner.once = function (event, callback) {
if (event === 'pass') {
callback(test);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <dt>' + expectedEscapedTitle + '</dt>\n',
' <dd><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n'
];
expect(stdout).to.eql(expectedArray);
});
});
describe('on fail', function () {
var expectedTitle = 'some tite';
var expectedBody = 'some body';
var expectedError = 'some error';
var test = {
title: expectedTitle,
body: expectedBody,
slow: function () {
return '';
}
};
it('should log html with indents and expected title, body and error', function () {
runner.on = runner.once = function (event, callback) {
if (event === 'fail') {
callback(test, expectedError);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <dt class="error">' + expectedTitle + '</dt>\n',
' <dd class="error"><pre><code>' + expectedBody + '</code></pre></dd>\n',
' <dd class="error">' + expectedError + '</dd>\n'
];
expect(stdout).to.eql(expectedArray);
});
it('should escape title, body and error where necessary', function () {
var unescapedTitle = '<div>' + expectedTitle + '</div>';
var unescapedBody = '<div>' + expectedBody + '</div>';
var unescapedError = '<div>' + expectedError + '</div>';
test.title = unescapedTitle;
test.body = unescapedBody;
var expectedEscapedTitle = '<div>' + expectedTitle + '</div>';
var expectedEscapedBody = '<div>' + expectedBody + '</div>';
var expectedEscapedError = '<div>' + expectedError + '</div>';
runner.on = runner.once = function (event, callback) {
if (event === 'fail') {
callback(test, unescapedError);
}
};
Doc.call(this, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' <dt class="error">' + expectedEscapedTitle + '</dt>\n',
' <dd class="error"><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n',
' <dd class="error">' + expectedEscapedError + '</dd>\n'
];
expect(stdout).to.eql(expectedArray);
});
});
});