blob: c8f60f894057bbefb620d4a44815c21e4b519726 [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, {
66 headless: true,
67 config: {
68 baseUrl: 'http://localhost:8000',
69 screenshotsFolder:
70 process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/screenshots',
71 video: false,
72 videosFolder: process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/videos',
73 },
74 })
75 );
Philipp Schrader175a93c2023-02-19 13:13:40 -080076 await servers.kill();
77 await serverShutdown;
78
79 exitCode = 0;
80 if (result.status == 'failed') {
81 exitCode = 1;
82 console.log('-'.repeat(50));
83 console.log('Test FAILED: ' + result.message);
84 console.log('-'.repeat(50));
85 } else if (result.totalFailed > 0) {
86 // When the "before" hook fails, we don't get a "failed" mesage for some
87 // reason. In that case, we just have to exit with an error.
88 exitCode = 1;
89 }
90 process.exit(exitCode);
91})();