| Index: test_runner.js | 
| diff --git a/test_runner.js b/test_runner.js | 
| index 094c7b93296276b1d24cc9d5e73ecfecd3b248d9..da2f25f4aa9d3e5a8ff68e8c40e70ba19a7af8fc 100644 | 
| --- a/test_runner.js | 
| +++ b/test_runner.js | 
| @@ -21,9 +21,10 @@ | 
| const fs = require("fs"); | 
| const path = require("path"); | 
| -const url = require("url"); | 
| const nodeunit = require("nodeunit"); | 
| +const webpack = require("webpack"); | 
| +const MemoryFS = require("memory-fs"); | 
| const chromiumProcess = require("./chromium_process"); | 
| @@ -49,41 +50,84 @@ function addTestPaths(testPaths, recurse) | 
| if (path.extname(testPath) == ".js") | 
| { | 
| if (testPath.split(path.sep).includes("browser")) | 
| - browserFiles.push(testPath); | 
| + { | 
| + browserFiles.push( | 
| + path.relative(path.join(__dirname, "test", "browser"), | 
| + testPath).replace(/\.js$/, "") | 
| + ); | 
| + } | 
| else | 
| unitFiles.push(testPath); | 
| } | 
| } | 
| } | 
| -function getFileURL(filePath) | 
| +function webpackInMemory(bundleFilename, options) | 
| { | 
| - return url.format({ | 
| - protocol: "file", | 
| - slashes: "true", | 
| - pathname: path.resolve(process.cwd(), filePath).split(path.sep).join("/") | 
| + return new Promise((resolve, reject) => | 
| + { | 
| + // Based on this example https://webpack.js.org/api/node/#custom-file-systems | 
| + let memoryFS = new MemoryFS(); | 
| + | 
| + options.output = {filename: bundleFilename, path: "/"}; | 
| + let webpackCompiler = webpack(options); | 
| + webpackCompiler.outputFileSystem = memoryFS; | 
| + | 
| + webpackCompiler.run((err, stats) => | 
| + { | 
| + // Error handling is based on this example | 
| + // https://webpack.js.org/api/node/#error-handling | 
| + if (err) | 
| + { | 
| + let reason = err.stack || err; | 
| + if (err.details) | 
| + reason += "\n" + err.details; | 
| + reject(reason); | 
| + } | 
| + else if (stats.hasErrors()) | 
| + reject(stats.toJson().errors); | 
| + else | 
| + { | 
| + let bundle = memoryFS.readFileSync("/" + bundleFilename, "utf-8"); | 
| + memoryFS.unlinkSync("/" + bundleFilename); | 
| + resolve(bundle); | 
| + } | 
| + }); | 
| }); | 
| } | 
| function runBrowserTests() | 
| { | 
| if (!browserFiles.length) | 
| - return; | 
| + return Promise.resolve(); | 
| 
 
Wladimir Palant
2017/08/17 13:06:11
Or maybe just change the call below from runBrowse
 
kzar
2017/08/17 13:26:43
Done.
 
 | 
| - // 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); | 
| + let nodeunitPath = path.join(__dirname, "node_modules", "nodeunit", | 
| + "examples", "browser", "nodeunit.js"); | 
| + let bundleFilename = "bundle.js"; | 
| + | 
| + return webpackInMemory(bundleFilename, { | 
| + entry: path.join(__dirname, "test", "browser", "_bootstrap.js"), | 
| + module: { | 
| + rules: [{ | 
| + resource: nodeunitPath, | 
| + // I would have rathered used exports-loader here, to avoid treating | 
| + // nodeunit as a global. Unfortunately the nodeunit browser example | 
| + // script is quite slopily put together, if exports isn't falsey it | 
| + // breaks! As a workaround we need to use script-loader, which means | 
| + // that exports is falsey for that script as a side-effect. | 
| + use: ["script-loader"] | 
| + }] | 
| + }, | 
| + resolve: { | 
| + alias: { | 
| + nodeunit$: nodeunitPath | 
| + }, | 
| + modules: [path.resolve(__dirname, "lib")] | 
| + } | 
| + }).then(bundle => | 
| + { | 
| + return chromiumProcess(bundle, bundleFilename, browserFiles); | 
| + }); | 
| } | 
| if (process.argv.length > 2) | 
| @@ -96,7 +140,7 @@ else | 
| ); | 
| } | 
| -Promise.resolve(runBrowserTests()).catch(error => | 
| +runBrowserTests().catch(error => | 
| { | 
| console.error("Failed running browser tests"); | 
| console.error(error); |