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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/browser/elemHideEmulation.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /* eslint-env node */ 18 /* eslint-env node */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const childProcess = require("child_process");
23 const fs = require("fs"); 22 const fs = require("fs");
23 const path = require("path");
24 const url = require("url");
25
24 const nodeunit = require("nodeunit"); 26 const nodeunit = require("nodeunit");
25 const path = require("path"); 27
26 const phantomjs = require("phantomjs2"); 28 const chromiumProcess = require("./chromium_process");
27 const process = require("process");
28 const url = require("url");
29 29
30 let unitFiles = []; 30 let unitFiles = [];
31 let browserFiles = []; 31 let browserFiles = [];
32
32 function addTestPaths(testPaths, recurse) 33 function addTestPaths(testPaths, recurse)
33 { 34 {
34 for (let testPath of testPaths) 35 for (let testPath of testPaths)
35 { 36 {
36 let stat = fs.statSync(testPath); 37 let stat = fs.statSync(testPath);
37 if (stat.isDirectory()) 38 if (stat.isDirectory())
38 { 39 {
39 if (recurse) 40 if (recurse)
40 { 41 {
41 addTestPaths(fs.readdirSync(testPath).map( 42 addTestPaths(fs.readdirSync(testPath).map(
42 file => path.join(testPath, file))); 43 file => path.join(testPath, file)));
43 } 44 }
44 continue; 45 continue;
45 } 46 }
46 if (path.basename(testPath).startsWith("_")) 47 if (path.basename(testPath).startsWith("_"))
47 continue; 48 continue;
48 if (path.extname(testPath) == ".js") 49 if (path.extname(testPath) == ".js")
49 { 50 {
50 if (testPath.split(path.sep).includes("browser")) 51 if (testPath.split(path.sep).includes("browser"))
51 browserFiles.push(testPath); 52 browserFiles.push(testPath);
52 else 53 else
53 unitFiles.push(testPath); 54 unitFiles.push(testPath);
54 } 55 }
55 } 56 }
56 } 57 }
58
59 function getFileURL(filePath)
60 {
61 return url.format({
62 protocol: "file",
63 slashes: "true",
64 pathname: path.resolve(process.cwd(), filePath).split(path.sep).join("/")
65 });
66 }
67
68 function runBrowserTests()
69 {
70 if (!browserFiles.length)
71 return;
72
73 // Navigate to this directory because about:blank won't be allowed to load
74 // file:/// URLs.
75 let initialPage = getFileURL(__dirname);
76 let bootstrapPath = path.join(__dirname, "test", "browser",
77 "_bootstrap.js");
78 let nodeunitPath = path.join(
79 path.dirname(require.resolve("nodeunit")),
80 "examples", "browser", "nodeunit.js"
81 );
82 let args = [
83 getFileURL(nodeunitPath),
84 ...browserFiles.map(getFileURL)
85 ];
86 return chromiumProcess(initialPage, bootstrapPath, args);
87 }
88
57 if (process.argv.length > 2) 89 if (process.argv.length > 2)
58 addTestPaths(process.argv.slice(2), true); 90 addTestPaths(process.argv.slice(2), true);
59 else 91 else
60 { 92 {
61 addTestPaths( 93 addTestPaths(
62 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")], 94 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")],
63 true 95 true
64 ); 96 );
65 } 97 }
66 98
67 if (browserFiles.length) 99 Promise.resolve(runBrowserTests()).catch(error =>
68 { 100 {
69 let nodeunitPath = path.join( 101 console.error("Failed running browser tests");
70 path.dirname(require.resolve("nodeunit")), 102 console.error(error);
71 "examples", "browser", "nodeunit.js" 103 }).then(() =>
72 ); 104 {
73 browserFiles.unshift(nodeunitPath); 105 if (unitFiles.length)
74 106 nodeunit.reporters.default.run(unitFiles);
75 let urls = browserFiles.map(file => 107 });
76 {
77 return url.format({
78 protocol: "file",
79 slashes: "true",
80 pathname: path.resolve(process.cwd(), file).split(path.sep).join("/")
81 });
82 });
83 let args = [path.join(__dirname, "browsertests.js")].concat(urls);
84 childProcess.execFileSync(phantomjs.path, args, {stdio: "inherit"});
85 }
86 if (unitFiles.length)
87 nodeunit.reporters.default.run(unitFiles);
OLDNEW
« 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