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: Created March 12, 2018, 8:23 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
« firefox_process.js ('K') | « test/browser/index.html ('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("./chromium_process");
30 const firefoxProcess = require("./firefox_process");
30 31
31 let unitFiles = []; 32 let unitFiles = [];
32 let browserFiles = []; 33 let browserFiles = [];
33 34
35 let runnerDefinitions = {
36 chromium: chromiumProcess,
37 firefox: firefoxProcess
38 };
39
40 function configureRunners()
41 {
42 let runners = "BROWSER_TEST_RUNNERS" in process.env ?
43 process.env.BROWSER_TEST_RUNNERS.split(",") : [];
44
45 // default is chromium only, for now.
46 if (runners.length == 0)
47 return ["chromium", "firefox"];
48
49 runners.filter(runner => runner in runnerDefinitions);
50
51 return runners;
52 }
53
54 let runnerProcesses = configureRunners();
55
34 function addTestPaths(testPaths, recurse) 56 function addTestPaths(testPaths, recurse)
35 { 57 {
36 for (let testPath of testPaths) 58 for (let testPath of testPaths)
37 { 59 {
38 let stat = fs.statSync(testPath); 60 let stat = fs.statSync(testPath);
39 if (stat.isDirectory()) 61 if (stat.isDirectory())
40 { 62 {
41 if (recurse) 63 if (recurse)
42 { 64 {
43 addTestPaths(fs.readdirSync(testPath).map( 65 addTestPaths(fs.readdirSync(testPath).map(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 else 108 else
87 { 109 {
88 let bundle = memoryFS.readFileSync("/" + bundleFilename, "utf-8"); 110 let bundle = memoryFS.readFileSync("/" + bundleFilename, "utf-8");
89 memoryFS.unlinkSync("/" + bundleFilename); 111 memoryFS.unlinkSync("/" + bundleFilename);
90 resolve(bundle); 112 resolve(bundle);
91 } 113 }
92 }); 114 });
93 }); 115 });
94 } 116 }
95 117
96 function runBrowserTests() 118 function runBrowserTests(processes)
97 { 119 {
98 if (!browserFiles.length) 120 if (!browserFiles.length)
99 return; 121 return;
100 122
101 let nodeunitPath = path.join(__dirname, "node_modules", "nodeunit", 123 let nodeunitPath = path.join(__dirname, "node_modules", "nodeunit",
102 "examples", "browser", "nodeunit.js"); 124 "examples", "browser", "nodeunit.js");
103 let bundleFilename = "bundle.js"; 125 let bundleFilename = "bundle.js";
104 126
105 return webpackInMemory(bundleFilename, { 127 return webpackInMemory(bundleFilename, {
106 entry: path.join(__dirname, "test", "browser", "_bootstrap.js"), 128 entry: path.join(__dirname, "test", "browser", "_bootstrap.js"),
107 module: { 129 module: {
108 rules: [{ 130 rules: [{
109 resource: nodeunitPath, 131 resource: nodeunitPath,
110 // I would have rather used exports-loader here, to avoid treating 132 // I would have rather used exports-loader here, to avoid treating
111 // nodeunit as a global. Unfortunately the nodeunit browser example 133 // nodeunit as a global. Unfortunately the nodeunit browser example
112 // script is quite slopily put together, if exports isn't falsey it 134 // 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 135 // breaks! As a workaround we need to use script-loader, which means
114 // that exports is falsey for that script as a side-effect. 136 // that exports is falsey for that script as a side-effect.
115 use: ["script-loader"] 137 use: ["script-loader"]
116 }] 138 }]
117 }, 139 },
118 resolve: { 140 resolve: {
119 alias: { 141 alias: {
120 nodeunit$: nodeunitPath 142 nodeunit$: nodeunitPath
121 }, 143 },
122 modules: [path.resolve(__dirname, "lib")] 144 modules: [path.resolve(__dirname, "lib")]
123 } 145 }
124 }).then(bundle => 146 }).then(bundle =>
125 { 147 Promise.all(
126 return chromiumProcess( 148 processes.map(currentProcess =>
127 bundle, bundleFilename, 149 runnerDefinitions[currentProcess](
128 browserFiles.map( 150 bundle, bundleFilename,
129 file => path.relative(path.join(__dirname, "test", "browser"), 151 browserFiles.map(
130 file).replace(/\.js$/, "") 152 file => path.relative(path.join(__dirname, "test", "browser"),
153 file).replace(/\.js$/, "")
154 )
155 )
131 ) 156 )
132 ); 157 )
133 }); 158 );
134 } 159 }
135 160
136 if (process.argv.length > 2) 161 if (process.argv.length > 2)
137 addTestPaths(process.argv.slice(2), true); 162 addTestPaths(process.argv.slice(2), true);
138 else 163 else
139 { 164 {
140 addTestPaths( 165 addTestPaths(
141 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")], 166 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")],
142 true 167 true
143 ); 168 );
144 } 169 }
145 170
146 Promise.resolve(runBrowserTests()).catch(error => 171 Promise.resolve(runBrowserTests(runnerProcesses)).catch(error =>
147 { 172 {
148 console.error("Failed running browser tests"); 173 console.error("Failed running browser tests");
149 console.error(error); 174 console.error(error);
150 }).then(() => 175 }).then(() =>
151 { 176 {
152 if (unitFiles.length) 177 if (unitFiles.length)
153 nodeunit.reporters.default.run(unitFiles); 178 nodeunit.reporters.default.run(unitFiles);
154 }); 179 });
OLDNEW
« firefox_process.js ('K') | « test/browser/index.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld