Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/firefox.js

Issue 29864561: Issue 6884 - Migrate from nodeunit to mocha (Closed)
Patch Set: Inline reportElements() for better code locality Created Aug. 26, 2018, 7:09 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/firefox.js
===================================================================
--- a/test/firefox.js
+++ b/test/firefox.js
@@ -15,11 +15,14 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+/* eslint-env mocha */
+
"use strict";
const FIREFOX_VERSION = "57.0";
const path = require("path");
+const assert = require("assert");
const webdriver = require("selenium-webdriver");
const {By, until} = webdriver;
const firefox = require("selenium-webdriver/firefox");
@@ -27,62 +30,47 @@
const {ensureFirefox} = require("../adblockpluscore/test/runners/" +
"firefox_download");
-function reportElements(test, driver, success)
-{
- return driver.findElements(
- By.css(`#qunit-tests ${success ? ".pass" : ".fail"} .test-name`)
- ).then(elements => Promise.all(elements.map(elem =>
- elem.getAttribute("innerHTML").then(data => test.ok(success, data))
- )));
-}
-
-exports.runFirefox = function(test)
+describe("Firefox", function()
{
- // https://stackoverflow.com/a/45045036
- function installWebExt(driver, extension)
- {
- let cmd = new Command("moz-install-web-ext")
- .setParameter("path", path.resolve(extension))
- .setParameter("temporary", true);
+ this.timeout(0);
+
+ let driver;
+ let origin;
- driver.getExecutor()
- .defineCommand(cmd.getName(), "POST",
- "/session/:sessionId/moz/addon/install");
+ before(() =>
+ ensureFirefox(FIREFOX_VERSION).then(firefoxPath =>
+ {
+ let binary = new firefox.Binary(firefoxPath);
+ binary.addArguments("-headless");
- return driver.schedule(cmd, `installWebExt(${extension})`);
- }
+ driver = new webdriver.Builder()
+ .forBrowser("firefox")
+ .setFirefoxOptions(new firefox.Options().setBinary(binary))
+ .build();
- ensureFirefox(FIREFOX_VERSION).then(firefoxPath =>
- {
- let binary = new firefox.Binary(firefoxPath);
-
- binary.addArguments("-headless");
+ let devenv = "./devenv.gecko";
+ let cmd = new Command("moz-install-web-ext")
+ .setParameter("path", path.resolve(devenv))
+ .setParameter("temporary", true);
- let options = new firefox.Options()
- .setBinary(binary);
-
- let driver = new webdriver.Builder()
- .forBrowser("firefox")
- .setFirefoxOptions(options)
- .build();
-
- installWebExt(driver, "./devenv.gecko");
+ driver.getExecutor().defineCommand(
+ cmd.getName(), "POST",
+ "/session/:sessionId/moz/addon/install"
+ );
+ driver.schedule(cmd, `installWebExt(${devenv})`);
- driver.wait(() =>
- // Wait for the firstrun-page to be loaded
- driver.getAllWindowHandles().then(handles =>
- {
- if (handles.length > 1)
- {
- driver.switchTo().window(handles[1]);
- return true;
- }
- return false;
- })
- ).then(() =>
- // Navigate to the qunit index
- driver.executeScript("location.href = \"qunit/index.html\";")
- ).then(() =>
+ return driver.wait(() =>
+ driver.getAllWindowHandles().then(handles => handles[1])
+ ).then(handle =>
+ driver.switchTo().window(handle)
+ ).then(() =>
+ driver.executeScript("return location.origin;")
+ ).then(result => { origin = result; });
+ })
+ );
+
+ it("qunit", () =>
+ driver.navigate().to(origin + "/qunit/index.html").then(() =>
// Wait for qunit-results to be present
driver.wait(until.elementLocated(By.id("qunit-testresult")))
).then(() =>
@@ -91,12 +79,14 @@
driver.findElement(By.id("qunit-testresult"))
.getAttribute("innerHTML").then(data =>
data.includes("Tests completed")))
- ).then(() => Promise.all([
- reportElements(test, driver, true),
- reportElements(test, driver, false)
- ])).then(
- () => driver.quit().then(() => test.done()),
- err => driver.quit().then(() => { throw err; })
- );
- });
-};
+ ).then(() => Promise.all([[true, ".pass"], [false, ".fail"]].map(
+ ([success, sel]) => driver.findElements(
+ By.css(`#qunit-tests ${sel} .test-name`)
+ ).then(elements => Promise.all(elements.map(elem =>
+ elem.getAttribute("textContent").then(data => assert.ok(success, data))
+ )))
+ )))
+ );
+
+ after(() => driver.quit());
+});
« no previous file with comments | « package.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld