-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move unittests to run-unittests.mjs - Move common test driver and server setup to separate helper.mjs module - Add "SpeedometerReady" and "SpeedometerDone" events for easier testing - Add simple end2end tests that invoke the benchmark via the html page
- Loading branch information
1 parent
9f85f8e
commit 0c3f0fb
Showing
11 changed files
with
357 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import commandLineUsage from "command-line-usage"; | ||
import commandLineArgs from "command-line-args"; | ||
import serve from "./server.mjs"; | ||
|
||
import { Builder, Capabilities, logging } from "selenium-webdriver"; | ||
|
||
const optionDefinitions = [ | ||
{ name: "browser", type: String, description: "Set the browser to test, choices are [safari, firefox, chrome]. By default the $BROWSER env variable is used." }, | ||
{ name: "port", type: Number, defaultValue: 8010, description: "Set the test-server port, The default value is 8010." }, | ||
{ name: "help", alias: "h", description: "Print this help text." }, | ||
]; | ||
|
||
function printHelp(message = "", exitStatus = 0) { | ||
const usage = commandLineUsage([ | ||
{ | ||
header: "Run all tests", | ||
}, | ||
{ | ||
header: "Options", | ||
optionList: optionDefinitions, | ||
}, | ||
]); | ||
if (message) { | ||
console.error(message); | ||
console.error(); | ||
} | ||
console.log(usage); | ||
process.exit(exitStatus); | ||
} | ||
|
||
export default async function testSetup(helpText) { | ||
const options = commandLineArgs(optionDefinitions); | ||
|
||
if ("help" in options) | ||
printHelp(helpText); | ||
|
||
const BROWSER = options?.browser; | ||
if (!BROWSER) | ||
printHelp("No browser specified, use $BROWSER or --browser", 1); | ||
|
||
let capabilities; | ||
switch (BROWSER) { | ||
case "safari": | ||
capabilities = Capabilities.safari(); | ||
break; | ||
|
||
case "firefox": { | ||
capabilities = Capabilities.firefox(); | ||
break; | ||
} | ||
case "chrome": { | ||
capabilities = Capabilities.chrome(); | ||
break; | ||
} | ||
case "edge": { | ||
capabilities = Capabilities.edge(); | ||
break; | ||
} | ||
default: { | ||
printHelp(`Invalid browser "${BROWSER}", choices are: "safari", "firefox", "chrome", "edge"`); | ||
} | ||
} | ||
const prefs = new logging.Preferences(); | ||
prefs.setLevel(logging.Type.BROWSER, logging.Level.ALL); // Capture all log levels | ||
capabilities.setLoggingPrefs(prefs); | ||
|
||
const PORT = options.port; | ||
const server = serve(PORT); | ||
let driver; | ||
|
||
process.on("unhandledRejection", (err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
process.once("uncaughtException", (err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
process.on("exit", () => stop()); | ||
|
||
driver = await new Builder().withCapabilities(capabilities).build(); | ||
driver.manage().window().setRect({ width: 1200, height: 1000 }); | ||
|
||
function stop() { | ||
server.close(); | ||
if (driver) | ||
driver.close(); | ||
} | ||
return { driver, PORT, stop }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.