Skip to content

Commit 494a31d

Browse files
committed
Add headless tests for example apps
Signed-off-by: Mihovil Ilakovac <mihovil@ilakovac.com>
1 parent e970187 commit 494a31d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+8478
-3445
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HEADLESS_TESTING=true

examples/hackathon-submissions/.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ node_modules/
1111
!.env.*.example
1212

1313
# Local Netlify folder
14-
.netlify
14+
.netlify
15+
16+
# Headless tests
17+
!.env.*.headless
18+
test-results/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// require('dotenv').config();
8+
9+
/**
10+
* See https://playwright.dev/docs/test-configuration.
11+
*/
12+
export default defineConfig({
13+
testDir: "./tests",
14+
/* Run tests in files in parallel */
15+
fullyParallel: true,
16+
/* Fail the build on CI if you accidentally left test.only in the source code. */
17+
forbidOnly: !!process.env.CI,
18+
/* Retry on CI only */
19+
retries: process.env.CI ? 2 : 0,
20+
/* Opt out of parallel tests on CI. */
21+
workers: process.env.CI ? 1 : undefined,
22+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
23+
reporter: process.env.CI ? "dot" : "list",
24+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
25+
use: {
26+
/* Base URL to use in actions like `await page.goto('/')`. */
27+
baseURL: "http://localhost:3000",
28+
29+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30+
trace: "on-first-retry",
31+
},
32+
33+
projects: [
34+
{
35+
name: "chromium",
36+
use: { ...devices["Desktop Chrome"] },
37+
},
38+
/* Test against mobile viewports. */
39+
{
40+
name: "Mobile Chrome",
41+
use: { ...devices["Pixel 5"] },
42+
},
43+
],
44+
45+
/* Run your local dev server before starting the tests */
46+
webServer: {
47+
command:
48+
"wasp-app-runner --app-path=../ --app-name=examples-hackathon-submissions",
49+
50+
// Wait for the backend to start
51+
url: "http://localhost:3001",
52+
reuseExistingServer: !process.env.CI,
53+
timeout: 180 * 1000,
54+
gracefulShutdown: { signal: "SIGTERM", timeout: 500 },
55+
},
56+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("create a new hackathon submission", async ({ page }) => {
4+
await page.goto("/");
5+
await page
6+
.getByRole("textbox", { name: "Project Name *" })
7+
.fill("New project");
8+
await page
9+
.getByRole("textbox", { name: "Email address *" })
10+
.fill("test@test.com");
11+
await page
12+
.getByRole("textbox", { name: "Countries Represented" })
13+
.fill("USA");
14+
await page
15+
.getByRole("textbox", { name: "Countries Represented" })
16+
.press("Tab");
17+
await page
18+
.getByRole("textbox", { name: "GitHub Repo *" })
19+
.fill("github.com/something/something");
20+
await page.getByRole("textbox", { name: "Website" }).fill("something.com");
21+
await page
22+
.getByRole("textbox", { name: "Twitter" })
23+
.fill("twitter.com/something");
24+
await page
25+
.getByRole("textbox", { name: "Description *" })
26+
.fill("Some description");
27+
28+
await page.getByRole("button", { name: "Save" }).click();
29+
await expect(page.locator(".project")).toContainText("New project");
30+
await expect(page.locator(".project")).toContainText("Some description");
31+
});

examples/hackathon-submissions/package-lock.json

+56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/hackathon-submissions/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "hackathon-submissions",
33
"type": "module",
44
"dependencies": {
5+
"@playwright/test": "^1.50.0",
56
"react": "^18.2.0",
67
"react-dom": "^18.2.0",
78
"react-feather": "2.0.10",

examples/streaming/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ node_modules/
99
# Don't ignore example dotenv files.
1010
!.env.example
1111
!.env.*.example
12+
13+
# Headless tests
14+
test-results/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// require('dotenv').config();
8+
9+
/**
10+
* See https://playwright.dev/docs/test-configuration.
11+
*/
12+
export default defineConfig({
13+
testDir: "./tests",
14+
/* Run tests in files in parallel */
15+
fullyParallel: true,
16+
/* Fail the build on CI if you accidentally left test.only in the source code. */
17+
forbidOnly: !!process.env.CI,
18+
/* Retry on CI only */
19+
retries: process.env.CI ? 2 : 0,
20+
/* Opt out of parallel tests on CI. */
21+
workers: process.env.CI ? 1 : undefined,
22+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
23+
reporter: process.env.CI ? "dot" : "list",
24+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
25+
use: {
26+
/* Base URL to use in actions like `await page.goto('/')`. */
27+
baseURL: "http://localhost:3000",
28+
29+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30+
trace: "on-first-retry",
31+
},
32+
33+
projects: [
34+
{
35+
name: "chromium",
36+
use: { ...devices["Desktop Chrome"] },
37+
},
38+
/* Test against mobile viewports. */
39+
{
40+
name: "Mobile Chrome",
41+
use: { ...devices["Pixel 5"] },
42+
},
43+
],
44+
45+
/* Run your local dev server before starting the tests */
46+
webServer: {
47+
command:
48+
"wasp-app-runner --app-path=../ --app-name=examples-streaming --db-type sqlite",
49+
50+
// Wait for the backend to start
51+
url: "http://localhost:3001",
52+
reuseExistingServer: !process.env.CI,
53+
timeout: 180 * 1000,
54+
gracefulShutdown: { signal: "SIGTERM", timeout: 500 },
55+
},
56+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test.describe("loads successfully", () => {
4+
test.describe.configure({ mode: "serial" });
5+
6+
test("can see streamed content", async ({ page }) => {
7+
await page.goto("/");
8+
9+
const finalText = `Hm, let me see... let's talk about number 1 and let's talk about number 2 and let's talk about number 3 and let's talk about number 4 and let's talk about number 5 and let's talk about number 6 and let's talk about number 7 and let's talk about number 8 and let's talk about number 9 and and finally about 10.`;
10+
await expect(page.locator("p")).toHaveText(finalText);
11+
});
12+
});

0 commit comments

Comments
 (0)