| 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); |
| +}); |