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

Side by Side Diff: test_runner.js

Issue 29720661: Issue 6391 - Allow running the browser unit tests with Firefox (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: eslint options and gitignore Created April 24, 2018, 2:05 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
« test/runners/firefox_process.js ('K') | « test/runners/webdriver.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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 fs = require("fs"); 22 const fs = require("fs");
23 const path = require("path"); 23 const path = require("path");
24 24
25 const MemoryFS = require("memory-fs"); 25 const MemoryFS = require("memory-fs");
26 const nodeunit = require("nodeunit"); 26 const nodeunit = require("nodeunit");
27 const webpack = require("webpack"); 27 const webpack = require("webpack");
28 28
29 const chromiumProcess = require("./chromium_process"); 29 const chromiumProcess = require("./test/runners/chromium_process");
30 const chromiumWdProcess = require("./test/runners/chromiumwd_process");
31 const firefoxProcess = require("./test/runners/firefox_process");
30 32
31 let unitFiles = []; 33 let unitFiles = [];
32 let browserFiles = []; 34 let browserFiles = [];
33 35
36 let runnerDefinitions = {
37 // Chromium with chrome-remote-interface
38 chromium_remote: chromiumProcess,
kzar 2018/05/04 10:52:44 So do I have this right that by default the browse
hub 2018/05/18 00:04:22 Yes
39 // Chromium with WebDriver ( >= 63.0.3239)
40 chromium: chromiumWdProcess,
41 firefox: firefoxProcess
42 };
43
44 function configureRunners()
kzar 2018/05/04 10:52:44 I wonder what the point of this function is, since
hub 2018/05/18 00:04:23 I think it is nice to have this in its own functio
45 {
46 let runners = "BROWSER_TEST_RUNNERS" in process.env ?
47 process.env.BROWSER_TEST_RUNNERS.split(",") : [];
48
49 if (runners.length == 0)
50 return ["chromium", "firefox"];
51
52 runners.filter(runner => runnerDefinitions.hasOwnProperty(runner));
kzar 2018/05/04 10:52:43 Shouldn't this instead be `return runners.filter..
hub 2018/05/18 00:04:22 good catch. fixed.
53
54 return runners;
55 }
56
57 let runnerProcesses = configureRunners();
58
34 function addTestPaths(testPaths, recurse) 59 function addTestPaths(testPaths, recurse)
35 { 60 {
36 for (let testPath of testPaths) 61 for (let testPath of testPaths)
37 { 62 {
38 let stat = fs.statSync(testPath); 63 let stat = fs.statSync(testPath);
39 if (stat.isDirectory()) 64 if (stat.isDirectory())
40 { 65 {
41 if (recurse) 66 if (recurse)
42 { 67 {
43 addTestPaths(fs.readdirSync(testPath).map( 68 addTestPaths(fs.readdirSync(testPath).map(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 else 111 else
87 { 112 {
88 let bundle = memoryFS.readFileSync("/" + bundleFilename, "utf-8"); 113 let bundle = memoryFS.readFileSync("/" + bundleFilename, "utf-8");
89 memoryFS.unlinkSync("/" + bundleFilename); 114 memoryFS.unlinkSync("/" + bundleFilename);
90 resolve(bundle); 115 resolve(bundle);
91 } 116 }
92 }); 117 });
93 }); 118 });
94 } 119 }
95 120
96 function runBrowserTests() 121 function runBrowserTests(processes)
97 { 122 {
98 if (!browserFiles.length) 123 if (!browserFiles.length)
99 return; 124 return;
100 125
101 let nodeunitPath = path.join(__dirname, "node_modules", "nodeunit", 126 let nodeunitPath = path.join(__dirname, "node_modules", "nodeunit",
102 "examples", "browser", "nodeunit.js"); 127 "examples", "browser", "nodeunit.js");
103 let bundleFilename = "bundle.js"; 128 let bundleFilename = "bundle.js";
104 129
105 return webpackInMemory(bundleFilename, { 130 return webpackInMemory(bundleFilename, {
106 entry: path.join(__dirname, "test", "browser", "_bootstrap.js"), 131 entry: path.join(__dirname, "test", "browser", "_bootstrap.js"),
107 module: { 132 module: {
108 rules: [{ 133 rules: [{
109 resource: nodeunitPath, 134 resource: nodeunitPath,
110 // I would have rather used exports-loader here, to avoid treating 135 // I would have rather used exports-loader here, to avoid treating
111 // nodeunit as a global. Unfortunately the nodeunit browser example 136 // nodeunit as a global. Unfortunately the nodeunit browser example
112 // script is quite slopily put together, if exports isn't falsey it 137 // script is quite slopily put together, if exports isn't falsey it
113 // breaks! As a workaround we need to use script-loader, which means 138 // breaks! As a workaround we need to use script-loader, which means
114 // that exports is falsey for that script as a side-effect. 139 // that exports is falsey for that script as a side-effect.
115 use: ["script-loader"] 140 use: ["script-loader"]
116 }] 141 }]
117 }, 142 },
118 resolve: { 143 resolve: {
119 alias: { 144 alias: {
120 nodeunit$: nodeunitPath 145 nodeunit$: nodeunitPath
121 }, 146 },
122 modules: [path.resolve(__dirname, "lib")] 147 modules: [path.resolve(__dirname, "lib")]
123 } 148 }
124 }).then(bundle => 149 }).then(bundle =>
125 { 150 Promise.all(
126 return chromiumProcess( 151 processes.map(currentProcess =>
127 bundle, bundleFilename, 152 runnerDefinitions[currentProcess](
128 browserFiles.map( 153 bundle, bundleFilename,
129 file => path.relative(path.join(__dirname, "test", "browser"), 154 browserFiles.map(
130 file).replace(/\.js$/, "") 155 file => path.relative(path.join(__dirname, "test", "browser"),
156 file).replace(/\.js$/, "")
157 )
158 )
131 ) 159 )
132 ); 160 )
133 }); 161 );
134 } 162 }
135 163
136 if (process.argv.length > 2) 164 if (process.argv.length > 2)
137 addTestPaths(process.argv.slice(2), true); 165 addTestPaths(process.argv.slice(2), true);
138 else 166 else
139 { 167 {
140 addTestPaths( 168 addTestPaths(
141 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")], 169 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")],
142 true 170 true
143 ); 171 );
144 } 172 }
145 173
146 Promise.resolve(runBrowserTests()).catch(error => 174 Promise.resolve(runBrowserTests(runnerProcesses)).catch(error =>
147 { 175 {
148 console.error("Failed running browser tests"); 176 console.error("Failed running browser tests");
149 console.error(error); 177 console.error(error);
150 }).then(() => 178 }).then(() =>
151 { 179 {
152 if (unitFiles.length) 180 if (unitFiles.length)
153 nodeunit.reporters.default.run(unitFiles); 181 nodeunit.reporters.default.run(unitFiles);
154 }); 182 });
OLDNEW
« test/runners/firefox_process.js ('K') | « test/runners/webdriver.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld