mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-18 23:41:45 +03:00
59b3b4dc8d
* tests: Add newlines between impl methods for Project * WIP headless browser testing with geckodriver and selenium * Get some more of headless testing working * Extract `console.log` invocations and print them from the console * Ship the error message from an exception from the browser back to the command line * Cleanup some "if headless" and `else` branches * Fix killing `webpack-dev-server` in the background with `--watch-stdin` * Fix path appending logic for Windows * Always log logs/errors in headless mode * Install Firefox on Travis * Don't duplicate full test suite with `yarn` No need to run that many tests, we should be able to get by with a smoke test that it just works. * headless tests: Move `run-headless.js` to its own file and `include_str!` it * Run `rustfmt` on `tests/all/main.rs` * guide: Add note about headless browser tests and configuration * test: Log WASM_BINDGEN_FIREFOX_BIN_PATH in run-headless.js * TEMP only run add_headless test in CI * Add more logging to headless testing * Allow headless tests to run for 60 seconds before timeout * TEMP add logging to add_headless test * Fix headless browser tests * Another attempt to fix Travis * More attempts at debugging * Fix more merge conflicts * Touch up an error message * Fixup travis again * Enable all travis tests again * Test everything on AppVeyor
129 lines
3.1 KiB
JavaScript
129 lines
3.1 KiB
JavaScript
const process = require("process");
|
|
const { promisify } = require("util");
|
|
const { Builder, By, Key, logging, promise, until } = require("selenium-webdriver");
|
|
const firefox = require("selenium-webdriver/firefox");
|
|
|
|
promise.USE_PROMISE_MANAGER = false;
|
|
|
|
const prefs = new logging.Preferences();
|
|
prefs.setLevel(logging.Type.BROWSER, logging.Level.DEBUG);
|
|
|
|
const opts = new firefox.Options();
|
|
opts.headless();
|
|
if (process.env.WASM_BINDGEN_FIREFOX_BIN_PATH) {
|
|
console.log("Using custom firefox-bin: $WASM_BINDGEN_FIREFOX_BIN_PATH =",
|
|
process.env.WASM_BINDGEN_FIREFOX_BIN_PATH);
|
|
opts.setBinary(process.env.WASM_BINDGEN_FIREFOX_BIN_PATH);
|
|
}
|
|
|
|
console.log("Using Firefox options:", opts);
|
|
|
|
const driver = new Builder()
|
|
.forBrowser("firefox")
|
|
.setFirefoxOptions(opts)
|
|
.build();
|
|
|
|
const SECONDS = 1000;
|
|
const MINUTES = 60 * SECONDS;
|
|
|
|
const start = Date.now();
|
|
const timeSinceStart = () => {
|
|
const elapsed = Date.now() - start;
|
|
const minutes = Math.floor(elapsed / MINUTES);
|
|
const seconds = elapsed % MINUTES / SECONDS;
|
|
return `${minutes}m${seconds.toFixed(3)}s`;
|
|
};
|
|
|
|
async function logged(msg, promise) {
|
|
console.log(`${timeSinceStart()}: START: ${msg}`);
|
|
try {
|
|
const value = await promise;
|
|
console.log(`${timeSinceStart()}: END: ${msg}`);
|
|
return value;
|
|
} catch (e) {
|
|
console.log(`${timeSinceStart()}: ERROR: ${msg}: ${e}\n\n${e.stack}`);
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
let body;
|
|
try {
|
|
await logged(
|
|
"load http://localhost:8080/index.html",
|
|
driver.get("http://localhost:8080/index.html")
|
|
);
|
|
|
|
body = driver.findElement(By.tagName("body"));
|
|
|
|
await logged(
|
|
"Waiting for <body> to include text 'TEST_START'",
|
|
driver.wait(
|
|
until.elementTextContains(body, "TEST_START"),
|
|
1 * MINUTES
|
|
)
|
|
);
|
|
|
|
await logged(
|
|
"Waiting for <body> to include text 'TEST_DONE'",
|
|
driver.wait(
|
|
until.elementTextContains(body, "TEST_DONE"),
|
|
1 * MINUTES
|
|
)
|
|
);
|
|
|
|
const status = await logged(
|
|
"get #status text",
|
|
body.findElement(By.id("status")).getText()
|
|
);
|
|
|
|
console.log(`Test status is: "${status}"`);
|
|
if (status != "good") {
|
|
throw new Error(`test failed with status = ${status}`);
|
|
}
|
|
} finally {
|
|
const logs = await logged(
|
|
"getting browser logs",
|
|
body.findElement(By.id("logs")).getText()
|
|
);
|
|
|
|
if (logs.length > 0) {
|
|
console.log("logs:");
|
|
logs.split("\n").forEach(line => {
|
|
console.log(` ${line}`);
|
|
});
|
|
}
|
|
|
|
const errors = await logged(
|
|
"getting browser errors",
|
|
body.findElement(By.id("error")).getText()
|
|
);
|
|
|
|
if (errors.length > 0) {
|
|
console.log("errors:");
|
|
errors.split("\n").forEach(line => {
|
|
console.log(` ${line}`);
|
|
});
|
|
}
|
|
|
|
const bodyText = await logged(
|
|
"getting browser body",
|
|
body.getText()
|
|
);
|
|
|
|
if (bodyText.length > 0) {
|
|
console.log("body:");
|
|
bodyText.split("\n").forEach(line => {
|
|
console.log(` ${line}`);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
main()
|
|
.finally(() => driver.quit())
|
|
.catch(e => {
|
|
console.error(`Got an error: ${e}\n\nStack: ${e.stack}`);
|
|
process.exit(1);
|
|
});
|