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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ jobs:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm typecheck
- run: pnpm build
- run: pnpm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
.DS_Store
.env*
*.log
test-results
.claude
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Test data management for [Better Auth](https://www.better-auth.com/) and [Playwr

## Features

- **Direct DB user creation** — bypasses sign-up flow and password hashing for fast tests
- **Direct DB user creation** — bypasses sign-up flow for fast tests (password hashing only when needed)
- **Auto session cookies** — sets session cookies on the Playwright browser context automatically
- **Automatic cleanup** — all test users are deleted after each test
- **Plugin system** — extend user creation with additional resources (orgs, API keys, etc.)
Expand Down Expand Up @@ -60,7 +60,7 @@ Use the `auth` fixture to create users and get authenticated browser sessions:

```ts
// e2e/dashboard.spec.ts
import { test, expect } from './fixtures'
import { expect, test } from './fixtures'

test('user can see the dashboard', async ({ page, auth }) => {
const user = await auth.createUser()
Expand Down Expand Up @@ -92,7 +92,7 @@ Better Auth plugin that registers test data endpoints. Import from `better-auth-
| `DELETE` | `/api/auth/test-data/user` | Delete a test user by email. Runs plugin cleanup in reverse order. |
| `GET` | `/api/auth/test-data/capabilities` | List installed test data plugins and detected Better Auth plugins. |

All endpoints require the `X-Test-Secret` header and are marked `SERVER_ONLY` (not callable from the client SDK).
All endpoints require the `X-Test-Secret` header and use `isAction: false` (not callable from the client SDK).

#### `organizationTest(defaults?)`

Expand All @@ -114,8 +114,8 @@ Returns `{ id, name, slug }` or `null` if skipped.
```ts
// auth.ts (server)
import { betterAuth } from 'better-auth'
import { organizationTest, testPlugin } from 'better-auth-playwright/server'
import { organization } from 'better-auth/plugins'
import { testPlugin, organizationTest } from 'better-auth-playwright/server'

export const auth = betterAuth({
plugins: [
Expand All @@ -137,7 +137,6 @@ Creates a Playwright `test` object with an `auth` fixture. Import from `better-a
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `secret` | `string` | *required* | Secret that matches the server plugin's secret. |
| `cookieName` | `string` | `'better-auth.session_token'` | Session cookie name. |
| `basePath` | `string` | `'/api/auth'` | Base path for Better Auth endpoints. |
| `test` | `TestType` | `@playwright/test`'s `test` | Custom base test to extend (see [Custom Base Test](#custom-base-test)). |

Expand All @@ -161,7 +160,7 @@ interface TestUser {
id: string
email: string
name: string
session: { id: string; token: string }
session: { id: string, token: string }
plugins: Record<string, unknown>
}
```
Expand All @@ -175,7 +174,7 @@ Delete a test user by email. Called automatically after each test for all users
Create custom test data plugins to extend user creation for other Better Auth plugins:

```ts
import type { TestDataPlugin, CreateUserContext } from 'better-auth-playwright'
import type { CreateUserContext, TestDataPlugin } from 'better-auth-playwright'

interface MyPluginOptions {
someOption?: string
Expand Down Expand Up @@ -233,6 +232,10 @@ export const test = createTestFixtures({
export { expect } from 'better-auth-playwright'
```

## Credit

Built by the team behind [Gaffer](https://gaffer.sh) — test reporting and analytics for CI/CD.

## License

MIT
5 changes: 5 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import antfu from '@antfu/eslint-config'

export default antfu({
type: 'lib',
})
32 changes: 24 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,39 @@
"name": "better-auth-playwright",
"type": "module",
"version": "0.1.4",
"packageManager": "pnpm@10.18.1",
"description": "E2E testing plugin for Better Auth — fast user creation and automatic session cookies for Playwright",
"license": "MIT",
"author": "Gaffer <hello@gaffer.sh>",
"license": "MIT",
"homepage": "https://gaffer.sh",
"repository": {
"type": "git",
"url": "https://github.com/gaffer-sh/better-auth-playwright.git"
},
"sideEffects": false,
"exports": {
".": "./dist/index.js",
"./server": "./dist/server.js",
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"engines": {
"node": ">=18"
},
"packageManager": "pnpm@10.18.1",
"sideEffects": false,
"scripts": {
"build": "tsdown",
"dev": "tsdown --watch",
"lint": "eslint .",
"typecheck": "tsc --noEmit",
"prepare": "simple-git-hooks",
"prepublishOnly": "pnpm build",
"test": "vitest run",
"test:watch": "vitest",
"release": "bumpp --tag 'v%s' --commit 'chore: release v%s' && git push --follow-tags"
},
"peerDependencies": {
Expand All @@ -39,18 +50,23 @@
}
},
"devDependencies": {
"@antfu/eslint-config": "^7.2.0",
"@playwright/test": "^1.57.0",
"@types/node": "^22.0.0",
"better-auth": "^1.4.18",
"bumpp": "^10.1.0",
"eslint": "^9.39.2",
"lint-staged": "^16.2.7",
"simple-git-hooks": "^2.13.1",
"tsdown": "^0.15.0",
"typescript": "^5.9.3",
"vitest": "^4.0.18",
"zod": "^3.24.0"
},
"module": "./dist/index.js",
"exports": {
".": "./dist/index.js",
"./server": "./dist/server.js",
"./package.json": "./package.json"
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
Loading