Skip to content

Commit

Permalink
MDL-63977 Behat: Read config.json version from running Ionic server
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Feb 12, 2019
1 parent ff3ccab commit 3e42f12
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions lib/behat/classes/behat_config_util.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,27 +700,40 @@ protected function get_behat_profile($profile, $values) {
* This is based on the current mobile app version (from its package.json) and all known
* mobile app versions (based on the list appversions.json in the lib/behat directory).
*
* @param bool $verbose If true, outputs information about installed app version
* @return string List of tags or '' if not supporting mobile
*/
protected function get_mobile_version_tags() : string {
protected function get_mobile_version_tags($verbose = true) : string {
global $CFG;

if (empty($CFG->behat_ionic_dirroot)) {
if (!empty($CFG->behat_ionic_dirroot)) {
// Get app version from package.json.
$jsonpath = $CFG->behat_ionic_dirroot . '/package.json';
$json = @file_get_contents($jsonpath);
if (!$json) {
throw new coding_exception('Unable to load app version from ' . $jsonpath);
}
$package = json_decode($json);
if ($package === null || empty($package->version)) {
throw new coding_exception('Invalid app package data in ' . $jsonpath);
}
$installedversion = $package->version;
} else if (!empty($CFG->behat_ionic_wwwroot)) {
// Get app version from config.json inside wwwroot.
$jsonurl = $CFG->behat_ionic_wwwroot . '/config.json';
$json = @download_file_content($jsonurl);
if (!$json) {
throw new coding_exception('Unable to load app version from ' . $jsonurl);
}
$config = json_decode($json);
if ($config === null || empty($config->versionname)) {
throw new coding_exception('Invalid app config data in ' . $jsonurl);
}
$installedversion = str_replace('-dev', '', $config->versionname);
} else {
return '';
}

// Get app version.
$jsonpath = $CFG->behat_ionic_dirroot . '/package.json';
$json = @file_get_contents($jsonpath);
if (!$json) {
throw new coding_exception('Unable to load app version from ' . $jsonpath);
}
$package = json_decode($json);
if ($package === null) {
throw new coding_exception('Invalid app package data in ' . $jsonpath);
}
$installedversion = $package->version;

// Read all feature files to check which mobile tags are used. (Note: This could be cached
// but ideally, it is the sort of thing that really ought to be refreshed by doing a new
// Behat init. Also, at time of coding it only takes 0.3 seconds and only if app enabled.)
Expand Down Expand Up @@ -751,7 +764,7 @@ protected function get_mobile_version_tags() : string {
// Installed version OLDER than the one being considered, so do not
// include any scenarios that only run from the considered version up.
if ($direction === 'from') {
$tags[] = '~app_from' . $version;
$tags[] = '~@app_from' . $version;
}
break;

Expand All @@ -764,11 +777,16 @@ protected function get_mobile_version_tags() : string {
// Installed version NEWER than the one being considered, so do not
// include any scenarios that only run up to that version.
if ($direction === 'upto') {
$tags[] = '~app_upto' . $version;
$tags[] = '~@app_upto' . $version;
}
break;
}
}

if ($verbose) {
mtrace('Configured app tests for version ' . $installedversion);
}

return join(' && ', $tags);
}

Expand Down Expand Up @@ -1360,7 +1378,8 @@ protected function get_behat_features_for_theme($theme) {

// Mobile app tests are not theme-specific, so run only for the default theme (and if
// configured).
if (empty($CFG->behat_ionic_dirroot) || $theme !== $this->get_default_theme()) {
if ((empty($CFG->behat_ionic_dirroot) && empty($CFG->behat_ionic_wwwroot)) ||
$theme !== $this->get_default_theme()) {
$themeblacklisttags[] = '@app';
}

Expand Down

0 comments on commit 3e42f12

Please sign in to comment.