-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
96 lines (92 loc) · 3.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
/* global describe, it */
var PassThrough = require('stream').PassThrough;
var TimeReporter = require('./index');
var assert = require('chai').assert;
describe('test failure reporter', function () {
it('writes out fast results as dots, plus a summary', function () {
var stream = new PassThrough();
var reporter = new TimeReporter({ out: stream });
reporter.report('phantomjs', {
name: 'it does stuff',
passed: true,
runDuration: 300,
logs: []
});
reporter.report('phantomjs', {
name: 'it does more stuff',
passed: true,
runDuration: 300,
logs: ['I am a log', 'Useful information']
});
reporter.finish();
var output = stream.read().toString();
// one line for all success plus 6 for summary
assert.equal(output.split('\n').length, 7);
assert.match(output, /\.\./); // two dots for passes
});
it('writes out slow results as lines with run duration, plus a summary', function () {
var stream = new PassThrough();
var reporter = new TimeReporter({ out: stream });
reporter.report('phantomjs', {
name: 'it does stuff',
passed: true,
runDuration: 300,
logs: []
});
reporter.report('phantomjs', {
name: 'it takes a while',
passed: true,
runDuration: 3000,
logs: ['I am a log', 'Useful information']
});
reporter.report('phantomjs', {
name: 'it takes a while more',
passed: true,
runDuration: 5000,
logs: ['I am a log', 'Useful information']
});
reporter.finish();
var output = stream.read().toString();
// one line fast success, two for slow success, plus 6 for summary
assert.equal(output.split('\n').length, 9);
assert.match(output, /3000ms - it takes a while/); // log long test
assert.match(output, /Longest test - 5000ms - it takes a while more/); // Log as longest test
});
it('can sort out slow tests', function () {
var stream = new PassThrough();
var reporter = new TimeReporter({ out: stream, sort: true });
reporter.report('phantomjs', {
name: 'it does stuff',
passed: true,
runDuration: 300,
logs: []
});
reporter.report('phantomjs', {
name: 'it takes a while more',
passed: true,
runDuration: 5000,
logs: ['I am a log', 'Useful information']
});
reporter.report('phantomjs', {
name: 'it takes a long damn time',
passed: true,
runDuration: 9000,
logs: ['I am a log', 'Useful information']
});
reporter.report('phantomjs', {
name: 'it takes a while',
passed: true,
runDuration: 3000,
logs: ['I am a log', 'Useful information']
});
reporter.finish();
var output = stream.read().toString();
// one line fast success, three for slow success, plus 5 for summary (no longest line)
assert.equal(output.split('\n').length, 8);
const index1 = output.indexOf('3000ms - it takes a while');
const index2 = output.indexOf('5000ms - it takes a while more');
const index3 = output.indexOf('9000ms - it takes a long damn time');
assert.equal(-1 < index1 < index2 < index3, true); // eslint-disable-line
assert.equal(output.indexOf('Longest'), -1);
});
});