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

Side by Side Diff: test_runner.js

Issue 29517687: Issue 5079, 5516 - Use webpack for browser tests, modules for content scripts (Closed)
Patch Set: Created Aug. 16, 2017, 3:40 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
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 fs = require("fs"); 22 const fs = require("fs");
23 const path = require("path"); 23 const path = require("path");
24 const url = require("url");
25 24
26 const nodeunit = require("nodeunit"); 25 const nodeunit = require("nodeunit");
27 26
28 const chromiumProcess = require("./chromium_process"); 27 const chromiumProcess = require("./chromium_process");
29 28
30 let unitFiles = []; 29 let unitFiles = [];
31 let browserFiles = []; 30 let browserFiles = [];
32 31
33 function addTestPaths(testPaths, recurse) 32 function addTestPaths(testPaths, recurse)
34 { 33 {
(...skipping 14 matching lines...) Expand all
49 if (path.extname(testPath) == ".js") 48 if (path.extname(testPath) == ".js")
50 { 49 {
51 if (testPath.split(path.sep).includes("browser")) 50 if (testPath.split(path.sep).includes("browser"))
52 browserFiles.push(testPath); 51 browserFiles.push(testPath);
53 else 52 else
54 unitFiles.push(testPath); 53 unitFiles.push(testPath);
55 } 54 }
56 } 55 }
57 } 56 }
58 57
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() 58 function runBrowserTests()
69 { 59 {
70 if (!browserFiles.length) 60 if (browserFiles.length)
71 return; 61 return chromiumProcess(browserFiles);
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 } 62 }
88 63
89 if (process.argv.length > 2) 64 if (process.argv.length > 2)
90 addTestPaths(process.argv.slice(2), true); 65 addTestPaths(process.argv.slice(2), true);
91 else 66 else
92 { 67 {
93 addTestPaths( 68 addTestPaths(
94 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")], 69 [path.join(__dirname, "test"), path.join(__dirname, "test", "browser")],
95 true 70 true
96 ); 71 );
97 } 72 }
98 73
99 Promise.resolve(runBrowserTests()).catch(error => 74 Promise.resolve(runBrowserTests()).catch(error =>
100 { 75 {
101 console.error("Failed running browser tests"); 76 console.error("Failed running browser tests");
102 console.error(error); 77 console.error(error);
103 }).then(() => 78 }).then(() =>
104 { 79 {
105 if (unitFiles.length) 80 if (unitFiles.length)
106 nodeunit.reporters.default.run(unitFiles); 81 nodeunit.reporters.default.run(unitFiles);
107 }); 82 });
OLDNEW
« test/browser/elemHideEmulation.js ('K') | « test/browser/elemHideEmulation.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld