-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-test-integ.js
111 lines (86 loc) · 2.46 KB
/
check-test-integ.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
const path = require('path')
const fs = require('fs')
const logDir = path.join(__dirname, 'logs')
const logPath = path.join(logDir, 'test-integ.log')
const { createSubTerminal } = require('./subterminal')
try {
fs.accessSync(logDir, fs.constants.F_OK)
} catch (err) {
fs.mkdirSync(logDir)
}
const stream = fs.createReadStream(logPath)
let data = ''
stream.on('readable', () => {
let chunk
while ((chunk = stream.read()) !== null) {
data += chunk
}
})
stream.on('end', () => {
const entries = data.split('\n').filter(l => l).map((l, ix) => {
console.info({ lineNumber: ix + 1, parsing: l })
return JSON.parse(l)
})
check(entries)
stream.close()
})
function check (entries) {
function drawCallback () {
// do nothing
}
// Receive data from process
function onProcData (data) {
// do nothing
}
const subTermIds = Array.from(new Set(entries.map(e => e.subTermId)))
// This does actually start a bash process, which is not needed
// TODO: just make a new SubTerminal - no side-effects testing
const subTerms = {}
subTermIds.map(id => {
const [subTerm] = createSubTerminal(drawCallback, { id, onProcData })
subTerm.resize(50, 50)
subTerms[id] = subTerm
})
function identical (a, b) {
return JSON.stringify(a) === JSON.stringify(b)
}
let errorCount = 0
function runEntry (e) {
const { subTermId } = e
const subTerm = subTerms[subTermId]
if (e.procOutput !== undefined) {
subTerm.write(e.procOutput)
}
if (e.userInput !== undefined) {
// User input is ignored - there is no process to send it to
}
if (e.subTerminal !== undefined) {
// Check that recorded state matches current subTerm state
const expected = e.subTerminal
const actual = {
lines: subTerm.drawSubTerminal(50, 50, {
isFocussed: true,
highlight: false
}),
size: subTerm.size,
cursor: subTerm.cursor
}
const props = ['size', 'cursor', 'lines']
function basicCheck (propName) {
// check size
if (!identical(expected[propName], actual[propName])) {
console.error('mismatch: ' + propName)
console.error({
expected: expected[propName],
actual: actual[propName]
})
errorCount++
}
}
props.map(basicCheck)
}
}
entries.map(runEntry)
console.info({ processedEntries: entries.length, errorCount })
process.exit(errorCount)
}