Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Playwright
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
37 changes: 37 additions & 0 deletions assets/e2e/register.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { test, expect } from "@playwright/test";

const testSuites = Number.parseInt(process.env.T);
const iterationsWithinTest = 10;

Array.from({ length: testSuites }).map((_, i) => {
test(`register ${i}`, async ({ page }) => {
for (let i = 0; i < iterationsWithinTest; i++) {
const email = `f${Math.random()}@ftes.de`;

await page.goto("http://localhost:4000/");
await page.getByRole("link", { name: "Register" }).click();
await expect(page.locator(".phx-connected")).toBeVisible();
await page.getByLabel("Email").fill(email);
await page.getByRole("button", { name: "Create an account" }).click();
await expect(
page.locator("#flash-info").getByText("email was sent"),
).toBeVisible();
await page.goto("http://localhost:4000/dev/mailbox");
await page
.getByRole("link", { name: `Confirmation instructions ${email}` })
.click();
await page.getByRole("link", { name: "log-in" }).click();
await expect(page.locator(".phx-connected")).toBeVisible();
await page
.getByRole("button", { name: "Confirm and stay logged in" })
.click();
await expect(
page.locator("#flash-info").getByText("User confirmed"),
).toBeVisible();
await page.goto("http://localhost:4000/users/settings");
await expect(page.locator(".phx-connected")).toBeVisible();
await page.getByRole("heading", { name: "Settings" }).click();
await page.getByRole("link", { name: "Log out" }).click();
}
});
});
51 changes: 44 additions & 7 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion assets/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"dependencies": {
"playwright": "^1.55.0"
}
},
"devDependencies": {
"@playwright/test": "^1.56.1",
"@types/node": "^24.9.1"
},
"scripts": {}
}
79 changes: 79 additions & 0 deletions assets/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./e2e",
/* 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: "html",
/* 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",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://localhost:3000',
// reuseExistingServer: !process.env.CI,
// },
});
9 changes: 8 additions & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import Config
# which you should run after static files are built and
# before starting your production server.
config :my_app, MyAppWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
config :my_app, dev_routes: true

config :my_app, MyApp.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "my_app_dev"

# Configures Swoosh API Client
config :swoosh, api_client: Swoosh.ApiClient.Req

# Disable Swoosh Local Memory Storage
config :swoosh, local: false
# config :swoosh, local: false

# Do not print debug messages in production
config :logger, level: :info
Expand Down
12 changes: 2 additions & 10 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,10 @@ if System.get_env("PHX_SERVER") do
end

if config_env() == :prod do
database_url =
System.get_env("DATABASE_URL") ||
raise """
environment variable DATABASE_URL is missing.
For example: ecto://USER:PASS@HOST/DATABASE
"""

maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []

config :my_app, MyApp.Repo,
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
# For machines with several cores, consider starting multiple pools of `pool_size`
# pool_count: 4,
Expand All @@ -50,13 +42,13 @@ if config_env() == :prod do
You can generate one by calling: mix phx.gen.secret
"""

host = System.get_env("PHX_HOST") || "example.com"
# host = System.get_env("PHX_HOST") || "example.com"
port = String.to_integer(System.get_env("PORT") || "4000")

config :my_app, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")

config :my_app, MyAppWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
# url: [host: host, port: 443, scheme: "https"],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
Expand Down
8 changes: 5 additions & 3 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ config :my_app, MyApp.Repo,
config :my_app, MyAppWeb.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 4002],
secret_key_base: "jsn/1/91hihxhFlb/ynE1r2Y3uIk1LZhSMyYJghMaBFowokOQOWU0taPLmaOOxSR",
server: true
server: false

# In test we don't send emails
# config :my_app, MyApp.Mailer, adapter: Swoosh.Adapters.Local
Expand All @@ -40,7 +40,7 @@ config :phoenix_live_view,
enable_expensive_runtime_checks: true

config :my_app,
sql_sandbox: true,
sql_sandbox: false,
dev_routes: true

config :phoenix_test,
Expand All @@ -49,5 +49,7 @@ config :phoenix_test,
playwright: [
# trace failed tests in CI via re-run
trace: System.get_env("PLAYWRIGHT_TRACE", "false") in ~w(t true),
trace_dir: "tmp"
trace_dir: "tmp",
timeout: 10_000,
browser_pool_size: String.to_integer(System.get_env("CONCURRENCY"))
]
2 changes: 1 addition & 1 deletion lib/my_app/accounts/user_notifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule MyApp.Accounts.UserNotifier do
end

defp deliver_confirmation_instructions(user, url) do
deliver(user.email, "Confirmation instructions", """
deliver(user.email, "Confirmation instructions #{user.email}", """

==============================

Expand Down
8 changes: 6 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ defmodule MyApp.MixProject do
{:dns_cluster, "~> 0.2.0"},
{:bandit, "~> 1.5"},
{:phoenix_test, "~> 0.7", only: :test, runtime: false},
{:phoenix_test_playwright, "~> 0.7", only: :test, runtime: false}
{:phoenix_test_playwright,
github: "ftes/phoenix_test_playwright",
ref: "feature/browser-pool",
only: :test,
runtime: false}
]
end

Expand All @@ -82,7 +86,7 @@ defmodule MyApp.MixProject do
[
setup: ["deps.get", "ecto.setup", "assets.setup", "assets.build"],
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
"ecto.reset": ["ecto.drop --force", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
"assets.setup": [
"tailwind.install --if-missing",
Expand Down
Loading
Loading