Skip to content

Add headless tests to starter templates #2868

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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

FranjoMindek
Copy link
Contributor

@FranjoMindek FranjoMindek commented Jul 1, 2025

Fixes: #2833

Since starter templates are not a valid Wasp project by themselves, we need to use Wasp CLI to generate the projects to test them out.

For that I created the waspc/starters-headless-tests/run-starter-headless-tests.sh script.
It:

  1. Creates a starter project from the template
  2. Runs the headless test in DEV mode
  3. If not using sqlite, runs the headless test in BUILD mode
  4. Cleans up the generated project

Note: we are only testing minimal and basic starters here. open-saas has it's own tests, and we are not testing AI generated apps.

@@ -0,0 +1,79 @@
#!/bin/bash

# Script to run E2E tests for a given Wasp template.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need a script because we need to generate projects from the starter templates.
Starter templates are not valid wasp projects:

  1. Missing files which are part of starters skeleton
  2. main.wasp has interpolation placeholder values for e.g. version, which is invalid wasp syntax

@@ -0,0 +1,6 @@
import { expect, test } from "@playwright/test";

test("health check", async ({ page }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Text the app runs successfully and works."

use: { ...devices["Desktop Chrome"] },
},
// {
// name: "firefox",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are only testing that the app works, mobile is not really needed.
Though it might be useful to try it with firefox and webkit since we did have a firefox only bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After we decide I will of course remove all the commented code.

Copy link

cloudflare-workers-and-pages bot commented Jul 1, 2025

Deploying wasp-docs-on-main with  Cloudflare Pages  Cloudflare Pages

Latest commit: 373f731
Status: ✅  Deploy successful!
Preview URL: https://b8b48221.wasp-docs-on-main.pages.dev
Branch Preview URL: https://franjo-starters-headless-tes.wasp-docs-on-main.pages.dev

View logs

Base automatically changed from franjo/starter-templates to main July 4, 2025 14:38
…ess-tests

# Conflicts:
#	waspc/cli/src/Wasp/Cli/Command/CreateNewProject/StarterTemplates.hs
#	waspc/data/Cli/starters/README.md
"main": "index.js",
"keywords": [],
"scripts": {
"test": "for starter in basic minimal; do ./run-starter-headless-tests.sh $starter wasp || exit 1; done",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way for this?

@infomiho infomiho self-requested a review July 11, 2025 13:37
@FranjoMindek FranjoMindek requested a review from sodic July 16, 2025 13:20
Copy link
Contributor

@infomiho infomiho left a comment

Choose a reason for hiding this comment

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

Left some suggestions

@@ -0,0 +1,70 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the script can run npm install before starting to ensure Playwright is installed.

We could run npx -y playwright test to avoid asking the user if they want to install the Playwright CLI.

DEBUG=pw:webserver E2E_APP_PATH="./${TEMP_PROJECT_NAME}" WASP_CLI_CMD="${WASP_CLI_CMD}" HEADLESS_TEST_MODE=build npx playwright test
}

template_uses_sqlite() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like the sqlite detection is kinda fragile, can we do better?

Do we want to upgrade from bash to Node.js and use zx here - we can reuse same logic for detecting SQlite from the Wasp App Runner: https://github.com/wasp-lang/wasp/blob/main/wasp-app-runner/src/waspCli.ts#L94

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to use zx regardless of reusing the SQLite detection logic, I feel like it's a quite common tool we use (Wasp App Runner, deploy package).

"test:dev": "for starter in basic minimal; do ./run-starter-headless-tests.sh $starter wasp-cli || exit 1; done"
},
"devDependencies": {
"@playwright/test": "^1.53.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest we pin the Playwright version so browsers can be reused (Playwright versions and browser version are tied together).

We use the same version across kitchen sink app and example apps, I believe it's "@playwright/test": "1.51.1"

@@ -0,0 +1,6 @@
import { expect, test } from "@playwright/test";

test("health check", async ({ page }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be much more comfortable with not testing starters manually we did something like added a new task with the basic template.

@@ -0,0 +1,70 @@
#!/bin/bash
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 test saas starter with this as well?

  1. There is an issue that the saas template has the app in the /app folder.
  2. Also the saas starter needs some .env vars set up to be able to run the app.
  3. We can't test the saas starter in production mode with email sender set as Dummy.

@@ -0,0 +1,70 @@
#!/bin/bash
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 be declarative around which tests we are doing, and define an object:

  • minimal / [sqlite] / use . as dir
  • basic / [sqlite] / use . as dir
  • saas / [postgres] / use app as dir

This way we don't bother with parsing the db type and we can declare stuff like app dir.

Also, do we see some value in testing all the starters with both database types?

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.

Create headless tests for starter templates
2 participants