Skip to content

Commit

Permalink
Add support for Safari & Mac testing to dpta #584788 (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
hnn0003 authored Mar 30, 2021
1 parent fe33f33 commit 3e255d0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
1 change: 1 addition & 0 deletions test-apps/display-performance-test-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Run the command "npm run test:chrome" to run the backend and automatically bring up a Google Chrome browser window to start the test. This will also automatically kill **ALL** Google Chrome browser windows once the test has completed.
* Run the command "npm run test:edge" to run the backend and automatically bring up an Edge browser window to start the test. This will also automatically kill **ALL** Edge browser windows once the test has completed.
* Run the command "npm run test:firefox" to run the backend and automatically bring up a FireFox browser window to start the test. This will also automatically kill **ALL** FireFox browser windows once the test has completed.
* Run the command "npm run test:safari" to run the backend and automatically bring up a Safari browser window to start the test. This will also automatically kill **ALL** Safari browser windows once the test has completed.

## Options available for a performance test run:

Expand Down
1 change: 1 addition & 0 deletions test-apps/display-performance-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"test:chrome": "node ./lib/common/npmCommands.js chrome",
"test:edge": "node ./lib/common/npmCommands.js edge",
"test:firefox": "node ./lib/common/npmCommands.js firefox",
"test:safari": "node ./lib/common/npmCommands.js safari",
"build:mobile-backend": "tsc 1>&2 && webpack --config ./node_modules/@bentley/webpack-tools/mobile/backend.config.js --env.outdir=./lib/mobile --env.entry=./lib/backend/MobileMain.js --env.bundlename=main ",
"test": "",
"cover": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class DisplayPerfRpcImpl extends DisplayPerfRpcInterface {
}
let argOutputPath: string | undefined;
process.argv.forEach((arg, index) => {
if (index >= 2 && arg !== "chrome" && arg !== "edge" && arg !== "firefox" && arg !== "headless" && arg.split(".").pop() !== "json") {
if (index >= 2 && arg !== "chrome" && arg !== "edge" && arg !== "firefox" && arg !== "safari" && arg !== "headless" && arg.split(".").pop() !== "json") {
while (arg.endsWith("\\") || arg.endsWith("\/"))
arg = arg.slice(0, -1);
argOutputPath = `"argOutputPath": "${arg}",`;
Expand Down
36 changes: 26 additions & 10 deletions test-apps/display-performance-test-app/src/backend/WebMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function startWebServer() {
process.argv.forEach((arg) => {
if (arg.split(".").pop() === "json")
DisplayPerfRpcInterface.jsonFilePath = arg;
else if (arg === "chrome" || arg === "edge" || arg === "firefox")
else if (arg === "chrome" || arg === "edge" || arg === "firefox" || arg === "safari")
browser = arg;
else if (arg === "headless")
chromeFlags.push("--headless");
Expand Down Expand Up @@ -99,13 +99,29 @@ function startWebServer() {
// ---------------------------------------------
// Start the browser, if given a specific one
// ---------------------------------------------
if (browser === "chrome")
chromeLauncher.launch({ // eslint-disable-line @typescript-eslint/no-floating-promises
startingUrl: "http://localhost:3000",
chromeFlags,
}).then((val) => { DisplayPerfRpcInterface.chrome = val; });
else if (browser === "firefox")
child_process.execSync("start firefox http://localhost:3000");
else if (browser === "edge")
child_process.execSync("start microsoft-edge:http://localhost:3000");
switch (browser) {
case "chrome":
if (process.platform === "darwin") { // Ie, if running on Mac
child_process.execSync("open -a \"Google Chrome\" http://localhost:3000");
} else {
chromeLauncher.launch({ // eslint-disable-line @typescript-eslint/no-floating-promises
startingUrl: "http://localhost:3000",
chromeFlags,
}).then((val) => { DisplayPerfRpcInterface.chrome = val; });
}
break;
case "edge":
child_process.execSync("start microsoft-edge:http://localhost:3000");
break;
case "safari":
child_process.execSync("open -a Safari http://localhost:3000");
break;
case "firefox":
if (process.platform === "darwin") { // Ie, if running on Mac
child_process.execSync("open -a firefox http://localhost:3000");
} else {
child_process.execSync("start firefox http://localhost:3000");
}
break;
}
})();
26 changes: 21 additions & 5 deletions test-apps/display-performance-test-app/src/common/npmCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,28 @@ let browser = "";
for (let i = 2; i < process.argv.length; i++) {
const curArg = process.argv[i];
args += `${curArg} `;
if (curArg === "chrome" || curArg === "edge" || curArg === "firefox")
if (curArg === "chrome" || curArg === "edge" || curArg === "firefox" || curArg === "safari")
browser = curArg;
}
execSync(`npm run start:web ${args}`, { stdio: [0, 1, 2] });

if (browser === "edge")
execSync("taskkill /f /im MicrosoftEdge.exe /t >nul");
else if (browser === "firefox")
execSync("taskkill /f /im firefox.exe /t >nul");
switch (browser) {
case "chrome":
if (process.platform === "darwin") { // Ie, if running on Mac
execSync("killall \"Google Chrome\"");
}
break;
case "edge":
execSync("taskkill /f /im msedge.exe /t >nul");
break;
case "safari":
execSync("killall Safari");
break;
case "firefox":
if (process.platform === "darwin") { // Ie, if running on Mac
execSync("killall firefox");
} else {
execSync("taskkill /f /im firefox.exe /t >nul");
}
break;
}

0 comments on commit 3e255d0

Please sign in to comment.