From c7ecbbd6845d93e035e3d15970a9b9a33f42a5ca Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Thu, 21 Feb 2019 17:00:32 +0100 Subject: [PATCH] selenium: improve ffmpeg reporting 1) stdout/stderr log improvement Our wdio test suite records video of Selenium test session using ffmpeg, its stdout/stderr are relayed via console.log() however the new line was not stripped which is confusing and in case the buffer contains multiple lines, only the first line had the 'ffmpeg stderr: ' prefix. Ensure each ffmpeg line is prefixed by logging them individually. 2) exit code / signal childProcess 'close' event is being passed the exit code and the signal. We only handled the exit code, thus when ffmpeg is send a signal we logged: ffmpeg exited with code null Handle the case when the childProcess is send a signal (typically SIGINT). Change-Id: I9f509690baa9b7981399a09448582f45c30800d7 --- tests/selenium/wdio.conf.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/selenium/wdio.conf.js b/tests/selenium/wdio.conf.js index 11be135404..bdabdbfdb3 100644 --- a/tests/selenium/wdio.conf.js +++ b/tests/selenium/wdio.conf.js @@ -154,6 +154,7 @@ exports.config = { */ beforeTest: function ( test ) { if ( process.env.DISPLAY && process.env.DISPLAY.startsWith( ':' ) ) { + var logBuffer; let videoPath = filePath( test, logPath, 'mp4' ); const { spawn } = require( 'child_process' ); ffmpeg = spawn( 'ffmpeg', [ @@ -166,17 +167,29 @@ exports.config = { videoPath // output file ] ); + logBuffer = function ( buffer, prefix ) { + let lines = buffer.toString().trim().split( '\n' ); + lines.forEach( function ( line ) { + console.log( prefix + line ); + } ); + }; + ffmpeg.stdout.on( 'data', ( data ) => { - console.log( `ffmpeg stdout: ${data}` ); + logBuffer( data, 'ffmpeg stdout: ' ); } ); ffmpeg.stderr.on( 'data', ( data ) => { - console.log( `ffmpeg stderr: ${data}` ); + logBuffer( data, 'ffmpeg stderr: ' ); } ); - ffmpeg.on( 'close', ( code ) => { + ffmpeg.on( 'close', ( code, signal ) => { console.log( '\n\tVideo location:', videoPath, '\n' ); - console.log( `ffmpeg exited with code ${code}` ); + if ( code !== null ) { + console.log( `\tffmpeg exited with code ${code} ${videoPath}` ); + } + if ( signal !== null ) { + console.log( `\tffmpeg received signal ${signal} ${videoPath}` ); + } } ); } }, -- 2.20.1