ui5-test-runner 5.13.0 → 6.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/Npm.js +80 -0
- package/dist/browsers/IBrowser.js +1 -0
- package/dist/browsers/factory.js +9 -0
- package/dist/browsers/puppeteer.js +158 -0
- package/dist/cli.js +17 -0
- package/dist/configuration/CommandLine.js +112 -0
- package/dist/configuration/Configuration.js +1 -0
- package/dist/configuration/ConfigurationValidator.js +79 -0
- package/dist/configuration/Option.js +1 -0
- package/dist/configuration/OptionValidationError.js +15 -0
- package/dist/configuration/indexedOptions.js +13 -0
- package/dist/configuration/options.js +191 -0
- package/dist/configuration/validators/OptionValidator.js +1 -0
- package/dist/configuration/validators/boolean.js +15 -0
- package/dist/configuration/validators/browser.js +11 -0
- package/dist/configuration/validators/fsEntry.js +70 -0
- package/dist/configuration/validators/index.js +20 -0
- package/dist/configuration/validators/integer.js +10 -0
- package/dist/configuration/validators/percent.js +17 -0
- package/dist/configuration/validators/regexp.js +20 -0
- package/dist/configuration/validators/string.js +7 -0
- package/dist/configuration/validators/timeout.js +24 -0
- package/dist/configuration/validators/url.js +8 -0
- package/dist/modes/ModeFunction.js +1 -0
- package/dist/modes/Modes.js +9 -0
- package/dist/modes/execute.js +27 -0
- package/dist/modes/help.js +3 -0
- package/dist/modes/log/ILogStorage.js +1 -0
- package/dist/modes/log/LogMetrics.js +9 -0
- package/dist/modes/log/LogReader.js +37 -0
- package/dist/modes/log/LogStorage.js +68 -0
- package/dist/modes/log/REserve.js +101 -0
- package/dist/modes/log/index.js +58 -0
- package/dist/modes/test/REserve.js +31 -0
- package/dist/modes/test/agent.js +8 -0
- package/dist/modes/test/browser.js +37 -0
- package/dist/modes/test/index.js +66 -0
- package/dist/modes/test/pageTask.js +145 -0
- package/dist/modes/test/report.js +3 -0
- package/dist/modes/test/server.js +109 -0
- package/dist/modes/version.js +11 -0
- package/dist/platform/Exit.js +139 -0
- package/dist/platform/FileSystem.js +13 -0
- package/dist/platform/Host.js +10 -0
- package/dist/platform/Http.js +38 -0
- package/dist/platform/Path.js +5 -0
- package/dist/platform/Process.js +133 -0
- package/dist/platform/Terminal.js +47 -0
- package/dist/platform/Thread.js +43 -0
- package/dist/platform/ZLib.js +7 -0
- package/dist/platform/assert.js +17 -0
- package/dist/platform/constants.js +5 -0
- package/dist/platform/environment.js +28 -0
- package/dist/platform/index.js +13 -0
- package/dist/platform/logger/ILogger.js +1 -0
- package/dist/platform/logger/allCompressed.js +54 -0
- package/dist/platform/logger/compress.js +277 -0
- package/dist/platform/logger/output/BaseLoggerOutput.js +158 -0
- package/dist/platform/logger/output/InteractiveLoggerOutput.js +102 -0
- package/dist/platform/logger/output/StaticLoggerOutput.js +32 -0
- package/dist/platform/logger/output/factory.js +10 -0
- package/dist/platform/logger/output.js +58 -0
- package/dist/platform/logger/proxy.js +6 -0
- package/dist/platform/logger/toInternalLogAttributes.js +22 -0
- package/dist/platform/logger/types.js +7 -0
- package/dist/platform/logger.js +138 -0
- package/dist/platform/mock.js +104 -0
- package/dist/platform/version.js +8 -0
- package/dist/platform/workerBootstrap.js +21 -0
- package/dist/reports/html.js +46 -0
- package/dist/types/AgentState.js +1 -0
- package/dist/types/CommonTestReportFormat.js +50 -0
- package/dist/types/IError.js +1 -0
- package/dist/types/IUserInterfaceController.js +1 -0
- package/dist/types/typeUtilities.js +1 -0
- package/dist/ui/agent.js +3 -0
- package/dist/ui/html-report.js +2 -0
- package/dist/ui/lib.js +1 -0
- package/dist/ui/log-viewer.js +2 -0
- package/dist/utils/node/Folder.js +28 -0
- package/dist/utils/node/FramedStreamReader.js +86 -0
- package/dist/utils/node/FramedStreamWriter.js +27 -0
- package/dist/utils/shared/ProgressBar.js +43 -0
- package/dist/utils/shared/TestReportBuilder.js +48 -0
- package/dist/utils/shared/memoize.js +19 -0
- package/dist/utils/shared/object.js +8 -0
- package/dist/utils/shared/parallelize.js +59 -0
- package/dist/utils/shared/string.js +23 -0
- package/dist/utils/shared/toIError.js +17 -0
- package/package.json +73 -50
- package/.releaserc +0 -5
- package/index.js +0 -175
- package/jest.config.json +0 -31
- package/src/add-test-pages.js +0 -67
- package/src/batch.js +0 -214
- package/src/browsers.js +0 -319
- package/src/capabilities/index.js +0 -204
- package/src/capabilities/tests/basic/iframe.html +0 -8
- package/src/capabilities/tests/basic/index.html +0 -12
- package/src/capabilities/tests/basic/index.js +0 -20
- package/src/capabilities/tests/basic/ui5.html +0 -24
- package/src/capabilities/tests/dynamic-include/index.js +0 -21
- package/src/capabilities/tests/dynamic-include/mix.html +0 -11
- package/src/capabilities/tests/dynamic-include/one.html +0 -11
- package/src/capabilities/tests/dynamic-include/post.js +0 -3
- package/src/capabilities/tests/dynamic-include/test.js +0 -1
- package/src/capabilities/tests/dynamic-include/two.html +0 -11
- package/src/capabilities/tests/index.js +0 -16
- package/src/capabilities/tests/local-storage/index.html +0 -16
- package/src/capabilities/tests/local-storage/index.js +0 -21
- package/src/capabilities/tests/screenshot/index.html +0 -23
- package/src/capabilities/tests/screenshot/index.js +0 -24
- package/src/capabilities/tests/scripts/coverage.html +0 -32
- package/src/capabilities/tests/scripts/iframe.html +0 -18
- package/src/capabilities/tests/scripts/index.js +0 -59
- package/src/capabilities/tests/scripts/qunit.html +0 -22
- package/src/capabilities/tests/scripts/testsuite.html +0 -10
- package/src/capabilities/tests/scripts/testsuite.js +0 -8
- package/src/capabilities/tests/timeout/index.html +0 -21
- package/src/capabilities/tests/timeout/index.js +0 -19
- package/src/capabilities/tests/traces/index.html +0 -18
- package/src/capabilities/tests/traces/index.js +0 -81
- package/src/capabilities/tests/ui5/focus.html +0 -89
- package/src/capabilities/tests/ui5/index.js +0 -39
- package/src/capabilities/tests/ui5/language.html +0 -50
- package/src/capabilities/tests/ui5/timezone.html +0 -27
- package/src/clean.js +0 -22
- package/src/cors.js +0 -21
- package/src/coverage.js +0 -384
- package/src/csv-reader.js +0 -36
- package/src/csv-writer.js +0 -55
- package/src/defaults/.nycrc.json +0 -4
- package/src/defaults/browser.js +0 -217
- package/src/defaults/happy-dom.js +0 -123
- package/src/defaults/jsdom/compatibility.js +0 -163
- package/src/defaults/jsdom/debug.js +0 -23
- package/src/defaults/jsdom/resource-loader.js +0 -44
- package/src/defaults/jsdom/sap.ui.test.matchers.visible.js +0 -39
- package/src/defaults/jsdom.js +0 -95
- package/src/defaults/json-report.js +0 -36
- package/src/defaults/junit-xml-report.js +0 -90
- package/src/defaults/playwright.js +0 -142
- package/src/defaults/puppeteer.js +0 -124
- package/src/defaults/report/common.js +0 -38
- package/src/defaults/report/decompress.js +0 -19
- package/src/defaults/report/default.html +0 -99
- package/src/defaults/report/main.js +0 -69
- package/src/defaults/report/progress.js +0 -60
- package/src/defaults/report/styles.css +0 -66
- package/src/defaults/report.js +0 -91
- package/src/defaults/scan-ui5.js +0 -26
- package/src/defaults/selenium-webdriver/chrome.js +0 -39
- package/src/defaults/selenium-webdriver/edge.js +0 -24
- package/src/defaults/selenium-webdriver/firefox.js +0 -30
- package/src/defaults/selenium-webdriver.js +0 -129
- package/src/defaults/text-report.js +0 -108
- package/src/defaults/webdriverio.js +0 -80
- package/src/end.js +0 -62
- package/src/endpoints.js +0 -219
- package/src/error.js +0 -54
- package/src/get-job-progress.js +0 -78
- package/src/handle.js +0 -43
- package/src/if.js +0 -10
- package/src/inject/jest2qunit.js +0 -289
- package/src/inject/opa-iframe-coverage.js +0 -22
- package/src/inject/post.js +0 -141
- package/src/inject/qunit-hooks.js +0 -107
- package/src/inject/qunit-redirect.js +0 -65
- package/src/inject/ui5-coverage.js +0 -33
- package/src/job-mode.js +0 -65
- package/src/job.js +0 -493
- package/src/npm.js +0 -136
- package/src/options.js +0 -95
- package/src/output.js +0 -739
- package/src/parallelize.js +0 -63
- package/src/qunit-hooks.js +0 -219
- package/src/report.js +0 -89
- package/src/reserve.js +0 -25
- package/src/start.js +0 -129
- package/src/symbols.js +0 -8
- package/src/tests.js +0 -183
- package/src/timeout.js +0 -53
- package/src/tools.js +0 -179
- package/src/ui5.js +0 -199
- package/src/unhandled.js +0 -32
package/index.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
'use strict'
|
|
4
|
-
|
|
5
|
-
const { serve } = require('reserve')
|
|
6
|
-
const { watch } = require('fs')
|
|
7
|
-
const { capabilities } = require('./src/capabilities')
|
|
8
|
-
const { execute } = require('./src/tests')
|
|
9
|
-
const { fromCmdLine } = require('./src/job')
|
|
10
|
-
const { getOutput } = require('./src/output')
|
|
11
|
-
const { preload } = require('./src/ui5')
|
|
12
|
-
const { probe: probeBrowser } = require('./src/browsers')
|
|
13
|
-
const { recreateDir, allocPromise } = require('./src/tools')
|
|
14
|
-
const reserveConfigurationFactory = require('./src/reserve')
|
|
15
|
-
const { start } = require('./src/start')
|
|
16
|
-
const { executeIf } = require('./src/if')
|
|
17
|
-
const { batch } = require('./src/batch')
|
|
18
|
-
const { end } = require('./src/end')
|
|
19
|
-
const { checkLatest } = require('./src/npm')
|
|
20
|
-
const { cleanHandles } = require('./src/clean')
|
|
21
|
-
|
|
22
|
-
function send (message) {
|
|
23
|
-
if (process.send) {
|
|
24
|
-
process.send({
|
|
25
|
-
pid: process.pid,
|
|
26
|
-
...message
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function notifyAndExecuteTests (job) {
|
|
32
|
-
send({ msg: 'begin' })
|
|
33
|
-
try {
|
|
34
|
-
await execute(job)
|
|
35
|
-
let status
|
|
36
|
-
if (job.failed) {
|
|
37
|
-
status = -1
|
|
38
|
-
} else {
|
|
39
|
-
status = 0
|
|
40
|
-
}
|
|
41
|
-
send({ msg: 'end', status })
|
|
42
|
-
} catch (error) {
|
|
43
|
-
getOutput(job).genericError(error)
|
|
44
|
-
send({ msg: 'error', error })
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let job
|
|
49
|
-
let output
|
|
50
|
-
|
|
51
|
-
async function main () {
|
|
52
|
-
job = fromCmdLine(process.cwd(), process.argv.slice(2))
|
|
53
|
-
output = getOutput(job)
|
|
54
|
-
await recreateDir(job.reportDir)
|
|
55
|
-
const { name, version } = output.version()
|
|
56
|
-
if (job.batchMode) {
|
|
57
|
-
output.batchMode()
|
|
58
|
-
}
|
|
59
|
-
output.reportOnJobProgress()
|
|
60
|
-
checkLatest(job, name, version)
|
|
61
|
-
if (job.if && !executeIf(job)) {
|
|
62
|
-
output.skipIf()
|
|
63
|
-
output.stop()
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
if (job.mode === 'capabilities') {
|
|
67
|
-
return capabilities(job)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
let startedCommand
|
|
71
|
-
if (job.startCommand) {
|
|
72
|
-
startedCommand = await start(job)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (job.mode === 'batch') {
|
|
76
|
-
return await batch(job)
|
|
77
|
-
.finally(async () => {
|
|
78
|
-
if (startedCommand) {
|
|
79
|
-
await startedCommand.stop()
|
|
80
|
-
}
|
|
81
|
-
cleanHandles(job)
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const configuration = await reserveConfigurationFactory(job)
|
|
86
|
-
output.debug('reserve', 'configuration', configuration)
|
|
87
|
-
const server = serve(configuration)
|
|
88
|
-
if (job.logServer) {
|
|
89
|
-
server
|
|
90
|
-
.on('incoming', output.logServerIncoming)
|
|
91
|
-
.on('redirected', output.logServerRedirected)
|
|
92
|
-
.on('closed', output.logServerClosed)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const { promise: serverStarted, resolve: serverReady, reject: serverError } = allocPromise()
|
|
96
|
-
server
|
|
97
|
-
.on('ready', async ({ url, port }) => {
|
|
98
|
-
job.port = port
|
|
99
|
-
send({ msg: 'ready', port: job.port })
|
|
100
|
-
output.serving(url)
|
|
101
|
-
serverReady()
|
|
102
|
-
})
|
|
103
|
-
.on('error', ({ reason }) => {
|
|
104
|
-
send({ msg: 'error', reason })
|
|
105
|
-
serverError(reason)
|
|
106
|
-
})
|
|
107
|
-
await serverStarted
|
|
108
|
-
if (job.preload) {
|
|
109
|
-
await preload(job)
|
|
110
|
-
}
|
|
111
|
-
if (job.serveOnly) {
|
|
112
|
-
job.status = 'Serving'
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
await probeBrowser(job)
|
|
116
|
-
await notifyAndExecuteTests(job)
|
|
117
|
-
if (job.watch) {
|
|
118
|
-
if (!job.watching) {
|
|
119
|
-
job.status = 'Watching...'
|
|
120
|
-
let running = false
|
|
121
|
-
let rerun = false
|
|
122
|
-
const run = async () => {
|
|
123
|
-
running = true
|
|
124
|
-
do {
|
|
125
|
-
rerun = false
|
|
126
|
-
await recreateDir(job.reportDir)
|
|
127
|
-
await notifyAndExecuteTests(job)
|
|
128
|
-
} while (rerun)
|
|
129
|
-
running = false
|
|
130
|
-
job.status = 'Watching...'
|
|
131
|
-
}
|
|
132
|
-
output.watching(job.watchFolder)
|
|
133
|
-
watch(job.watchFolder, { recursive: true }, async (eventType, filename) => {
|
|
134
|
-
output.changeDetected(eventType, filename)
|
|
135
|
-
if (running) {
|
|
136
|
-
rerun = true
|
|
137
|
-
} else {
|
|
138
|
-
run()
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
job.watching = true
|
|
142
|
-
}
|
|
143
|
-
return
|
|
144
|
-
} else if (job.keepAlive) {
|
|
145
|
-
job.status = 'Serving'
|
|
146
|
-
return
|
|
147
|
-
} else if (job.failed) {
|
|
148
|
-
process.exitCode = -1
|
|
149
|
-
}
|
|
150
|
-
if (job.endScript) {
|
|
151
|
-
await end(job)
|
|
152
|
-
}
|
|
153
|
-
output.stop()
|
|
154
|
-
await server.close({ close: true })
|
|
155
|
-
await new Promise(resolve => setTimeout(resolve, 100)) // wait for server handles to be released
|
|
156
|
-
if (job.logServer) {
|
|
157
|
-
output.logServerSummary()
|
|
158
|
-
}
|
|
159
|
-
if (startedCommand) {
|
|
160
|
-
await startedCommand.stop()
|
|
161
|
-
}
|
|
162
|
-
output.debug('main', 'terminated')
|
|
163
|
-
cleanHandles(job)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
main()
|
|
167
|
-
.catch(reason => {
|
|
168
|
-
if (output) {
|
|
169
|
-
output.genericError(reason)
|
|
170
|
-
output.stop()
|
|
171
|
-
} else if (reason.name !== 'CommanderError') {
|
|
172
|
-
console.error(reason)
|
|
173
|
-
}
|
|
174
|
-
process.exit(-1)
|
|
175
|
-
})
|
package/jest.config.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testTimeout": 15000,
|
|
3
|
-
"setupFilesAfterEnv": [
|
|
4
|
-
"./test/setup.js"
|
|
5
|
-
],
|
|
6
|
-
"testPathIgnorePatterns": [
|
|
7
|
-
"/node_modules/",
|
|
8
|
-
"/capabilities/",
|
|
9
|
-
"/e2e/"
|
|
10
|
-
],
|
|
11
|
-
"collectCoverage": true,
|
|
12
|
-
"collectCoverageFrom": [
|
|
13
|
-
"src/*.js",
|
|
14
|
-
"src/defaults/junit-xml-report.js"
|
|
15
|
-
],
|
|
16
|
-
"coveragePathIgnorePatterns": [
|
|
17
|
-
"\\.spec\\.js",
|
|
18
|
-
"output\\.js",
|
|
19
|
-
"handle\\.js",
|
|
20
|
-
"coverage\\.js",
|
|
21
|
-
"b\\capabilities\\b"
|
|
22
|
-
],
|
|
23
|
-
"coverageThreshold": {
|
|
24
|
-
"global": {
|
|
25
|
-
"branches": 80,
|
|
26
|
-
"functions": 80,
|
|
27
|
-
"lines": 80,
|
|
28
|
-
"statements": 80
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/add-test-pages.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { stop } = require('./browsers')
|
|
4
|
-
const { URL } = require('url')
|
|
5
|
-
const { getOutput } = require('./output')
|
|
6
|
-
const { stripUrlHash } = require('./tools')
|
|
7
|
-
|
|
8
|
-
const addUrlParam = (url, param) => {
|
|
9
|
-
if (url.includes(param)) {
|
|
10
|
-
return url
|
|
11
|
-
}
|
|
12
|
-
if (url.includes('?')) {
|
|
13
|
-
return url + '&' + param
|
|
14
|
-
}
|
|
15
|
-
return url + '?' + param
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = {
|
|
19
|
-
async addTestPages (job, url, data) {
|
|
20
|
-
const { type, opa, module, pages, page } = data
|
|
21
|
-
getOutput(job).debug('probe', `addTestPages from ${url}`, data)
|
|
22
|
-
let testPageUrls
|
|
23
|
-
if (type === 'none') {
|
|
24
|
-
testPageUrls = []
|
|
25
|
-
} else {
|
|
26
|
-
let receivedPages
|
|
27
|
-
if (type === 'qunit') {
|
|
28
|
-
receivedPages = [page]
|
|
29
|
-
if (job.splitOpa && opa && module) {
|
|
30
|
-
if (module.ids && module.ids.length > 1) {
|
|
31
|
-
receivedPages = module.ids.map(id => addUrlParam(stripUrlHash(page), `moduleId=${id}`))
|
|
32
|
-
} else if (module.names && module.names.length > 1) {
|
|
33
|
-
receivedPages = module.names.map(name => addUrlParam(stripUrlHash(page), `module=${name}`))
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
receivedPages = pages
|
|
38
|
-
}
|
|
39
|
-
receivedPages = receivedPages.map(relativeUrl => {
|
|
40
|
-
const absoluteUrl = new URL(relativeUrl, url)
|
|
41
|
-
return stripUrlHash(absoluteUrl.toString())
|
|
42
|
-
})
|
|
43
|
-
if (job.pageFilter) {
|
|
44
|
-
const filter = new RegExp(job.pageFilter)
|
|
45
|
-
testPageUrls = receivedPages.filter(name => name.match(filter))
|
|
46
|
-
} else {
|
|
47
|
-
testPageUrls = receivedPages
|
|
48
|
-
}
|
|
49
|
-
if (job.pageParams) {
|
|
50
|
-
testPageUrls = testPageUrls.map(url => addUrlParam(url, job.pageParams))
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
let member
|
|
54
|
-
if (type === 'suite' && job.splitOpa) {
|
|
55
|
-
member = 'url'
|
|
56
|
-
} else {
|
|
57
|
-
member = 'testPageUrls'
|
|
58
|
-
}
|
|
59
|
-
job[member] = testPageUrls.reduce((uniques, url) => {
|
|
60
|
-
if (!uniques.includes(url)) {
|
|
61
|
-
uniques.push(url)
|
|
62
|
-
}
|
|
63
|
-
return uniques
|
|
64
|
-
}, job[member] || [])
|
|
65
|
-
stop(job, url)
|
|
66
|
-
}
|
|
67
|
-
}
|
package/src/batch.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
const { open, readdir, stat, unlink } = require('fs/promises')
|
|
2
|
-
const { extname, isAbsolute, join } = require('path')
|
|
3
|
-
const { allocPromise, filename } = require('./tools')
|
|
4
|
-
const { fork } = require('child_process')
|
|
5
|
-
const { getOutput, newProgress } = require('./output')
|
|
6
|
-
const { parallelize } = require('./parallelize')
|
|
7
|
-
const { $statusProgressCount } = require('./symbols')
|
|
8
|
-
const { $valueSources } = require('./symbols')
|
|
9
|
-
const { getCommand, toLongName } = require('./job')
|
|
10
|
-
const { save } = require('./report')
|
|
11
|
-
const { end } = require('./end')
|
|
12
|
-
|
|
13
|
-
const batchParameters = getCommand('.').options
|
|
14
|
-
.filter(option => option.description.includes('📡'))
|
|
15
|
-
.reduce((dictionary, option) => {
|
|
16
|
-
dictionary[option.long.substring(2)] = option
|
|
17
|
-
return dictionary
|
|
18
|
-
}, {})
|
|
19
|
-
|
|
20
|
-
const root = join(__dirname, '..')
|
|
21
|
-
|
|
22
|
-
const folder = (job, folderPath) => {
|
|
23
|
-
getOutput(job).debug('batch', `adding folder: ${folderPath}`)
|
|
24
|
-
job.batchItems.push({
|
|
25
|
-
path: folderPath,
|
|
26
|
-
id: filename(folderPath),
|
|
27
|
-
label: folderPath,
|
|
28
|
-
args: ['--cwd', folderPath]
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const configurationFile = (job, configurationFilePath) => {
|
|
33
|
-
getOutput(job).debug('batch', `adding configuration file: ${configurationFilePath}`)
|
|
34
|
-
try {
|
|
35
|
-
const {
|
|
36
|
-
batchId: id = filename(configurationFilePath),
|
|
37
|
-
batchLabel: label = configurationFilePath
|
|
38
|
-
} = require(configurationFilePath)
|
|
39
|
-
job.batchItems.push({
|
|
40
|
-
path: configurationFilePath,
|
|
41
|
-
id,
|
|
42
|
-
label,
|
|
43
|
-
args: ['--config', configurationFilePath]
|
|
44
|
-
})
|
|
45
|
-
} catch (e) {
|
|
46
|
-
getOutput(job).batchFailed(configurationFilePath, 'invalid JSON configuration file')
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const task = async function (batchItem) {
|
|
51
|
-
const { id, label, args } = batchItem
|
|
52
|
-
batchItem.start = new Date()
|
|
53
|
-
const job = this
|
|
54
|
-
const output = getOutput(job)
|
|
55
|
-
const progress = newProgress(job)
|
|
56
|
-
const reportDir = join(job.reportDir, id)
|
|
57
|
-
progress.label = `${label} (${id})`
|
|
58
|
-
progress.count = 1
|
|
59
|
-
output.batchStartingTask(label)
|
|
60
|
-
const { promise, resolve, reject } = allocPromise()
|
|
61
|
-
const parameters = [
|
|
62
|
-
...args,
|
|
63
|
-
'--batch-mode'
|
|
64
|
-
]
|
|
65
|
-
if (job[$valueSources]) {
|
|
66
|
-
if (job[$valueSources].reportDir === 'cli') {
|
|
67
|
-
parameters.push('--report-dir', reportDir)
|
|
68
|
-
}
|
|
69
|
-
Object.keys(job[$valueSources])
|
|
70
|
-
.filter(name => job[$valueSources][name] === 'cli')
|
|
71
|
-
.forEach(name => {
|
|
72
|
-
const longName = toLongName(name)
|
|
73
|
-
const option = batchParameters[longName] || batchParameters['no-' + longName]
|
|
74
|
-
if (option) {
|
|
75
|
-
parameters.push(option.long)
|
|
76
|
-
if (!option.negate) {
|
|
77
|
-
if (name === 'env') {
|
|
78
|
-
Object.keys(job.env).forEach(key => {
|
|
79
|
-
parameters.push(`${key}=${job.env[key]}`)
|
|
80
|
-
})
|
|
81
|
-
} else if (option.variadic) {
|
|
82
|
-
parameters.push(...job[name].map(value => value.toString()))
|
|
83
|
-
} else {
|
|
84
|
-
parameters.push(job[name].toString())
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const stdoutFilename = join(job.reportDir, `${id}.stdout.txt`)
|
|
92
|
-
const stdout = await open(stdoutFilename, 'w')
|
|
93
|
-
const stderrFilename = join(job.reportDir, `${id}.stderr.txt`)
|
|
94
|
-
const stderr = await open(stderrFilename, 'w')
|
|
95
|
-
const childProcess = fork(
|
|
96
|
-
join(root, 'index.js'),
|
|
97
|
-
parameters,
|
|
98
|
-
{
|
|
99
|
-
stdio: [0, stdout, stderr, 'ipc']
|
|
100
|
-
}
|
|
101
|
-
)
|
|
102
|
-
childProcess.on('message', data => {
|
|
103
|
-
if (data.type === 'progress') {
|
|
104
|
-
const { count, total } = data
|
|
105
|
-
progress.count = count
|
|
106
|
-
progress.total = total
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
childProcess.on('close', async code => {
|
|
110
|
-
await stdout.close()
|
|
111
|
-
await stderr.close()
|
|
112
|
-
batchItem.statusCode = code
|
|
113
|
-
batchItem.end = new Date()
|
|
114
|
-
if (code !== 0) {
|
|
115
|
-
reject(code)
|
|
116
|
-
} else {
|
|
117
|
-
await unlink(stdoutFilename)
|
|
118
|
-
await unlink(stderrFilename)
|
|
119
|
-
resolve()
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
return promise
|
|
123
|
-
.then(() => {
|
|
124
|
-
output.log('✔️ ', progress.label)
|
|
125
|
-
}, (reason) => {
|
|
126
|
-
++job.failed
|
|
127
|
-
output.log('❌', progress.label, reason)
|
|
128
|
-
})
|
|
129
|
-
.finally(() => {
|
|
130
|
-
++job[$statusProgressCount]
|
|
131
|
-
progress.done()
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function batch (job) {
|
|
136
|
-
/**
|
|
137
|
-
* job
|
|
138
|
-
* path: full path
|
|
139
|
-
* id: batchId | hash (using filename)
|
|
140
|
-
* label: batchLabel | configuration file path | path
|
|
141
|
-
* args: []
|
|
142
|
-
* --report-dir is always passed to aggregate reports under one root folder
|
|
143
|
-
*/
|
|
144
|
-
const output = getOutput(job)
|
|
145
|
-
job.start = new Date()
|
|
146
|
-
job.failed = 0
|
|
147
|
-
job.batchItems = []
|
|
148
|
-
for (const batch of job.batch) {
|
|
149
|
-
output.debug('batch', `processing: ${batch}`)
|
|
150
|
-
// check if path
|
|
151
|
-
try {
|
|
152
|
-
let path = batch
|
|
153
|
-
if (!isAbsolute(path)) {
|
|
154
|
-
path = join(job.cwd, path)
|
|
155
|
-
}
|
|
156
|
-
const pathStat = await stat(path)
|
|
157
|
-
if (pathStat.isDirectory()) {
|
|
158
|
-
folder(job, path)
|
|
159
|
-
} else if (pathStat.isFile() && extname(path) === '.json') {
|
|
160
|
-
configurationFile(job, path)
|
|
161
|
-
} else {
|
|
162
|
-
output.batchFailed(batch, 'only folders and JSON configuration files are supported')
|
|
163
|
-
}
|
|
164
|
-
continue
|
|
165
|
-
} catch (e) {
|
|
166
|
-
// ignore
|
|
167
|
-
}
|
|
168
|
-
// Try using regular expression match
|
|
169
|
-
let re
|
|
170
|
-
try {
|
|
171
|
-
re = new RegExp(batch)
|
|
172
|
-
} catch (e) {
|
|
173
|
-
getOutput(job).batchFailed(batch, 'invalid regular expression')
|
|
174
|
-
continue
|
|
175
|
-
}
|
|
176
|
-
const scan = async (cwd) => {
|
|
177
|
-
const names = await readdir(cwd)
|
|
178
|
-
for (const name of names) {
|
|
179
|
-
const path = join(cwd, name)
|
|
180
|
-
const pathStat = await stat(path)
|
|
181
|
-
if (pathStat.isDirectory()) {
|
|
182
|
-
if (re.test(path) || re.test(path.replaceAll('\\', '/'))) {
|
|
183
|
-
folder(job, path)
|
|
184
|
-
continue
|
|
185
|
-
}
|
|
186
|
-
await scan(path)
|
|
187
|
-
} else if (pathStat.isFile() && (re.test(path) || re.test(path.replaceAll('\\', '/')))) {
|
|
188
|
-
configurationFile(job, path)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
await scan(job.cwd)
|
|
193
|
-
}
|
|
194
|
-
if (job.batchItems.length) {
|
|
195
|
-
job.status = 'Running batch items...'
|
|
196
|
-
await parallelize(task.bind(job), job.batchItems, job.parallel)
|
|
197
|
-
} else {
|
|
198
|
-
output.batchFailed(job.batch, 'no match')
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
job.end = new Date()
|
|
202
|
-
job.failed = !!job.failed
|
|
203
|
-
if (job.failed) {
|
|
204
|
-
process.exitCode = -1
|
|
205
|
-
}
|
|
206
|
-
await save(job)
|
|
207
|
-
if (job.endScript) {
|
|
208
|
-
await end(job)
|
|
209
|
-
}
|
|
210
|
-
output.stop()
|
|
211
|
-
return 0
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
module.exports = { batch, task }
|