Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | 1x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 58x 58x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 7x 2x 2x 2x 5x 5x 5x 1x 1x 4x 7x 5x 5x 5x 8x 1x 1x 4x 1x 9x 9x 2x 7x 21x 61x 61x 9x 61x 58x 58x 51x 32x 21x 4x 17x 17x 17x 17x 7x 266x 19x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 3x 7x 4x 4x 1x 3x 3x 4x 4x 4x 4x 4x 2x 2x 2x 1x 1x 1x 1x | import path from 'path' import fs from 'fs-extra' import exitHook from 'async-exit-hook' import logger from '@wdio/logger' import { ConfigParser } from '@wdio/config' import { initialisePlugin, initialiseServices } from '@wdio/utils' import CLInterface from './interface' import { runOnPrepareHook, runOnCompleteHook, runServiceHook } from './utils' const log = logger('@wdio/cli:Launcher') class Launcher { constructor (configFile, argv = {}, isWatchMode = false) { this.argv = argv this.configFile = configFile this.configParser = new ConfigParser() this.configParser.addConfigFile(configFile) this.configParser.merge(argv) const config = this.configParser.getConfig() const capabilities = this.configParser.getCapabilities() const specs = this.configParser.getSpecs() Eif (config.outputDir) { fs.ensureDirSync(path.join(config.outputDir)) process.env.WDIO_LOG_PATH = path.join(config.outputDir, 'wdio.log') } logger.setLogLevelsConfig(config.logLevels, config.logLevel) const totalWorkerCnt = Array.isArray(capabilities) ? capabilities .map((c) => this.configParser.getSpecs(c.specs, c.exclude).length) .reduce((a, b) => a + b, 0) : 1 const Runner = initialisePlugin(config.runner, 'runner') this.runner = new Runner(configFile, config) this.interface = new CLInterface(config, specs, totalWorkerCnt, isWatchMode) config.runnerEnv.FORCE_COLOR = Number(this.interface.hasAnsiSupport) this.isMultiremote = !Array.isArray(capabilities) this.exitCode = 0 this.hasTriggeredExitRoutine = false this.hasStartedAnyProcess = false this.schedule = [] this.rid = [] this.runnerStarted = 0 this.runnerFailed = 0 } /** * run sequence * @return {Promise} that only gets resolves with either an exitCode or an error */ async run () { let config = this.configParser.getConfig() let caps = this.configParser.getCapabilities() const launcher = initialiseServices(config, caps, 'launcher') /** * run pre test tasks for runner plugins * (e.g. deploy Lambda function to AWS) */ await this.runner.initialise() /** * run onPrepare hook */ log.info('Run onPrepare hook') await runOnPrepareHook(config.onPrepare, config, caps) await runServiceHook(launcher, 'onPrepare', config, caps) /** * catches ctrl+c event */ exitHook(::this.exitHandler) let exitCode = await this.runMode(config, caps) /** * run onComplete hook * even if it fails we still want to see result and end logger stream */ log.info('Run onComplete hook') await runServiceHook(launcher, 'onComplete', exitCode, config, caps) const onCompleteResults = await runOnCompleteHook(config.onComplete, config, caps, exitCode, this.interface.result) // if any of the onComplete hooks failed, update the exit code exitCode = onCompleteResults.includes(1) ? 1 : exitCode await logger.waitForBuffer() this.interface.finalise() return exitCode } /** * run without triggering onPrepare/onComplete hooks */ runMode (config, caps) { /** * fail if no caps were found */ if (!caps || (!this.isMultiremote && !caps.length)) { return new Promise((resolve) => { log.error('Missing capabilities, exiting with failure') return resolve(1) }) } /** * avoid retries in watch mode */ const specFileRetries = config.watch ? 0 : config.specFileRetries /** * schedule test runs */ let cid = 0 if (this.isMultiremote) { /** * Multiremote mode */ this.schedule.push({ cid: cid++, caps, specs: this.configParser.getSpecs(caps.specs, caps.exclude).map(s => ({ files: [s], retries: specFileRetries })), availableInstances: config.maxInstances || 1, runningInstances: 0 }) } else { /** * Regular mode */ for (let capabilities of caps) { this.schedule.push({ cid: cid++, caps: capabilities, specs: this.configParser.getSpecs(capabilities.specs, capabilities.exclude).map(s => ({ files: [s], retries: specFileRetries })), availableInstances: capabilities.maxInstances || config.maxInstancesPerCapability, runningInstances: 0, seleniumServer: { hostname: config.hostname, port: config.port, protocol: config.protocol } }) } } return new Promise((resolve) => { this.resolve = resolve /** * fail if no specs were found or specified */ if (Object.values(this.schedule).reduce((specCnt, schedule) => specCnt + schedule.specs.length, 0) === 0) { log.error('No specs found to run, exiting with failure') return resolve(1) } /** * return immediately if no spec was run */ if (this.runSpecs()) { resolve(0) } }) } /** * run multiple single remote tests * @return {Boolean} true if all specs have been run and all instances have finished */ runSpecs () { let config = this.configParser.getConfig() /** * stop spawning new processes when CTRL+C was triggered */ if (this.hasTriggeredExitRoutine) { return true } while (this.getNumberOfRunningInstances() < config.maxInstances) { let schedulableCaps = this.schedule /** * bail if number of errors exceeds allowed */ .filter(() => { const filter = typeof config.bail !== 'number' || config.bail < 1 || config.bail > this.runnerFailed /** * clear number of specs when filter is false */ if (!filter) { this.schedule.forEach((t) => { t.specs = [] }) } return filter }) /** * make sure complete number of running instances is not higher than general maxInstances number */ .filter(() => this.getNumberOfRunningInstances() < config.maxInstances) /** * make sure the capability has available capacities */ .filter((a) => a.availableInstances > 0) /** * make sure capability has still caps to run */ .filter((a) => a.specs.length > 0) /** * make sure we are running caps with less running instances first */ .sort((a, b) => a.runningInstances > b.runningInstances) /** * continue if no capability were schedulable */ if (schedulableCaps.length === 0) { break } let specs = schedulableCaps[0].specs.shift() this.startInstance( specs.files, schedulableCaps[0].caps, schedulableCaps[0].cid, schedulableCaps[0].seleniumServer, specs.rid, specs.retries ) schedulableCaps[0].availableInstances-- schedulableCaps[0].runningInstances++ } return this.getNumberOfRunningInstances() === 0 && this.getNumberOfSpecsLeft() === 0 } /** * gets number of all running instances * @return {number} number of running instances */ getNumberOfRunningInstances () { return this.schedule.map((a) => a.runningInstances).reduce((a, b) => a + b) } /** * get number of total specs left to complete whole suites * @return {number} specs left to complete suite */ getNumberOfSpecsLeft () { return this.schedule.map((a) => a.specs.length).reduce((a, b) => a + b) } /** * Start instance in a child process. * @param {Array} specs Specs to run * @param {Number} cid Capabilities ID * @param {String} rid Runner ID override * @param {Number} retries Number of retries remaining */ startInstance (specs, caps, cid, server, rid, retries) { let config = this.configParser.getConfig() // Retried tests receive the cid of the failing test as rid // so they can run with the same cid of the failing test. cid = rid || this.getRunnerId(cid) let processNumber = this.runnerStarted + 1 // process.debugPort defaults to 5858 and is set even when process // is not being debugged. let debugArgs = [] let debugType let debugHost = '' let debugPort = process.debugPort for (let i in process.execArgv) { const debugArgs = process.execArgv[i].match('--(debug|inspect)(?:-brk)?(?:=(.*):)?') if (debugArgs) { let [, type, host] = debugArgs if (type) { debugType = type } if (host) { debugHost = `${host}:` } } } Iif (debugType) { debugArgs.push(`--${debugType}=${debugHost}${(debugPort + processNumber)}`) } // if you would like to add --debug-brk, use a different port, etc... let capExecArgs = [ ...(config.execArgv || []), ...(caps.execArgv || []) ] // The default value for child.fork execArgs is process.execArgs, // so continue to use this unless another value is specified in config. let defaultArgs = (capExecArgs.length) ? process.execArgv : [] // If an arg appears multiple times the last occurrence is used let execArgv = [...defaultArgs, ...debugArgs, ...capExecArgs] // prefer launcher settings in capabilities over general launcher const worker = this.runner.run({ cid, command: 'run', configFile: this.configFile, argv: this.argv, caps, specs, server, execArgv, retries }) worker.on('message', ::this.interface.onMessage) worker.on('error', ::this.interface.onMessage) worker.on('exit', ::this.endHandler) this.interface.emit('job:start', { cid, caps, specs }) this.runnerStarted++ } /** * generates a runner id * @param {Number} cid capability id (unique identifier for a capability) * @return {String} runner id (combination of cid and test id e.g. 0a, 0b, 1a, 1b ...) */ getRunnerId (cid) { if (!this.rid[cid]) { this.rid[cid] = 0 } return `${cid}-${this.rid[cid]++}` } /** * Close test runner process once all child processes have exited * @param {Number} cid Capabilities ID * @param {Number} exitCode exit code of child process * @param {Array} specs Specs that were run * @param {Number} retries Number or retries remaining */ endHandler ({ cid, exitCode, specs, retries }) { const passed = exitCode === 0 if (!passed && retries > 0) { this.schedule[parseInt(cid)].specs.push({ files: specs, retries: retries - 1, rid: cid }) } else { this.exitCode = this.exitCode || exitCode this.runnerFailed += !passed ? 1 : 0 } this.interface.emit('job:end', { cid, passed, retries }) /** * Update schedule now this process has ended */ // get cid (capability id) from rid (runner id) cid = parseInt(cid, 10) this.schedule[cid].availableInstances++ this.schedule[cid].runningInstances-- if (!this.runSpecs()) { return } this.resolve(passed ? this.exitCode : 1) } /** * Make sure all started selenium sessions get closed properly and prevent * having dead driver processes. To do so let the runner end its Selenium * session first before killing */ exitHandler (callback) { if (!callback) { return } this.hasTriggeredExitRoutine = true this.interface.sigintTrigger() return this.runner.shutdown().then(callback) } } export default Launcher |