Skip to content
Merged
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
1 change: 1 addition & 0 deletions e2e/solid-start/basic-auth/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ yarn.lock
/playwright-report/
/blob-report/
/playwright/.cache/
.tmp/
Binary file modified e2e/solid-start/basic-auth/dev.db
Binary file not shown.
7 changes: 4 additions & 3 deletions e2e/solid-start/basic-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"scripts": {
"dev": "vite dev --port 3000",
"dev:e2e": "vite dev",
"build": "vite build",
"build": "vite build && tsc --noEmit",
"preview": "vite preview",
"start": "node .output/server/index.mjs",
"start": "pnpx srvx --prod -s ../client dist/server/server.js",
"prisma-generate": "prisma generate",
"test:e2e": "exit 0; rm -rf port*.txt; pnpm run prisma-generate && playwright test --project=chromium"
"test:e2e": "rm -rf port*.txt; mkdir -p .tmp; rm -f .tmp/dev.db .tmp/dev.db-journal .tmp/dev.db-wal .tmp/dev.db-shm; export DATABASE_URL=file:./.tmp/dev.db; pnpm run prisma-generate && pnpm exec prisma migrate deploy && playwright test --project=chromium"
},
"dependencies": {
"@libsql/client": "^0.15.15",
Expand All @@ -32,6 +32,7 @@
"dotenv": "^17.2.3",
"postcss": "^8.5.1",
"prisma": "^7.0.0",
"srvx": "^0.9.8",
"tailwindcss": "^4.1.17",
"typescript": "^5.7.2",
"vite-plugin-solid": "^2.11.10",
Expand Down
8 changes: 7 additions & 1 deletion e2e/solid-start/basic-auth/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import { defineConfig, devices } from '@playwright/test'
import { getTestServerPort } from '@tanstack/router-e2e-utils'
import packageJson from './package.json' with { type: 'json' }

// Ensure port file is written next to this config, even if Playwright loads it
// from a different working directory.
process.chdir(path.dirname(fileURLToPath(import.meta.url)))

const PORT = await getTestServerPort(packageJson.name)
const baseURL = `http://localhost:${PORT}`
/**
Expand All @@ -19,7 +25,7 @@ export default defineConfig({
},

webServer: {
command: `VITE_SERVER_PORT=${PORT} pnpm build && PORT=${PORT} VITE_SERVER_PORT=${PORT} pnpm start`,
command: `pnpm build && VITE_SERVER_PORT=${PORT} PORT=${PORT} pnpm start`,
url: baseURL,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
Expand Down
4 changes: 2 additions & 2 deletions e2e/solid-start/basic-auth/src/components/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function Auth({
actionText: string
onSubmit: (e: HTMLFormElement) => void
status: 'pending' | 'idle' | 'success' | 'error'
afterSubmit?: JSX.Element
afterSubmit?: () => JSX.Element
}) {
return (
<div class="fixed inset-0 bg-white dark:bg-black flex items-start justify-center p-8">
Expand Down Expand Up @@ -51,7 +51,7 @@ export function Auth({
>
{status === 'pending' ? '...' : actionText}
</button>
{afterSubmit ? afterSubmit : null}
{afterSubmit ? afterSubmit() : null}
</form>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions e2e/solid-start/basic-auth/src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { signupFn } from '~/routes/signup'

export function Login() {
const router = useRouter()
const login = useServerFn(loginFn)

const loginMutation = useMutation({
fn: loginFn,
fn: login,
onSuccess: async (ctx) => {
if (!ctx.data?.error) {
await router.invalidate()
Expand Down Expand Up @@ -37,7 +38,7 @@ export function Login() {
},
})
}}
afterSubmit={
afterSubmit={() =>
loginMutation.data() ? (
<>
<div class="text-red-400">{loginMutation.data()?.message}</div>
Expand Down
2 changes: 1 addition & 1 deletion e2e/solid-start/basic-auth/src/routes/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function SignupComp() {
},
})
}}
afterSubmit={
afterSubmit={() =>
signupMutation.data()?.error ? (
<>
<div class="text-red-400">{signupMutation.data()?.message}</div>
Expand Down
2 changes: 1 addition & 1 deletion e2e/solid-start/basic-auth/src/utils/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PrismaLibSql } from '@prisma/adapter-libsql'
import { PrismaClient } from '../prisma-generated/client'

const adapter = new PrismaLibSql({
url: process.env.DATABASE_URL || 'file:./prisma/dev.db',
url: process.env.DATABASE_URL || 'file:./dev.db',
})
export const prismaClient = new PrismaClient({ adapter })

Expand Down
2 changes: 1 addition & 1 deletion e2e/solid-start/basic-auth/src/utils/session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// src/services/session.server.ts
import { useSession } from '@tanstack/solid-start/server'
import type { User } from '@prisma/client'
import type { User } from '~/prisma-generated/client'

type SessionUser = {
userEmail: User['email']
Expand Down
37 changes: 22 additions & 15 deletions e2e/solid-start/basic-auth/tests/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { expect, test } from '@playwright/test'
import type { Page } from '@playwright/test'

async function signup(
page: Page,
baseUrl: string,
email: string,
password: string,
) {
await page.goto(baseUrl + '/signup')
async function waitForHydration(page: Page) {
await page.waitForFunction(() => typeof (window as any).$_TSR === 'undefined')
}

async function signup(page: Page, email: string, password: string) {
await page.goto('/signup')
await waitForHydration(page)
await page.fill('input[name="email"]', email)
await page.fill('input[name="password"]', password)
await page.click('button[type="submit"]')
await page.waitForSelector('text=Logout')
}

async function login(
Expand All @@ -20,6 +21,7 @@ async function login(
signupOnFail = false,
) {
await page.goto('/login')
await waitForHydration(page)
await page.fill('input[name="email"]', email)
await page.fill('input[name="password"]', password)
await page.click('button[type="submit"]')
Expand All @@ -37,23 +39,28 @@ test('Posts redirects to login when not authenticated', async ({ page }) => {
})

test('Login fails with user not found', async ({ page }) => {
await login(page, 'bad@gmail.com', 'badpassword')
expect(page.getByText('User not found')).toBeTruthy()
const email = `missing-${Date.now()}@gmail.com`
await login(page, email, 'badpassword')
await expect(page.getByText('User not found')).toBeVisible()
})

test('Login fails with incorrect password', async ({ page }) => {
await signup(page, 'test@gmail.com', 'badpassword')
expect(page.getByText('Incorrect password')).toBeTruthy()
const email = `incorrect-password-${Date.now()}@gmail.com`
await signup(page, email, 'test')
await page.goto('/logout')
await login(page, email, 'badpassword')
await expect(page.getByText('Incorrect password')).toBeVisible()
})

test('Can sign up from a not found user', async ({ page }) => {
await login(page, 'test2@gmail.com', 'badpassword', true)
expect(page.getByText('test@gmail.com')).toBeTruthy()
const email = `new-${Date.now()}@gmail.com`
await login(page, email, 'badpassword', true)
await expect(page.getByText(email)).toBeVisible()
})

test('Navigating to post after logging in', async ({ page }) => {
await login(page, 'test@gmail.com', 'test')
await new Promise((r) => setTimeout(r, 1000))
const email = `posts-${Date.now()}@gmail.com`
await signup(page, email, 'test')
await page.getByRole('link', { name: 'Posts' }).click()
await page.getByRole('link', { name: 'sunt aut facere repe' }).click()
await expect(page.getByRole('heading')).toContainText('sunt aut facere')
Expand Down
27 changes: 11 additions & 16 deletions e2e/solid-start/basic-auth/tests/mock-db-setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { test as setup } from '@playwright/test'

import { PrismaClient } from '@prisma/client'

const prismaClient = new PrismaClient()
import { hashPassword, prismaClient } from '../src/utils/prisma'

setup('create new database', async () => {
if (
await prismaClient.user.findUnique({
where: {
email: 'test2@gmail.com',
},
})
) {
await prismaClient.user.delete({
where: {
email: 'test2@gmail.com',
},
})
}
await prismaClient.user.deleteMany()

const email = 'test@gmail.com'
const password = await hashPassword('test')
await prismaClient.user.create({
data: {
email,
password,
},
})
})
27 changes: 11 additions & 16 deletions e2e/solid-start/basic-auth/tests/mock-db-teardown.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { test as teardown } from '@playwright/test'

import { PrismaClient } from '@prisma/client'

const prismaClient = new PrismaClient()
import { hashPassword, prismaClient } from '../src/utils/prisma'

teardown('create new database', async () => {
if (
await prismaClient.user.findUnique({
where: {
email: 'test2@gmail.com',
},
})
) {
await prismaClient.user.delete({
where: {
email: 'test2@gmail.com',
},
})
}
await prismaClient.user.deleteMany()

const email = 'test@gmail.com'
const password = await hashPassword('test')
await prismaClient.user.create({
data: {
email,
password,
},
})
})
Comment on lines 5 to 16
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Test description is misleading.

The teardown test is named "create new database" but it's performing cleanup operations. While the logic (deleting all users and recreating the test user) may be intentional to reset to a known state, the test name should reflect its teardown purpose more accurately.

🔎 Consider renaming the test:
-teardown('create new database', async () => {
+teardown('reset database to initial state', async () => {
  await prismaClient.user.deleteMany()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
teardown('create new database', async () => {
if (
await prismaClient.user.findUnique({
where: {
email: 'test2@gmail.com',
},
})
) {
await prismaClient.user.delete({
where: {
email: 'test2@gmail.com',
},
})
}
await prismaClient.user.deleteMany()
const email = 'test@gmail.com'
const password = await hashPassword('test')
await prismaClient.user.create({
data: {
email,
password,
},
})
})
teardown('reset database to initial state', async () => {
await prismaClient.user.deleteMany()
const email = 'test@gmail.com'
const password = await hashPassword('test')
await prismaClient.user.create({
data: {
email,
password,
},
})
})
🤖 Prompt for AI Agents
In e2e/solid-start/basic-auth/tests/mock-db-teardown.test.ts around lines 5 to
16, the test title "create new database" is misleading because the block
performs teardown/cleanup (deleting users and recreating a test user); rename
the test to reflect its teardown purpose (for example "reset test database" or
"teardown: reset users to known state") so the name matches the actions, and
update any related comments or test suite descriptions accordingly.

7 changes: 7 additions & 0 deletions e2e/vue-start/basic-auth/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="file:./dev.db"
21 changes: 21 additions & 0 deletions e2e/vue-start/basic-auth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
node_modules
package-lock.json
yarn.lock

!.env
.DS_Store
.cache
.vercel
.output

/build/
/api/
/server/build
/public/build
# Sentry Config File
.env.sentry-build-plugin
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
.tmp/
4 changes: 4 additions & 0 deletions e2e/vue-start/basic-auth/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/build
**/public
pnpm-lock.yaml
routeTree.gen.ts
Binary file added e2e/vue-start/basic-auth/dev.db
Binary file not shown.
42 changes: 42 additions & 0 deletions e2e/vue-start/basic-auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "tanstack-vue-start-e2e-basic-auth",
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"dev": "vite dev --port 3000",
"dev:e2e": "vite dev",
"build": "vite build && tsc --noEmit",
"preview": "vite preview",
"start": "pnpx srvx --prod -s ../client dist/server/server.js",
"prisma-generate": "prisma generate",
"test:e2e": "rm -rf port*.txt; mkdir -p .tmp; rm -f .tmp/dev.db .tmp/dev.db-journal .tmp/dev.db-wal .tmp/dev.db-shm; export DATABASE_URL=file:./.tmp/dev.db; pnpm run prisma-generate && pnpm exec prisma migrate deploy && playwright test --project=chromium"
},
"dependencies": {
"@libsql/client": "^0.15.15",
"@prisma/adapter-libsql": "^7.0.0",
"@prisma/client": "^7.0.0",
"@tanstack/vue-router": "workspace:^",
"@tanstack/vue-router-devtools": "workspace:^",
"@tanstack/vue-start": "workspace:^",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "^7.1.7",
"vue": "^3.5.25"
},
"devDependencies": {
"@playwright/test": "^1.50.1",
"@tailwindcss/postcss": "^4.1.15",
"@tanstack/router-e2e-utils": "workspace:^",
"@types/node": "^22.10.2",
"dotenv": "^17.2.3",
"postcss": "^8.5.1",
"prisma": "^7.0.0",
"srvx": "^0.9.8",
"tailwindcss": "^4.1.17",
"typescript": "^5.7.2",
"@vitejs/plugin-vue": "^6.0.3",
"@vitejs/plugin-vue-jsx": "^5.1.2",
"vite-tsconfig-paths": "^5.1.4"
}
}
34 changes: 34 additions & 0 deletions e2e/vue-start/basic-auth/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { defineConfig, devices } from '@playwright/test'
import { getTestServerPort } from '@tanstack/router-e2e-utils'
import packageJson from './package.json' with { type: 'json' }

const PORT = await getTestServerPort(packageJson.name)
const baseURL = `http://localhost:${PORT}`
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
workers: 1,

reporter: [['line']],

use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL,
},

webServer: {
command: `VITE_SERVER_PORT=${PORT} pnpm build && PORT=${PORT} VITE_SERVER_PORT=${PORT} pnpm start`,
url: baseURL,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
},

projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
})
5 changes: 5 additions & 0 deletions e2e/vue-start/basic-auth/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
12 changes: 12 additions & 0 deletions e2e/vue-start/basic-auth/prisma.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config'

export default defineConfig({
schema: './prisma/schema.prisma',
migrations: {
path: './prisma/migrations',
},
datasource: {
url: env('DATABASE_URL'),
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- CreateTable
CREATE TABLE "User" (
"email" TEXT NOT NULL PRIMARY KEY,
"password" TEXT NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
Loading
Loading