-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ab1d91a
Add headless tests for example apps
infomiho a8ea42c
Fix hackathon-submisisons tests
infomiho af79320
Updated example apps package*.json files
infomiho 81f09f8
Merge branch 'main' into miho-example-apps-headless-tests
infomiho 9dc07b4
Update tests to work with latest changes
infomiho 5acf4e4
Cleanup
infomiho 7378cc1
Missing newline
infomiho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ node_modules/ | |
# Don't ignore example dotenv files. | ||
!.env.example | ||
!.env.*.example | ||
|
||
# Headless tests | ||
test-results/ |
55 changes: 55 additions & 0 deletions
55
examples/tutorials/TodoApp/headless-tests/playwright.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./tests", | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: process.env.CI ? "dot" : "list", | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: "http://localhost:3000", | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
}, | ||
|
||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
/* Test against mobile viewports. */ | ||
{ | ||
name: "Mobile Chrome", | ||
use: { ...devices["Pixel 5"] }, | ||
}, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: "run-wasp-app dev --path-to-app=../", | ||
|
||
// Wait for the backend to start | ||
url: "http://localhost:3001", | ||
reuseExistingServer: !process.env.CI, | ||
timeout: 180 * 1000, | ||
gracefulShutdown: { signal: "SIGTERM", timeout: 500 }, | ||
}, | ||
}); |
43 changes: 43 additions & 0 deletions
43
examples/tutorials/TodoApp/headless-tests/tests/helpers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Page } from "@playwright/test"; | ||
|
||
export async function performSignup( | ||
page: Page, | ||
{ username, password }: { username: string; password: string } | ||
) { | ||
await page.goto("/signup"); | ||
|
||
await page.waitForSelector("text=Create a new account"); | ||
|
||
await page.locator("input[name='username']").fill(username); | ||
await page.locator("input[type='password']").fill(password); | ||
await page.locator("button").click(); | ||
} | ||
|
||
export async function performLogin( | ||
page: Page, | ||
{ | ||
username, | ||
password, | ||
}: { | ||
username: string; | ||
password: string; | ||
} | ||
) { | ||
await page.goto("/login"); | ||
|
||
await page.waitForSelector("text=Log in to your account"); | ||
|
||
await page.locator("input[name='username']").fill(username); | ||
await page.locator("input[type='password']").fill(password); | ||
await page.getByRole("button", { name: "Log in" }).click(); | ||
} | ||
|
||
export function generateRandomCredentials(): { | ||
username: string; | ||
password: string; | ||
} { | ||
return { | ||
username: `test${Math.random().toString(36).substring(7)}`, | ||
password: "12345678", | ||
}; | ||
} |
49 changes: 49 additions & 0 deletions
49
examples/tutorials/TodoApp/headless-tests/tests/simple.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { | ||
generateRandomCredentials, | ||
performLogin, | ||
performSignup, | ||
} from "./helpers"; | ||
|
||
test.describe("auth and work tasks", () => { | ||
const { username, password } = generateRandomCredentials(); | ||
|
||
test.describe.configure({ mode: "serial" }); | ||
|
||
test("can sign up", async ({ page }) => { | ||
await performSignup(page, { | ||
username, | ||
password, | ||
}); | ||
|
||
await expect(page).toHaveURL("/"); | ||
|
||
await page.getByText("Logout").click(); | ||
|
||
await expect(page).toHaveURL("/login"); | ||
}); | ||
|
||
test("can log in and interact with tasks", async ({ page }) => { | ||
await performLogin(page, { | ||
username, | ||
password: "12345678xxx", | ||
}); | ||
|
||
await expect(page.locator("body")).toContainText("Invalid credentials"); | ||
|
||
await performLogin(page, { | ||
username, | ||
password, | ||
}); | ||
|
||
await expect(page).toHaveURL("/"); | ||
|
||
const randomTask = `New Task ${Math.random().toString(36).substring(7)}`; | ||
await page.locator("input[name='description']").fill(randomTask); | ||
await page.locator("input[type='submit']").click(); | ||
await expect(page.locator("body")).toContainText(randomTask); | ||
await page.locator("input[type='checkbox']").click(); | ||
await page.reload(); | ||
await expect(page.locator("input[type='checkbox']")).toBeChecked(); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ node_modules/ | |
# Don't ignore example dotenv files. | ||
!.env.example | ||
!.env.*.example | ||
|
||
# Headless tests | ||
test-results/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.