|
1 | 1 | const protractor = require('protractor');
|
2 |
| -const utils = require('@bazel/protractor/protractor-utils'); |
3 |
| -const spawn = require('child_process').spawn; |
4 | 2 |
|
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'); |
28 | 7 |
|
29 | 8 | /**
|
30 | 9 | * Called by Protractor before starting any tests. This is script is responsible for
|
31 | 10 | * starting up the devserver and updating the Protractor base URL to the proper port.
|
32 | 11 | */
|
33 | 12 | 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', []); |
35 | 14 | const baseUrl = `http://localhost:${port}`;
|
36 | 15 | const processedConfig = await protractor.browser.getProcessedConfig();
|
37 | 16 |
|
|
0 commit comments