-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathe2e.spec.ts
376 lines (325 loc) · 11.5 KB
/
e2e.spec.ts
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
import defaultBuilder, { type Builder, TestCase, TestSuite } from '../dist';
//@ts-ignore
import rmdir from 'rimraf';
import fs from 'fs';
describe('JUnit Report builder', () => {
let builder: Builder;
beforeEach(() => (builder = defaultBuilder.newBuilder()));
beforeAll((done) =>
rmdir('build/tmp/test_resources', (error: any) => {
if (error) {
throw new Error(error);
}
done();
}),
);
const reportWith = (content: string) => '<?xml version="1.0" encoding="UTF-8"?>\n' + content;
it('should produce a report identical to the expected one', () => {
builder.testCase().className('root.test.Class1');
const suite1: TestSuite = builder.testSuite().name('first.Suite');
suite1.testCase().name('Second test');
const case2: TestCase = suite1.testCase();
case2
.className('suite1.test.Class2')
.name('Third test')
.file('./path-to/the-test-file.coffee')
.property('property name', 'property value')
.multilineProperty('property name 2', 'property value 2');
const suite2 = builder.testSuite().name('second.Suite');
suite2.testCase().failure('Failure message');
suite2.testCase().stacktrace('Stacktrace');
suite2.testCase().skipped();
builder.writeTo('build/tmp/test_resources/actual_report.xml');
const actual = fs.readFileSync('build/tmp/test_resources/actual_report.xml').toString().trim();
const expected = fs.readFileSync('spec/expected_report.xml').toString().trim();
expect(actual).toBe(expected);
});
it('should produce an empty list of test suites when nothing reported', () => {
expect(builder.build()).toBe(
// prettier-ignore
'<?xml version="1.0" encoding="UTF-8"?>\n' +
'<testsuites tests="0" failures="0" errors="0" skipped="0"/>',
);
});
it('should set testsuites name', () => {
builder.name('testSuitesName');
expect(builder.build()).toBe(
// prettier-ignore
'<?xml version="1.0" encoding="UTF-8"?>\n' +
'<testsuites name="testSuitesName" tests="0" failures="0" errors="0" skipped="0"/>',
);
});
it('should produce an empty test suite when a test suite reported', () => {
builder.testSuite();
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="0" failures="0" errors="0" skipped="0">\n' +
' <testsuite tests="0" failures="0" errors="0" skipped="0"/>\n' +
'</testsuites>',
),
);
});
it('should produce a root test case when reported', () => {
builder.testCase();
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="0" skipped="0">\n' +
' <testcase/>\n' +
'</testsuites>',
),
);
});
it('should produce a root test case with failure when reported', () => {
builder.testCase().failure('it failed');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="1" errors="0" skipped="0">\n' +
' <testcase>\n' +
' <failure message="it failed"/>\n' +
' </testcase>\n' +
'</testsuites>',
),
);
});
it('should produce a root test case with failure and type when reported', () => {
builder.testCase().failure('it failed', 'the type');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="1" errors="0" skipped="0">\n' +
' <testcase>\n' +
' <failure message="it failed" type="the type"/>\n' +
' </testcase>\n' +
'</testsuites>',
),
);
});
it('should produce a root test case with error when reported', () => {
builder.testCase().error('it errored');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="1" skipped="0">\n' +
' <testcase>\n' +
' <error message="it errored"/>\n' +
' </testcase>\n' +
'</testsuites>',
),
);
});
it('should produce a root test case with error, type and content when reported', () => {
builder.testCase().error('it errored', 'the type', 'the content');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="1" skipped="0">\n' +
' <testcase>\n' +
' <error message="it errored" type="the type"><![CDATA[the content]]></error>\n' +
' </testcase>\n' +
'</testsuites>',
),
);
});
it('should produce a test suite with a test case when reported', () => {
builder.testSuite().testCase();
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="0" skipped="0">\n' +
' <testsuite tests="1" failures="0" errors="0" skipped="0">\n' +
' <testcase/>\n' +
' </testsuite>\n' +
'</testsuites>',
),
);
});
it('should produce a test suite with a failed test case when reported', () => {
builder.testSuite().testCase().failure();
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="1" errors="0" skipped="0">\n' +
' <testsuite tests="1" failures="1" errors="0" skipped="0">\n' +
' <testcase>\n' +
' <failure/>\n' +
' </testcase>\n' +
' </testsuite>\n' +
'</testsuites>',
),
);
});
it('should produce a test suite with an errored test case when reported', () => {
builder.testSuite().testCase().error();
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="1" skipped="0">\n' +
' <testsuite tests="1" failures="0" errors="1" skipped="0">\n' +
' <testcase>\n' +
' <error/>\n' +
' </testcase>\n' +
' </testsuite>\n' +
'</testsuites>',
),
);
});
it('should produce a test suite with a skipped test case when reported', () => {
builder.testSuite().testCase().skipped();
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="0" skipped="1">\n' +
' <testsuite tests="1" failures="0" errors="0" skipped="1">\n' +
' <testcase>\n' +
' <skipped/>\n' +
' </testcase>\n' +
' </testsuite>\n' +
'</testsuites>',
),
);
});
it('should add the reported time to the test sute', () => {
builder.testSuite().time(2.5);
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="0" failures="0" errors="0" skipped="0">\n' +
' <testsuite time="2.5" tests="0" failures="0" errors="0" skipped="0"/>\n' +
'</testsuites>',
),
);
});
it('should add the reported timestamp to the test sute', () => {
builder.testSuite().timestamp(new Date(2015, 10, 22, 13, 37, 59, 123));
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="0" failures="0" errors="0" skipped="0">\n' +
' <testsuite timestamp="2015-11-22T13:37:59" tests="0" failures="0" errors="0" skipped="0"/>\n' +
'</testsuites>',
),
);
});
it('should add the reported time to the test case', () => {
builder.testSuite().testCase().time(2.5);
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="0" skipped="0">\n' +
' <testsuite tests="1" failures="0" errors="0" skipped="0">\n' +
' <testcase time="2.5"/>\n' +
' </testsuite>\n' +
'</testsuites>',
),
);
});
it('should print the reported standard output log to system-out', () => {
builder.testSuite().testCase().standardOutput('This was written to stdout!');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="0" skipped="0">\n' +
' <testsuite tests="1" failures="0" errors="0" skipped="0">\n' +
' <testcase>\n' +
' <system-out><![CDATA[This was written to stdout!]]></system-out>\n' +
' </testcase>\n' +
' </testsuite>\n' +
'</testsuites>',
),
);
});
it('should print the reported standard error log to system-err', () => {
builder.testSuite().testCase().standardError('This was written to stderr!');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="0" skipped="0">\n' +
' <testsuite tests="1" failures="0" errors="0" skipped="0">\n' +
' <testcase>\n' +
' <system-err><![CDATA[This was written to stderr!]]></system-err>\n' +
' </testcase>\n' +
' </testsuite>\n' +
'</testsuites>',
),
);
});
it('should print the reported attachment to system-err', () => {
builder
.testSuite()
.testCase()
.standardError('This was written to stderr!')
.errorAttachment('absolute/path/to/attachment');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="0" skipped="0">\n' +
' <testsuite tests="1" failures="0" errors="0" skipped="0">\n' +
' <testcase>\n' +
' <system-err>\n' +
' <![CDATA[This was written to stderr!]]>\n' +
' [[ATTACHMENT|absolute/path/to/attachment]]\n' +
' </system-err>\n' +
' </testcase>\n' +
' </testsuite>\n' +
'</testsuites>',
),
);
});
it('should output test suites and test cases in the order reported', () => {
builder.testCase().name('1');
builder.testSuite().name('2');
builder.testCase().name('3');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="2" failures="0" errors="0" skipped="0">\n' +
' <testcase name="1"/>\n' +
' <testsuite name="2" tests="0" failures="0" errors="0" skipped="0"/>\n' +
' <testcase name="3"/>\n' +
'</testsuites>',
),
);
});
it('should builder supports emojis in cdata tags', () => {
builder.testCase().standardOutput('Emoji: 🤦');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="0" skipped="0">\n' +
' <testcase>\n' +
' <system-out><![CDATA[Emoji: 🤦]]></system-out>\n' +
' </testcase>\n' +
'</testsuites>',
),
);
});
it('should escape quotes', () => {
builder.testCase().error('it is "quoted"');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="1" skipped="0">\n' +
' <testcase>\n' +
' <error message="it is "quoted""/>\n' +
' </testcase>\n' +
'</testsuites>',
),
);
});
it('should remove invalid characters', () => {
builder.testCase().error('Invalid\x00Characters\x08Stripped');
expect(builder.build()).toBe(
reportWith(
// prettier-ignore
'<testsuites tests="1" failures="0" errors="1" skipped="0">\n' +
' <testcase>\n' +
' <error message="InvalidCharactersStripped"/>\n' +
' </testcase>\n' +
'</testsuites>',
),
);
});
});