blob: 3106ee70d66cc9fb0daca1ddebd9228822ae8d4f [file] [log] [blame]
Philipp Schrader175a93c2023-02-19 13:13:40 -08001const child_process = require('child_process');
2const process = require('process');
3
4const cypress = require('cypress');
5
6// Set up the xvfb binary.
7process.env[
8 'PATH'
9] = `${process.env.RUNFILES_DIR}/xvfb_amd64/wrapped_bin:${process.env.PATH}`;
10
11// Start the web server, database, and fake TBA server.
12// We use file descriptor 3 ('pipe') for the test server to let us know when
13// everything has started up.
14console.log('Starting server.');
15let servers = child_process.spawn(
16 'testing/scouting_test_servers',
17 ['--port=8000', '--notify_fd=3'],
18 {
19 stdio: ['inherit', 'inherit', 'inherit', 'pipe'],
20 }
21);
22
23// Wait for the server to finish starting up.
24const serverStartup = new Promise((resolve, reject) => {
25 let cumulativeData = '';
26 servers.stdio[3].on('data', async (data) => {
27 console.log('Got data: ' + data);
28 cumulativeData += data;
29 if (cumulativeData.includes('READY')) {
30 console.log('Everything is ready!');
31 resolve();
32 }
33 });
34
35 servers.on('error', (err) => {
36 console.log(`Failed to start scouting_test_servers: ${err}`);
37 reject();
38 });
39
40 servers.on('close', (code, signal) => {
41 console.log(`scouting_test_servers closed: ${code} (${signal})`);
42 reject();
43 });
44
45 servers.on('exit', (code, signal) => {
46 console.log(`scouting_test_servers exited: ${code} (${signal})`);
47 reject();
48 });
49});
50
51// Wait for the server to shut down.
52const serverShutdown = new Promise((resolve) => {
53 servers.on('exit', () => {
54 resolve();
55 });
56});
57
58// Wait for the server to be ready, run the tests, then shut down the server.
59(async () => {
Philipp Schrader155e76c2023-02-25 18:42:31 -080060 // Parse command line options.
61 let runOptions = await cypress.cli.parseRunArguments(process.argv.slice(2));
62
Philipp Schrader175a93c2023-02-19 13:13:40 -080063 await serverStartup;
Philipp Schrader155e76c2023-02-25 18:42:31 -080064 const result = await cypress.run(
65 Object.assign(runOptions, {
Philipp Schrader155e76c2023-02-25 18:42:31 -080066 config: {
67 baseUrl: 'http://localhost:8000',
68 screenshotsFolder:
69 process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/screenshots',
70 video: false,
71 videosFolder: process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/videos',
72 },
73 })
74 );
Philipp Schrader175a93c2023-02-19 13:13:40 -080075 await servers.kill();
76 await serverShutdown;
77
78 exitCode = 0;
79 if (result.status == 'failed') {
80 exitCode = 1;
81 console.log('-'.repeat(50));
82 console.log('Test FAILED: ' + result.message);
83 console.log('-'.repeat(50));
84 } else if (result.totalFailed > 0) {
85 // When the "before" hook fails, we don't get a "failed" mesage for some
86 // reason. In that case, we just have to exit with an error.
87 exitCode = 1;
88 }
89 process.exit(exitCode);
90})();