Adding output support to Behat plugin.
This commit is contained in:
parent
1f4fb58014
commit
9133c544d5
|
@ -184,6 +184,7 @@ PHPCI',
|
||||||
'phpspec' => 'PHP Spec',
|
'phpspec' => 'PHP Spec',
|
||||||
'phpunit' => 'PHP Unit',
|
'phpunit' => 'PHP Unit',
|
||||||
'technical_debt' => 'Technical Debt',
|
'technical_debt' => 'Technical Debt',
|
||||||
|
'behat' => 'Behat',
|
||||||
|
|
||||||
'file' => 'File',
|
'file' => 'File',
|
||||||
'line' => 'Line',
|
'line' => 'Line',
|
||||||
|
|
|
@ -66,12 +66,64 @@ class Behat implements \PHPCI\Plugin
|
||||||
|
|
||||||
if (!$behat) {
|
if (!$behat) {
|
||||||
$this->phpci->logFailure(Lang::get('could_not_find', 'behat'));
|
$this->phpci->logFailure(Lang::get('could_not_find', 'behat'));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->phpci->executeCommand($behat . ' %s', $this->features);
|
$success = $this->phpci->executeCommand($behat . ' %s', $this->features);
|
||||||
chdir($curdir);
|
chdir($curdir);
|
||||||
|
|
||||||
|
list($errorCount, $data) = $this->parseBehatOutput();
|
||||||
|
|
||||||
|
$this->build->storeMeta('behat-warnings', $errorCount);
|
||||||
|
$this->build->storeMeta('behat-data', $data);
|
||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the behat output and return details on failures
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function parseBehatOutput()
|
||||||
|
{
|
||||||
|
$output = $this->phpci->getLastOutput();
|
||||||
|
|
||||||
|
$parts = explode('---', $output);
|
||||||
|
|
||||||
|
if (count($parts) <= 1) {
|
||||||
|
return array(0, array());
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines = explode(PHP_EOL, $parts[1]);
|
||||||
|
|
||||||
|
$errorCount = 0;
|
||||||
|
$storeFailures = false;
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$line = trim($line);
|
||||||
|
if ($line == 'Failed scenarios:') {
|
||||||
|
$storeFailures = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($line, ':') === false) {
|
||||||
|
$storeFailures = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($storeFailures) {
|
||||||
|
$lineParts = explode(':', $line);
|
||||||
|
$data[] = array(
|
||||||
|
'file' => $lineParts[0],
|
||||||
|
'line' => $lineParts[1]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$errorCount = count($data);
|
||||||
|
|
||||||
|
return array($errorCount, $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,7 +202,5 @@ class TechnicalDebt implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($errorCount, $data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
74
public/assets/js/build-plugins/behat.js
Normal file
74
public/assets/js/build-plugins/behat.js
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
var BehatPlugin = ActiveBuild.UiPlugin.extend({
|
||||||
|
id: 'build-behat',
|
||||||
|
css: 'col-lg-6 col-md-12 col-sm-12 col-xs-12',
|
||||||
|
title: Lang.get('behat'),
|
||||||
|
lastData: null,
|
||||||
|
box: true,
|
||||||
|
rendered: false,
|
||||||
|
|
||||||
|
register: function() {
|
||||||
|
var self = this;
|
||||||
|
var query = ActiveBuild.registerQuery('behat-data', -1, {key: 'behat-data'})
|
||||||
|
|
||||||
|
$(window).on('behat-data', function(data) {
|
||||||
|
self.onUpdate(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).on('build-updated', function() {
|
||||||
|
if (!self.rendered) {
|
||||||
|
query();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
render: function() {
|
||||||
|
return $('<div class="table-responsive"><table class="table" id="behat-data">' +
|
||||||
|
'<thead>' +
|
||||||
|
'<tr>' +
|
||||||
|
' <th>'+Lang.get('file')+'</th>' +
|
||||||
|
' <th>'+Lang.get('line')+'</th>' +
|
||||||
|
'</tr>' +
|
||||||
|
'</thead><tbody></tbody></table></div>');
|
||||||
|
},
|
||||||
|
|
||||||
|
onUpdate: function(e) {
|
||||||
|
if (!e.queryData) {
|
||||||
|
$('#build-behat').hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rendered = true;
|
||||||
|
this.lastData = e.queryData;
|
||||||
|
|
||||||
|
var errors = this.lastData[0].meta_value;
|
||||||
|
var tbody = $('#behat-data tbody');
|
||||||
|
tbody.empty();
|
||||||
|
|
||||||
|
if (errors.length == 0) {
|
||||||
|
$('#build-behat').hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i in errors) {
|
||||||
|
var file = errors[i].file;
|
||||||
|
|
||||||
|
if (ActiveBuild.fileLinkTemplate) {
|
||||||
|
var fileLink = ActiveBuild.fileLinkTemplate.replace('{FILE}', file);
|
||||||
|
fileLink = fileLink.replace('{LINE}', errors[i].line);
|
||||||
|
|
||||||
|
file = '<a target="_blank" href="'+fileLink+'">' + file + '</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
var row = $('<tr class="danger">' +
|
||||||
|
'<td>'+file+'</td>' +
|
||||||
|
'<td>'+errors[i].line+'</td>' +
|
||||||
|
'</tr>');
|
||||||
|
|
||||||
|
tbody.append(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#build-behat').show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ActiveBuild.registerPlugin(new BehatPlugin());
|
Loading…
Reference in a new issue