-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathterminal_spec.js
138 lines (107 loc) · 3.32 KB
/
terminal_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
require('../../spec_helper')
const snapshot = require('snap-shot-it')
const stripAnsi = require('strip-ansi')
const widestLine = require('widest-line')
const env = require(`${root}../lib/util/env`)
const terminal = require(`${root}../lib/util/terminal`)
const terminalSize = require(`${root}../lib/util/terminal-size`)
const sanitizeSnapshot = (str) => {
return snapshot(stripAnsi(str))
}
const render = function (...tables) {
const str = terminal.renderTables(...tables)
console.log(str)
return str
}
const expectLength = function (str, length) {
const lineLength = widestLine(str.split('\n')[0])
// first line should always be 100 chars
expect(lineLength).to.eq(length)
}
describe('lib/util/terminal', () => {
context('.getMaximumColumns', () => {
it('uses max 100 when exceeds terminalSize', () => {
sinon.stub(terminalSize, 'get').returns({ columns: 1000 })
expect(terminal.getMaximumColumns()).to.eq(100)
})
it('uses terminalSize when less than 100', () => {
sinon.stub(terminalSize, 'get').returns({ columns: 99 })
expect(terminal.getMaximumColumns()).to.eq(99)
})
it('overrides terminalSize when in CI', () => {
sinon.stub(env, 'get').withArgs('CI').returns('1')
expect(terminal.getMaximumColumns()).to.eq(100)
})
})
context('.table', () => {
beforeEach(() => {
return sinon.stub(terminalSize, 'get').returns({ columns: 100 })
})
it('draws multiple specs summary table', () => {
const colAligns = ['left', 'right', 'right', 'right', 'right', 'right', 'right']
const colWidths = [39, 11, 10, 10, 10, 10, 10]
const table1 = terminal.table({
colAligns,
colWidths,
type: 'noBorder',
head: ['Spec', '', 'Tests', 'Passing', 'Failing', 'Pending', 'Skipped'],
})
const table2 = terminal.table({
colAligns,
colWidths,
type: 'border',
})
const table3 = terminal.table({
colAligns,
colWidths,
type: 'noBorder',
head: ['2 of 3 passed (66%)', '1:05:36', 37, 29, 8, 102, 18],
})
table2.push(
['foo.js', '00:49', 7, 4, 3, 2, 1],
['bar.js', '796ms', 0, 0, 0, 0, 15],
['fail/is/whale.js', '03:28', 30, 25, 5, 100, 3],
)
const str = render(table1, table2, table3)
expectLength(str, 100)
return sanitizeSnapshot(str)
})
it('draws single spec summary table', () => {
const table = terminal.table({
type: 'outsideBorder',
})
table.push(
['Tests:', 1],
['Passing:', 2],
['Failing:', 3],
['Pending:', 4],
['Skipped:', 5],
['Duration:', 6],
['Screenshots:', 7],
['Video:', true],
['Spec:', 'foo/bar/baz.js'],
)
const str = render(table)
return sanitizeSnapshot(str)
})
it('draws a page divider', () => {
const table = terminal.table({
colWidths: [80, 20],
colAligns: ['left', 'right'],
type: 'pageDivider',
style: {
'padding-left': 2,
'padding-right': 1,
},
})
table.push(['', ''])
table.push([
'Running: foo/bar/baz.js...',
'(100 of 200)',
])
const str = render(table)
expectLength(str, 100)
return sanitizeSnapshot(str)
})
})
})