MCPcopy Create free account
hub / github.com/angular/dev-infra / runTest

Function runTest

bazel/http-server/test/server-test.ts:22–98  ·  view source on GitHub ↗

* Test script that will start the test http server binary in a background process. * Once the server is available and listening, Chromium from `bazel/browsers` is * launched through Selenium to ensure that the environment variable inlining, * actual resolution of JavaScript resources and `index.h

()

Source from the content-addressed store, hash-verified

20 * actual resolution of JavaScript resources and `index.html` works as expected.
21 */
22async function runTest() {
23 const [chromiumRootpath, chromedriverRootpath] = process.argv.slice(2);
24
25 // Resolve chromium, chromedriver and the server binary to disk paths.
26 const chromiumPath = path.resolve(chromiumRootpath);
27 const chromedriverPath = path.resolve(chromedriverRootpath);
28 const serverBinPath = path.resolve('bazel/http-server/test/server');
29
30 const serverPort = 1234;
31 const serverHost = `127.0.0.1:${serverPort}`;
32
33 // Start test http server in background
34 const serverProcess = childProcess.spawn(serverBinPath, ['--port', `${serverPort}`], {
35 env: {...process.env, GOOGLE_MAPS_API_KEY: 'myPersonalSecret'},
36 stdio: 'inherit',
37 });
38
39 console.error('Spawning');
40
41 serverProcess.on('error', (err) => {
42 console.error(err);
43 });
44
45 // Ensure the process gets killed, if the test terminates early.
46 process.on('exit', () => serverProcess.kill());
47
48 // Keep track of potentially launched webdriver instance, so that
49 // we can kill it when the test code errors unexpectedly.
50 let driver: WebDriver | null = null;
51
52 try {
53 // Wait for server to be ready, regardless of status code (404/200 or else)
54 await waitOn({
55 resources: [`http-get://${serverHost}`],
56 timeout: 20_000,
57 headers: {
58 'accept': 'text/html',
59 },
60 });
61
62 const service = new ServiceBuilder(chromedriverPath);
63 const options = new ChromeOptions();
64 options.setChromeBinaryPath(chromiumPath).addArguments('--no-sandbox', '--headless');
65
66 driver = await new Builder()
67 .forBrowser('chrome')
68 .setChromeOptions(options)
69 .setChromeService(service)
70 .build();
71
72 await driver.get(`http://${serverHost}`);
73
74 let bodyText = await driver.findElement(By.css('body')).getText();
75
76 // Assert that the variable is inlined, and that the `index.html` renders.
77 if (bodyText !== 'Works My key: myPersonalSecret') {
78 throw Error(`Unexpected body: ${bodyText}`);
79 }

Callers 1

server-test.tsFile · 0.85

Calls 4

sliceMethod · 0.45
errorMethod · 0.45
onMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected