Migrate from rules_nodejs to rules_js
This patch is huge because I can't easily break it into smaller
pieces. This is largely because a few things are changing with the
migration.
Firstly, we're upgrading the angular libraries and our version of
typescript. This is actually not too disruptive. It required some
changes in the top-level `package.json` file.
Secondly, the new rules have this concept of copying everything into
the `bazel-bin` directory and executing out of there. This makes the
various tools like node and angular happy, but means that a few file
paths are changing. For example, the `common.css` file can't have the
same path in the source tree as it does in the `bazel-bin` tree, so I
moved it to a `common` directory inside the `bazel-bin` tree. You can
read more about this here:
https://docs.aspect.build/rules/aspect_rules_js#running-nodejs-programs
Thirdly, I couldn't find a simple way to support Protractor in
rules_js. Protractor is the end-to-end testing framework we use for
the scouting application. Since protractor is getting deprecated and
won't receive any more updates, it's time to move to something else.
We settled on Cypress because it appears to be popular and should make
debugging easier for the students. For example, it takes screenshots
of the browser when an assertion fails. It would have been ideal to
switch to Cypress before this migration, but I couldn't find a simple
way to make that work with rules_nodejs. In other words, this
migration patch is huge in part because we are also switching testing
frameworks at the same time. I wanted to split it out, but it was more
difficult than I would have liked.
Fourthly, I also needed to migrate the flatbuffer rules. This I think
is relatively low impact, but it again means that this patch is bigger
than I wanted it to be.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I6674874f985952f2e3ef40274da0a2fb9e5631a7
diff --git a/scouting/cypress_runner.js b/scouting/cypress_runner.js
new file mode 100644
index 0000000..6c63adb
--- /dev/null
+++ b/scouting/cypress_runner.js
@@ -0,0 +1,86 @@
+const child_process = require('child_process');
+const process = require('process');
+
+const cypress = require('cypress');
+
+// Set up the xvfb binary.
+process.env[
+ 'PATH'
+] = `${process.env.RUNFILES_DIR}/xvfb_amd64/wrapped_bin:${process.env.PATH}`;
+
+// Start the web server, database, and fake TBA server.
+// We use file descriptor 3 ('pipe') for the test server to let us know when
+// everything has started up.
+console.log('Starting server.');
+let servers = child_process.spawn(
+ 'testing/scouting_test_servers',
+ ['--port=8000', '--notify_fd=3'],
+ {
+ stdio: ['inherit', 'inherit', 'inherit', 'pipe'],
+ }
+);
+
+// Wait for the server to finish starting up.
+const serverStartup = new Promise((resolve, reject) => {
+ let cumulativeData = '';
+ servers.stdio[3].on('data', async (data) => {
+ console.log('Got data: ' + data);
+ cumulativeData += data;
+ if (cumulativeData.includes('READY')) {
+ console.log('Everything is ready!');
+ resolve();
+ }
+ });
+
+ servers.on('error', (err) => {
+ console.log(`Failed to start scouting_test_servers: ${err}`);
+ reject();
+ });
+
+ servers.on('close', (code, signal) => {
+ console.log(`scouting_test_servers closed: ${code} (${signal})`);
+ reject();
+ });
+
+ servers.on('exit', (code, signal) => {
+ console.log(`scouting_test_servers exited: ${code} (${signal})`);
+ reject();
+ });
+});
+
+// Wait for the server to shut down.
+const serverShutdown = new Promise((resolve) => {
+ servers.on('exit', () => {
+ resolve();
+ });
+});
+
+// Wait for the server to be ready, run the tests, then shut down the server.
+(async () => {
+ await serverStartup;
+ const result = await cypress.run({
+ headless: true,
+ config: {
+ baseUrl: 'http://localhost:8000',
+ screenshotsFolder:
+ process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/screenshots',
+ video: false,
+ videosFolder: process.env.TEST_UNDECLARED_OUTPUTS_DIR + '/videos',
+ },
+ });
+ await servers.kill();
+ await serverShutdown;
+
+ exitCode = 0;
+ if (result.status == 'failed') {
+ exitCode = 1;
+ console.log('-'.repeat(50));
+ console.log('Test FAILED: ' + result.message);
+ console.log('-'.repeat(50));
+ } else if (result.totalFailed > 0) {
+ // When the "before" hook fails, we don't get a "failed" mesage for some
+ // reason. In that case, we just have to exit with an error.
+ exitCode = 1;
+ }
+ process.exit(exitCode);
+})();