Skip to content

Adds headless tests for example apps #2478

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

Merged
merged 7 commits into from
May 22, 2025
Merged

Conversation

infomiho
Copy link
Contributor

@infomiho infomiho commented Jan 31, 2025

  • Adds headless tests for
    • examples/waspello
    • examples/waspleau
    • examples/websockets-realtime-voting
    • examples/tutorials/TodoApp
    • examples/tutorials/TodoAppTs

@infomiho infomiho force-pushed the miho-merge-todo-apps branch from e1ee1c0 to 4a9c181 Compare March 5, 2025 11:51
@infomiho infomiho changed the base branch from miho-merge-todo-apps to miho-wasp-app-runner March 5, 2025 12:07
@infomiho infomiho force-pushed the miho-example-apps-headless-tests branch from 3ea3f9d to 494a31d Compare March 5, 2025 12:57
@Martinsos
Copy link
Member

What are next steps here?

Copy link
Contributor

@sodic sodic left a comment

Choose a reason for hiding this comment

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

Excellent work!

But I can't decide whether we should remove most of the tests. They're pretty repetitive and unlikely to fail if waspc/todoApp works. Then again, we run them manually every time...

Another big repetition is the playwright config, so we should decide whether to do something about that too.

# Headless tests
!.env.*.headless
test-results/
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I may have changed my mind on this grouping 😅

It makes sense to kepp all the headless stuff together. But netlify should definitely be pushed up.

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 app is now gone, but the headless ignore patterns are grouped together in all other apps as well 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this app is supposed to test streaming, can we somehow write the test to check for that (not just the final content)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've migrated streaming to todoApp with a test that you mention, you'd be pleased 👍

await page.locator("button").click();
}

export async function performLogin(
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably skip on testing the signup and the login in all apps. It's a lot of repetitive code that brings little benefit I'd say.

However, if and where we test for it (e.g., in waspc/todoApp), we should also test for unsuccessful logins and signups.

Copy link
Member

Choose a reason for hiding this comment

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

Jumping in a bit, but I see this is in helper.ts and I guess login is just needed to test the rest of the app, so probably no point in trying to do less of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, testing login and signup is something we do along the way because we need to authenticate anyways to test the apps.

Comment on lines 42 to 54
// Fill input[name="description"] with random task
await page.locator("input[name='description']").fill(randomTask);
// Click input[type="submit"] to submit the form
await page.locator("input[type='submit']").click();
// Expect to see the task on the page
await expect(page.locator("body")).toContainText(randomTask);
// Check the task as done input[type="checkbox"]
await page.locator("input[type='checkbox']").click();
// Reload the page
await page.reload();
// Expect the task to be checked
await expect(page.locator("input[type='checkbox']")).toBeChecked();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The comments are probably gpt leftovers, we can remove them :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, probably me telling Copilot what to write (or I generated this with Playwright's extension, not sure).

@infomiho infomiho force-pushed the miho-wasp-app-runner branch from 119a4b4 to f7cb11b Compare April 4, 2025 14:49
Base automatically changed from miho-wasp-app-runner to main April 9, 2025 10:12
@infomiho infomiho force-pushed the miho-example-apps-headless-tests branch from f0e42a0 to a8ea42c Compare April 9, 2025 10:32
@@ -8,16 +8,16 @@ import addWaspSourceHeader from '../common/addWaspSourceHeader'

import mainLogo from '../common/waspello-logo.svg'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move to Typescript to cleanup a bit, there was a type error hiding in the Signup page, so I wanted to convert the Login as well.

@@ -7,18 +7,16 @@ import addWaspSourceHeader from '../common/addWaspSourceHeader'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a type error (which I didn't notice) when using this code with the latest released Wasp, but this code works with main Wasp CLI. Cleaned up and converted to Typescript just in case.

@@ -11,38 +11,18 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Migrated to latest tsconfig.json

@infomiho infomiho requested a review from sodic May 19, 2025 13:24
@@ -1,13 +1,21 @@
import { type ServerToClientPayload, useSocket, useSocketListener } from "wasp/client/webSocket";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of this file is formatting, but I added some classes for easier headless testing

Copy link
Contributor

@sodic sodic left a comment

Choose a reason for hiding this comment

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

Went through it again.

Everything looks ok functionally, but I'm still uneasy about the duplication:

  • playwright.config.ts files seem to be identical, at least we intend them to be. But they're already drifting apart through small unintended differences (e.g., quotes and variables, check screenshot below).
  • I believe the same applies for simple.spec.ts files.

Can we do anything about this? It doesn't need to be fancy. For example, we could symlink them all to the same file.

image

} catch (err) {
if (err.statusCode == 422) {
} catch (err: any) {
// TODO: Update this to check against WaspHttpError https://github.com/wasp-lang/wasp/issues/2767
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we mention this in the issue? We'll otherwise forget to update it.

} catch (err) {
if (err.statusCode == 422) {
} catch (err: any) {
// TODO: Update this to check against WaspHttpError https://github.com/wasp-lang/wasp/issues/2767
Copy link
Contributor

Choose a reason for hiding this comment

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

Also please mention it in the issue.

@infomiho
Copy link
Contributor Author

infomiho commented May 22, 2025

Everything looks ok functionally, but I'm still uneasy about the duplication:

I get you, I agree with you on the config duplication, but in the tests I wouldn't try to be fancy since most of the work is just replicating what users would do manually while testing the app. t might get quite messy if we try to abstract that away.

Can we do anything about this? It doesn't need to be fancy. For example, we could symlink them all to the same file.

I guess we are trying to solve the issue of sharing JS code between multiple different Wasp apps. I'm not sure symlinking is the best way to go (it feels OS specific to me, correct if I'm wrong). This is one argument for publishing the wasp-app-runner as an npm package which would enable use to centralise our common headless apps setup, but then I'd rename it into wasp-headless-tests-utils or smth like that, so it reflects it's wider scope.

Maybe we can locally install the wasp-app-runner package? But then it's not accessible to open-saas for example.

Copy link
Contributor

@sodic sodic left a comment

Choose a reason for hiding this comment

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

Talked out of band, we'll handle the duplication separately. @infomiho Please link the issue when you create it.

Good to go!

@infomiho
Copy link
Contributor Author

Great, thanks! I'll merge this then and here's the issue for deduplication effort: #2790

@infomiho infomiho merged commit abdd636 into main May 22, 2025
@infomiho infomiho deleted the miho-example-apps-headless-tests branch May 22, 2025 12:35
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.

3 participants