Skip to content
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

test: initial test #18

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
CLERK_PUBLISHABLE_KEY=your_publishable_key
CLERK_SECRET_KEY=your_secret_key

E2E_CLERK_USER_USERNAME=
E2E_CLERK_USER_PASSWORD=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ logs
!.env.example

.vscode

test-results
34 changes: 34 additions & 0 deletions e2e/app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { setupClerkTestingToken } from '@clerk/testing/playwright'
import { test } from '@nuxt/test-utils/playwright'

test.describe('app', () => {
test('sign -in', async ({ page, goto }) => {
await setupClerkTestingToken({ page })

await goto('/', { waitUntil: 'hydration' })
// await expect(page.locator("h1")).toContainText("Sign In")
await page.goto('/dashboard')
await page.waitForSelector('.cl-signIn-root', { state: 'attached' })
await page.locator('input[name=identifier]').fill(process.env.E2E_CLERK_USER_USERNAME!)
await page.getByRole('button', { name: 'Continue', exact: true }).click()
await page.locator('input[name=password]').fill(process.env.E2E_CLERK_USER_PASSWORD!)
await page.getByRole('button', { name: 'Continue', exact: true }).click()
await page.waitForURL('**/dashboard')
})

test('sign up', async ({ page }) => {
await setupClerkTestingToken({ page })

await page.goto('/sign-up')
// await expect(page.locator("h1")).toContainText("Sign Up");
await page.waitForSelector('.cl-signUp-root', { state: 'attached' })
await page.locator('input[name=username]').fill(`user${Date.now()}`)
await page.locator('input[name=emailAddress]').fill(`user${Date.now()}[email protected]`)
await page.locator('input[name=password]').fill(`Pass!@${Date.now()}`)
await page.getByRole('button', { name: 'Continue', exact: true }).click()
await page.waitForSelector('.cl-signUp-emailCode', { state: 'attached' })
await page.locator('input[id=digit-0-field]').fill('424242')
await page.getByRole('button', { name: 'Continue', exact: true }).click()
await page.waitForURL('**/dashboard')
})
})
12 changes: 12 additions & 0 deletions e2e/global.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { clerkSetup } from '@clerk/testing/playwright'
import { test as setup } from '@playwright/test'

setup('global setup', async () => {
await clerkSetup()

if (!process.env.E2E_CLERK_USER_USERNAME || !process.env.E2E_CLERK_USER_PASSWORD) {
throw new Error(
'Please provide E2E_CLERK_USER_USERNAME and E2E_CLERK_USER_PASSWORD environment variables.',
)
}
})
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "nuxt-app",
"type": "module",
"private": true,
"scripts": {
"build": "nuxt build",
Expand All @@ -8,7 +9,8 @@
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
"lint:fix": "eslint . --fix",
"test:e2e": "playwright test"
},
"dependencies": {
"@nuxt/image": "^1.7.0",
Expand All @@ -19,8 +21,11 @@
},
"devDependencies": {
"@antfu/eslint-config": "^2.21.2",
"@clerk/testing": "^1.1.8",
"@nuxt/test-utils": "^3.13.1",
"@nuxtjs/google-fonts": "^3.2.0",
"@nuxtjs/tailwindcss": "^6.12.0",
"@playwright/test": "^1.45.1",
"@types/node": "^20.14.9",
"eslint": "^9.6.0",
"nuxt": "^3.12.3",
Expand Down
30 changes: 30 additions & 0 deletions playwright.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { fileURLToPath } from 'node:url'
import { defineConfig, devices } from '@playwright/test'
import type { ConfigOptions } from '@nuxt/test-utils/playwright'

export default defineConfig<ConfigOptions>({
testDir: fileURLToPath(new URL('e2e', import.meta.url)),
outputDir: 'test-results/',
webServer: {
command: 'pnpm dev',
},
use: {
headless: false,
nuxt: {
rootDir: fileURLToPath(new URL('.', import.meta.url)),
},
},
projects: [
{
name: 'global setup',
testMatch: /global\.setup\.ts/,
},
{
name: 'Desktop Chrome',
use: {
...devices['Desktop Chrome'],
},
dependencies: ['global setup'],
},
],
})
Loading