-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathtest-suite-result.cjs
186 lines (177 loc) · 5.36 KB
/
test-suite-result.cjs
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
const path = require('path')
const fs = require('fs')
const prettier = require('prettier')
const TestEnv = require('../../modules/e2e-test/test-env.cjs')
class TestSuiteResult {
#cnsl
#testSuiteResults
#testCases
#testCasesConfig
#createHashes
constructor(testSuiteResults, testCases, testCasesConfig, createHashes, cnsl) {
this.#cnsl = cnsl
this.#testSuiteResults = testSuiteResults
this.#testCases = testCases
this.#testCasesConfig = testCasesConfig
this.#createHashes = createHashes
}
createTestSuiteResult() {
this.#createNewConfig()
if (this.#testSuiteResults.MANUAL.length !== 0) {
this.#cnsl.log('\n')
this.#testSuiteResults.MANUAL.forEach((testCase) => {
this.#cnsl.log(
''.padEnd(this.#cnsl.getTestStatusPad() + 5, ' ') +
path.relative(
TestEnv.getTestSuitePath(),
path.join(TestEnv.getWorkspacePath(), testCase.testName)
)
)
this.#cnsl.log(
''.padEnd(this.#cnsl.getTestStatusPad() + 5, ' ') +
'http://127.0.0.1:8080/test/e2e/tools/manual/client?testFile=' +
testCase.testFile +
'&testType=' +
testCase.testType +
'&testIndex=' +
testCase.testIndex +
'&vizzuUrl=localhost\n'
)
})
this.#cnsl.log('\n')
this.#cnsl.log(
''.padEnd(this.#cnsl.getTestStatusPad() + 5, ' ') +
'npm run test:man --' +
' ' +
this.#testSuiteResults.MANUAL_FORMATTED.map((s) => `'${s}'`).join(' ')
)
}
this.#testSuiteResults.TIME.END = Math.round(Date.now() / 1000)
const duration = this.#testSuiteResults.TIME.END - this.#testSuiteResults.TIME.START
this.#cnsl.log('\n' + 'duration:'.padEnd(15, ' ') + duration + 's')
this.#cnsl.log('\n' + 'all tests:'.padEnd(15, ' ') + this.#testCases.testCases.length)
const sum =
this.#testSuiteResults.PASSED.length +
this.#testSuiteResults.WARNING.length +
this.#testSuiteResults.FAILED.length
this.#cnsl.log('tests run:'.padEnd(15, ' ') + sum)
this.#cnsl.log(
('tests passed:'.padEnd(15, ' ') + this.#testSuiteResults.PASSED.length).success
)
if (this.#testSuiteResults.WARNING.length !== 0) {
this.#cnsl.log(
('tests warning:'.padEnd(15, ' ') + this.#testSuiteResults.WARNING.length).warn
)
} else {
this.#cnsl.log('tests warning:'.padEnd(15, ' ') + this.#testSuiteResults.WARNING.length)
}
if (this.#testSuiteResults.FAILED.length !== 0) {
this.#cnsl.log(
('tests failed:'.padEnd(15, ' ') + this.#testSuiteResults.FAILED.length).error
)
process.exitCode = 1
} else {
this.#cnsl.log('tests failed:'.padEnd(15, ' ') + this.#testSuiteResults.FAILED.length)
}
}
#createNewConfig() {
if (this.#createHashes !== 'DISABLED') {
if (
this.#createHashes === 'ALL' ||
(this.#createHashes === 'FAILED' && this.#testSuiteResults.FAILED.length !== 0) ||
(this.#createHashes === 'FAILURES' &&
(this.#testSuiteResults.FAILED.length !== 0 ||
this.#testSuiteResults.WARNING.length !== 0))
) {
const testCasesConfig = {}
this.#testCasesConfig.suites.forEach((suite) => {
const suitePath = '/' + path.relative(TestEnv.getWorkspacePath(), suite.suite)
testCasesConfig[suitePath] = {
suite: suitePath,
tmp: suite.config,
test: {}
}
})
for (const [key] of Object.entries(this.#testSuiteResults.RESULTS)) {
if (
this.#createHashes === 'FAILURES' &&
!this.#testSuiteResults.FAILED.includes(key) &&
!this.#testSuiteResults.WARNING.includes(key)
) {
continue
}
if (
this.#createHashes === 'FAILED' &&
!this.#testSuiteResults.FAILED.includes(key)
) {
continue
}
Object.keys(testCasesConfig).forEach((suite) => {
if (key.startsWith(suite)) {
if (this.#testSuiteResults.RESULTS[key].hash) {
testCasesConfig[suite].test[path.relative(suite, key)] = {
refs: [this.#testSuiteResults.RESULTS[key].hash]
}
}
}
})
}
for (const [key, value] of Object.entries(testCasesConfig)) {
if (Object.keys(testCasesConfig[key].test).length === 0) {
continue
}
const conFigPath = path.join(
TestEnv.getTestSuiteResultsPath(),
path.relative(
TestEnv.getTestSuitePath(),
path.join(TestEnv.getWorkspacePath(), key)
),
path.basename(value.tmp)
)
const rmReady = new Promise((resolve, reject) => {
fs.rm(conFigPath, { force: true }, (err) => {
if (err) {
return reject(err)
}
return resolve()
})
})
const mkdirReady = new Promise((resolve, reject) => {
fs.mkdir(path.dirname(conFigPath), { recursive: true }, (err) => {
if (err) {
return reject(err)
}
return resolve()
})
})
Promise.all([rmReady, mkdirReady]).then(() => {
const configData = value
delete configData.tmp
configData.test = Object.keys(configData.test)
.sort()
.reduce((a, c) => {
a[c] = configData.test[c]
return a
}, {})
const formattedConfigDataReady = prettier.format(
JSON.stringify(configData, null, '\t'),
{
parser: 'json',
tabWidth: 4,
useTabs: true
}
)
formattedConfigDataReady.then((formattedConfigData) => {
fs.writeFile(conFigPath, formattedConfigData, (err) => {
if (err) {
throw err
}
})
})
})
}
}
}
}
}
module.exports = TestSuiteResult