Skip to content

Commit 8a1b6f2

Browse files
authored
build: fix being unable to run e2e tests locally on windows (#23219)
Fixes that e2e tests cannot be run locally on Windows right now. This happens because there is no sandbox on Windows w/ Bazel and the `start-devserver.js` utility accidentally resolves to a `.mjs` file due to the patched NodeJS module resolution. We specify an explicit file extension to avoid resolving an ESM module. Also simplifies the server launching because the Protractor utils now expose a method for starting the server.
1 parent c7baa54 commit 8a1b6f2

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

src/e2e-app/start-devserver.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,16 @@
11
const protractor = require('protractor');
2-
const utils = require('@bazel/protractor/protractor-utils');
3-
const spawn = require('child_process').spawn;
42

5-
/**
6-
* Runs the specified server binary from a given workspace and waits for the server
7-
* being ready. The server binary will be resolved from the runfiles.
8-
*/
9-
async function runBazelServer(workspace, serverPath, timeout) {
10-
const serverBinary = require.resolve(`${workspace}/${serverPath}`);
11-
const port = await utils.findFreeTcpPort();
12-
13-
// Start the Bazel server binary with a random free TCP port.
14-
const serverProcess = spawn(serverBinary, ['-port', port], {stdio: 'inherit'});
15-
16-
// In case the process exited with an error, we want to propagate the error.
17-
serverProcess.on('exit', exitCode => {
18-
if (exitCode !== 0) {
19-
throw new Error(`Server exited with error code: ${exitCode}`);
20-
}
21-
});
22-
23-
// Wait for the server to be bound to the given port.
24-
await utils.waitForServer(port, timeout);
25-
26-
return port;
27-
}
3+
// Note: We need to specify an explicit file extension here because otherwise
4+
// the Bazel-patched NodeJS module resolution would resolve to the `.mjs` file
5+
// in non-sandbox environments (as usually with Bazel and Windows).
6+
const utils = require('@bazel/protractor/protractor-utils.js');
287

298
/**
309
* Called by Protractor before starting any tests. This is script is responsible for
3110
* starting up the devserver and updating the Protractor base URL to the proper port.
3211
*/
3312
module.exports = async function(config) {
34-
const port = await runBazelServer(config.workspace, config.server);
13+
const {port} = await utils.runServer(config.workspace, config.server, '-port', []);
3514
const baseUrl = `http://localhost:${port}`;
3615
const processedConfig = await protractor.browser.getProcessedConfig();
3716

0 commit comments

Comments
 (0)