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

Unified Diff: test_runner.js

Issue 29423569: Issue 4796 - Use a modern JS engine in the browser tests and convert all files to ECMAScript 6 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Addressed some nits Created May 3, 2017, 12:18 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 | « test/browser/elemHideEmulation.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test_runner.js
===================================================================
--- a/test_runner.js
+++ b/test_runner.js
@@ -14,26 +14,27 @@
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/* eslint-env node */
"use strict";
-const childProcess = require("child_process");
const fs = require("fs");
+const path = require("path");
+const url = require("url");
+
const nodeunit = require("nodeunit");
-const path = require("path");
-const phantomjs = require("phantomjs2");
-const process = require("process");
-const url = require("url");
+
+const chromiumProcess = require("./chromium_process");
let unitFiles = [];
let browserFiles = [];
+
function addTestPaths(testPaths, recurse)
{
for (let testPath of testPaths)
{
let stat = fs.statSync(testPath);
if (stat.isDirectory())
{
if (recurse)
@@ -49,39 +50,58 @@ function addTestPaths(testPaths, recurse
{
if (testPath.split(path.sep).includes("browser"))
browserFiles.push(testPath);
else
unitFiles.push(testPath);
}
}
}
+
+function getFileURL(filePath)
+{
+ return url.format({
+ protocol: "file",
+ slashes: "true",
+ pathname: path.resolve(process.cwd(), filePath).split(path.sep).join("/")
+ });
+}
+
+function runBrowserTests()
+{
+ if (!browserFiles.length)
+ return;
+
+ // Navigate to this directory because about:blank won't be allowed to load
+ // file:/// URLs.
+ let initialPage = getFileURL(__dirname);
+ let bootstrapPath = path.join(__dirname, "test", "browser",
+ "_bootstrap.js");
+ let nodeunitPath = path.join(
+ path.dirname(require.resolve("nodeunit")),
+ "examples", "browser", "nodeunit.js"
+ );
+ let args = [
+ getFileURL(nodeunitPath),
+ ...browserFiles.map(getFileURL)
+ ];
+ return chromiumProcess(initialPage, bootstrapPath, args);
+}
+
if (process.argv.length > 2)
addTestPaths(process.argv.slice(2), true);
else
{
addTestPaths(
[path.join(__dirname, "test"), path.join(__dirname, "test", "browser")],
true
);
}
-if (browserFiles.length)
+Promise.resolve(runBrowserTests()).catch(error =>
{
- let nodeunitPath = path.join(
- path.dirname(require.resolve("nodeunit")),
- "examples", "browser", "nodeunit.js"
- );
- browserFiles.unshift(nodeunitPath);
-
- let urls = browserFiles.map(file =>
- {
- return url.format({
- protocol: "file",
- slashes: "true",
- pathname: path.resolve(process.cwd(), file).split(path.sep).join("/")
- });
- });
- let args = [path.join(__dirname, "browsertests.js")].concat(urls);
- childProcess.execFileSync(phantomjs.path, args, {stdio: "inherit"});
-}
-if (unitFiles.length)
- nodeunit.reporters.default.run(unitFiles);
+ console.error("Failed running browser tests");
+ console.error(error);
+}).then(() =>
+{
+ if (unitFiles.length)
+ nodeunit.reporters.default.run(unitFiles);
+});
« no previous file with comments | « test/browser/elemHideEmulation.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld