Skip to content

Commit

Permalink
Merge branch 'feature/region-support' into 'main'
Browse files Browse the repository at this point in the history
adding region support, and test timing debug information (for --json)

See merge request uilicious/cli-code!13
  • Loading branch information
Eugene Cheah committed Mar 1, 2022
2 parents d5a7262 + 4e1f156 commit d0f5773
Showing 1 changed file with 124 additions and 31 deletions.
155 changes: 124 additions & 31 deletions src/cli-command/project/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,38 +147,10 @@ class TestRunnerSession {
let browser = argv.browser || "chrome";
let width = argv.width || 1280;
let height = argv.height || 960;
let region = argv.region || "default";
let dataSet = argv.dataset || argv.dataSet;
let disableSystemErrorRetry = !!argv.disableSystemErrorRetry;

// Normalize the browser string
browser = (browser || "chrome").toLowerCase().trim();
browser = browser.replace(/\s/g,"");
browser = browser.replace(/\-/g,"");

// Validate the browser string
let validBrowserList = [
"chrome",
"firefox",
"edgechromium",
"edge",
"edgelegacy",
"edge2019",
"safari",
"ie11"
];
if( validBrowserList.indexOf(browser) < 0 ) {
throw `Invalid Browser : ${browser}`
}

// Browser remapping
if( browser.startsWith("edge") ) {
if( browser == "edge" || browser == "edgechromium" ) {
browser = "edgechromium";
} else {
browser = "edge";
}
}

// Project start timeout in minutes
let startTimeout = Math.max(argv.startTimeout || argv["start-timeout"] || 15, 0);

Expand Down Expand Up @@ -227,6 +199,7 @@ class TestRunnerSession {
this.browser = browser;
this.width = width;
this.height = height;
this.region = region;
this.dataSet = dataSet;
this.startTimeout = startTimeout;
this.startTimeout_sec = startTimeout_sec;
Expand Down Expand Up @@ -255,6 +228,7 @@ class TestRunnerSession {
`> Project Name: ${this.projectObj.name}`,
`> Project ID: ${this.projectObj._oid}`,
`> Browser: ${this.browser}`,
`> Region: ${this.region}`,
`> Resolution: ${this.width}x${this.height}`,
`> Script Path: ${this.normalizedScriptPath}`,
].join("\n"))
Expand Down Expand Up @@ -326,6 +300,7 @@ class TestRunnerSession {
browser: this.browser,
width: this.width,
height: this.height,
region: this.region,
dataSetID: this.dataSetID,
data: this.dataObject,
secretData: this.secretObject
Expand Down Expand Up @@ -440,7 +415,14 @@ class TestRunnerSession {
processedTestRunSteps.push(formatAndOutputStepObject(step));
} else {
// Minor additional delay for "pending" steps
await sleep(1000+Math.random()*150)
if( index <= 5 ) {
// For first 5 steps, lets, reduce the the "wait" between steps
// await sleep(100+Math.random()*50)
await sleep(10)
} else {
// 1s awaits min
await sleep(1000+Math.random()*150)
}
}

// Minimum 10 ms delay between step - makes outputs more readable
Expand Down Expand Up @@ -499,6 +481,9 @@ class TestRunnerSession {
let startTimeMS = Date.now();
let startTimeoutTimeMS = startTimeMS + this.startTimeout*this.startTimeout_ms;

// save the start time
this._startTimeMS = startTimeMS;

// The final test result status
let finalTestStatus = null;

Expand Down Expand Up @@ -624,6 +609,10 @@ class TestRunnerSession {
">"
];

// Get the test time taken (from CLI point of view)
let startTimeMS = this._startTimeMS;
let timeTakenMS = Date.now() - this._startTimeMS;

// Inject the various URL links
if( !this.assumeOnPremise ) {
// Into the result message
Expand All @@ -646,6 +635,10 @@ class TestRunnerSession {
this.jsonOutputObj.webstudioURL = `${this.webstudioURL}/project/${this.projectID}/editor/${this.uriEncodedScriptPath}?testRunId=${this.testID}`;
}

// Lets add in the CLI debugging information
this.jsonOutputObj._cli = this.jsonOutputObj._cli || {};
this.jsonOutputObj._cli.testTimeTaken_ms = timeTakenMS;

// Handle JSON output
OutputHandler.json( this.jsonOutputObj )

Expand Down Expand Up @@ -714,7 +707,9 @@ module.exports = {
cmd.number("--height <height>", {
description: "[default: 960] Browser height to use (in px)"
});

cmd.string("--region <region-name>", {
description: "[default: 'default'] Browser region to use (chrome, firefox, edgechromium only)"
});
cmd.string("--dataset <set-name>", {
hidden: true,
description: "Dataset to use, belonging to your account and project"
Expand Down Expand Up @@ -744,6 +739,104 @@ module.exports = {
description: "Disable CLI automated retries when uilicious SYSTEM_ERROR occurs"
});
cmd.check((argv,context) => {

//------------------------------------------------------------------
// Browser Checking
//------------------------------------------------------------------

// Get and normalize the browser
let browser = argv.browser || "chrome";

// Normalize the browser string
browser = (browser || "chrome").toLowerCase().trim();
browser = browser.replace(/\s/g,"");
browser = browser.replace(/\-/g,"");

// Validate the browser string
let validBrowserList = [
"chrome",
"firefox",
"edge",
"edgechromium",
"edgelegacy",
"edge2019",
"safari",
"ie11"
];
if( validBrowserList.indexOf(browser) < 0 ) {
OutputHandler.cliArgumentError( `Unknown Browser Selected : ${browser}\nPlease use one of the following browsers: `+validBrowserList.join(", ") )
}

// Browser remapping
if( browser.startsWith("edge") ) {
if( browser == "edge" || browser == "edgechromium" ) {
browser = "edgechromium";
} else {
browser = "edge";
}
}

argv.browser = browser;

//------------------------------------------------------------------
// Region Checking
//------------------------------------------------------------------

// Get the current region selected
let region = argv.region || argv["region-name"] || "default";

// Normalize to lower case
region = region.toLowerCase();

// The full region list to check against
let regionList = [
"default",
"unitedkingdom",
"hongkong",
"singapore",
"usa-newyork",
"usa-sanfranc",
"canada-toronto",
"india-bangalore",
"netherlands-amsterdam",
"germany-frankfurt",
"indonesia-jarkata",
]

// Common aliases
let regionAlias = {
"netherlands": "netherlands-amsterdam",
"amsterdam": "netherlands-amsterdam",
"india" : "india-bangalore",
"bangalore" : "india-bangalore",
"canada" : "canada-toronto",
"toronto" : "canada-toronto",
"germany": "germany-frankfurt",
"frankfurt": "germany-frankfurt",
"indonesia": "indonesia-jarkata",
"jarkata": "indonesia-jarkata",
"usa": "usa-newyork",
"newyork": "usa-newyork",
"sanfranc": "usa-sanfranc"
}

// If region is an alias, remap it
if( regionAlias[region] ) {
region = regionAlias[region];
}

// Check if the region is in the list
if( regionList.indexOf(region) < 0 ) {
OutputHandler.cliArgumentError( `Unknown region selected : ${region}\nPlease use one of the following regions: `+regionList.join(", ") )
}

// Save back the region settings
argv.region = region;

//------------------------------------------------------------------
// DataSet / Object / File Checking
//------------------------------------------------------------------

//
// Get the data arguments
//
Expand Down

0 comments on commit d0f5773

Please sign in to comment.