Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start converting tests to Playwright #307

Merged
merged 22 commits into from Nov 30, 2022
Merged

Start converting tests to Playwright #307

merged 22 commits into from Nov 30, 2022

Conversation

darabos
Copy link
Contributor

@darabos darabos commented Nov 21, 2022

First step for #238. Includes a conversion of web/test/tests/splash-page-test.js.

I haven't updated the docs yet. You can see the CI setup in the Earthfile. For local development you install Playwright the same way. Then you run LynxKite with run.sh and run the tests with yarn playwright test. There's a nice debug utility you can start with yarn playwright debug. If you hit an issue that you can't reproduce with debug, you can run the tests with yarn playwright test --trace on. This will save a trace that you can replay to see what happened.

I want to set up the trace on GitHub Actions too. The trace will have to be saved as an Earthly local artifact, then saved as a GitHub Actions artifact. This will be fantastic to track down any flaky tests. Or maybe we just won't have flaky tests at all!

@darabos darabos requested a review from lacca0 November 21, 2022 15:41
@@ -0,0 +1,1596 @@
import { expect, Locator, Page } from '@playwright/test';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is a garbage dump at the moment. It started as a copy of web/test/test-lib.js, then I converted the parts that I used to Playwright.

I think in many places this library is overdoing it. Is expectDirectoryNotListed(name) any clearer than expect(page.splash.directory(name)).not.toBeVisible()?

My approach would be to convert the tests fairly faithfully in the first round. Then we can have another pass to clean up a bit.

return page;
}

test.describe.configure({ mode: 'serial' });
Copy link
Contributor Author

@darabos darabos Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Protractor tests have an intricate test framework implemented in web/test/declarative.js. Instead of a simple independent/serial execution this allows a tree of tests, where some tests preserve the state and some tests change it.

This is made possible by the discardAllReallyIMeanIt endpoint, which resets LynxKite completely and provides a safe starting state. I'm not fond of this, because I often have some nice workspaces for testing stuff I'm working on, and then the tests blow it away.

My hope is that we can ditch all this. We can get to a known state by (re)creating a directory for the tests. We can write each test file to be runnable on its own. They can still share code: another test could import newSplash() from this file and just call it. We don't need to build a framework for this.

If we put the test stuff for each test file into a separate LynxKite directory, perhaps we could one day run those in parallel. But it's fine not to worry about this for now.

Base automatically changed from darabos-html-tests-docs to main November 24, 2022 13:41
@darabos
Copy link
Contributor Author

darabos commented Nov 24, 2022

On my laptop when I run all the tests, something goes wrong when "SQL runs nice on belongs to reached from project and segmentation" tries to add the "Create vertices" box. It clicks on it but the popup doesn't come up. I think this may be an actual LynxKite bug.

A difference between Protractor and Playwright is that Protractor waited for network requests to finish before taking the next action. Playwright doesn't care. So it may be clicking the box before the getOrSetWorkspace call has finished. Which is fine! A user wouldn't wait either! And I have actually experienced clicking boxes and not getting popups. Fixing things for Playwright also fixes things for users.

@darabos
Copy link
Contributor Author

darabos commented Nov 24, 2022

It passed on GitHub Actions. I guess let's merge it! (After review.) Then we can start converting more tests and fixing things as we go.

await tableBrowser.expectNode([3, 1], 'age (Double)', '`age`');
});

/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are commented-out in the original. But let's fix what we can and delete what we no longer need during this migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are commented-out in the original. But let's fix what we can and delete what we no longer need during this migration.

I've reviewed them. Nothing worth fixing I think. I've deleted them all.

Copy link
Contributor Author

@darabos darabos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've managed to track down some reliability issues. Looks rock solid for me now!

await tableBrowser.expectNode([3, 1], 'age (Double)', '`age`');
});

/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are commented-out in the original. But let's fix what we can and delete what we no longer need during this migration.

I've reviewed them. Nothing worth fixing I think. I've deleted them all.

{ logicalX: boxData.x, logicalY: boxData.y },
{ boxId: boxData.id });
}, boxData);
// Wait for the backend to save this box.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could make it so that it's okay to click a box before it's saved. I've filed #308.

@darabos darabos force-pushed the darabos-playwright branch 2 times, most recently from 00c6004 to a0d1d99 Compare November 25, 2022 17:02
@@ -33,13 +34,14 @@ jobs:
fi
git checkout -b "$branch" || true
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.6.26/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.6.30/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we use /earthly/releases/latest/...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we use /earthly/releases/latest/...?

With a fixed version the behavior is more predictable. With /latest there would always be a chance that something broke because of a new Earthly release.

(I'm in favor of a lockfile for the Conda dependencies too, for the same reason.)

But maybe we can switch to /latest when Earthly becomes stable enough, e.g. 1.0.

@@ -1,4 +1,4 @@
VERSION --use-copy-include-patterns 0.6
VERSION --use-copy-include-patterns --try 0.6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot find this option at docs.earthly.dev. What does it do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot find this option at docs.earthly.dev. What does it do?

Yeah, it's pretty new. See earthly/earthly#587 (comment).

Unfortunately it only works for files under 64 kB at the moment. (earthly/earthly#2452) We will only start getting test reports when a new Earthly is released with the fix.

@@ -25,24 +25,24 @@ sbt-deps:

npm-deps:
COPY web/package.json web/yarn.lock web/
RUN cd web; yarn --frozen-lockfile
RUN cd web && yarn --frozen-lockfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

For cd it doesn't make much difference. But I used ; instead of && at some other step and ended up ignoring a failure as a result. I took revenge on all semicolons.

KITE_DEPLOYMENT_CONFIG_DIR=$(realpath "${KITE_DEPLOYMENT_CONFIG_DIR}")
export HTTP_PORT=$[ 9100 + RANDOM % 100 ]
export HTTPS_PORT=$[ 9200 + RANDOM % 100 ]
export KITE_HTTP_PORT=$[ 9100 + RANDOM % 100 ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we need to make these ports random at the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we need to make these ports random at the first place?

I think it's to make it more convenient for local testing. You usually run a LynxKite on port 2200 that you're working with. You can use that for testing. This script is for starting a different, brand new LynxKite just for the test.

For testing in Earthly it doesn't matter. A fixed port would be fine.

Copy link
Contributor

@lacca0 lacca0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@darabos
Copy link
Contributor Author

darabos commented Nov 30, 2022

I was considering whether to merge this before the release. I think it's fine. The enqueue fix is a small change. Playwright likes it. It looks okay in manual testing. I've run the Protractor tests and they pass too.

@darabos darabos merged commit 51aadc3 into main Nov 30, 2022
@darabos darabos deleted the darabos-playwright branch November 30, 2022 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants