Skip to content

Commit

Permalink
Update UI test environment config override if installed plugins change (
Browse files Browse the repository at this point in the history
#22285)

* Update UI test environment config override if installed plugins change

* Remove UI test asset retry
  • Loading branch information
mneudert authored Jun 5, 2024
1 parent 30acd11 commit a694468
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
36 changes: 34 additions & 2 deletions tests/PHPUnit/Framework/Mock/TestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,33 @@

use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Config;
use Piwik\Plugin\Manager;
use Piwik\Tests\Framework\TestingEnvironmentVariables;

class TestConfig extends Config
{
private $allowSave = false;
private $doSetTestEnvironment = false;
/**
* @var bool
*/
private $allowSave;

/**
* @var bool
*/
private $doSetTestEnvironment;

/**
* @var TestingEnvironmentVariables
*/
private $testingEnvironment;

public function __construct(GlobalSettingsProvider $provider, TestingEnvironmentVariables $testingEnvironment, $allowSave = false, $doSetTestEnvironment = true)
{
parent::__construct($provider);

$this->allowSave = $allowSave;
$this->doSetTestEnvironment = $doSetTestEnvironment;
$this->testingEnvironment = $testingEnvironment;

$this->reload();

Expand All @@ -42,6 +56,24 @@ public function forceSave()
if ($this->allowSave) {
parent::forceSave();
}

if (!$this->doSetTestEnvironment) {
return;
}

$environmentPlugins = $this->testingEnvironment->configOverride['PluginsInstalled']['PluginsInstalled'] ?? [];
$installedPlugins = Manager::getInstance()->getInstalledPluginsName();

$onlyEnvironment = array_diff($environmentPlugins, $installedPlugins);
$onlyInstalled = array_diff($installedPlugins, $environmentPlugins);

if ([] === $onlyEnvironment && [] === $onlyInstalled) {
// environment matches list of installed plugins
return;
}

$this->testingEnvironment->overrideConfig('PluginsInstalled', 'PluginsInstalled', $installedPlugins);
$this->testingEnvironment->save();
}

public function setTestEnvironment()
Expand Down
34 changes: 0 additions & 34 deletions tests/lib/screenshot-testing/support/page-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,20 +457,6 @@ PageRenderer.prototype._setupWebpageEvents = function () {
if (!VERBOSE) {
this._logMessage('Unable to load resource (URL:' + request.url() + '): ' + errorMessage);
}

var type = '';
if (type = request.url().match(/action=get(Css|CoreJs|NonCoreJs|UmdJs)/)) {
if (errorMessage === 'net::ERR_ABORTED' && (!response || response.status() !== 500)) {
console.log(type[1]+' request aborted.');
} else if (request.url().indexOf('&reload=') === -1) {
console.log('Loading '+type[1]+' failed (' + errorMessage + ')... Try adding it with another tag.');
var method = type[1] == 'Css' ? 'addStyleTag' : 'addScriptTag';
await this.webpage[method]({url: request.url() + '&reload=' + Date.now()}); // add another get parameter to ensure browser doesn't use cache
await this.waitForNetworkIdle(); // wait for request to finish before continuing with tests
} else {
console.log('Reloading '+type[1]+' failed (' + errorMessage + ').');
}
}
});

this.webpage.on('requestfinished', async (request) => {
Expand All @@ -489,26 +475,6 @@ PageRenderer.prototype._setupWebpageEvents = function () {
const message = 'Response (size "' + bodyLength + '", status "' + response.status() + '"): ' + request.url() + "\n" + bodyContent.substring(0, 2000);
this._logMessage(message);
}

// if response of css or js request does not start with /*, we assume it had an error and try to load it again
// Note: We can't do that in requestfailed only, as the response code might be 200 even if it throws an exception
var type = '';
if (type = request.url().match(/action=get(Css|CoreJs|NonCoreJs)/)) {
var body = await response.buffer();
if (body.toString().substring(0, 2) === '/*') {
return;
}
if (request.url().indexOf('&reload=') === -1) {
console.log('Loading '+type[1]+' failed... Try adding it with another tag.');
var method = type[1] == 'Css' ? 'addStyleTag' : 'addScriptTag';
await this.waitForNetworkIdle(); // wait for other requests to finish before trying to reload
await this.webpage[method]({url: request.url() + '&reload=' + Date.now()}); // add another get parameter to ensure browser doesn't use cache
await this.webpage.waitForTimeout(1000);
} else {
console.log('Reloading '+type[1]+' failed.');
}
console.log('Response (size "' + body.length + '", status "' + response.status() + ', headers "' + JSON.stringify(response.headers()) + '"): ' + request.url() + "\n" + body.toString());
}
});

this.webpage.on('console', async (consoleMessage) => {
Expand Down

0 comments on commit a694468

Please sign in to comment.