diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..f8481d8 --- /dev/null +++ b/.env.test @@ -0,0 +1,14 @@ +# user=password:user=password; +NUXT_LOCAL_AUTHS=usertest1=a5756f781e0e433986364b82de545c3b:usertest2=963a71f1868248df912e7488e02233f0 +NUXT_PUBLIC_LOCAL_AUTH_ENABLED=true +NUXT_APP_ENABLE_DRIZZLE_LOGGING=true +NUXT_DB_URL=http://localhost:8888 +NUXT_DB_AUTH_TOKEN=basic:c3FsZDppOHJ3ZXlzNzBkN2Zh +NUXT_S3_ENDPOINT=http://localhost:9000 +NUXT_S3_ACCESS_KEY_ID=minioadmin +NUXT_S3_SECRET_ACCESS_KEY=minioadmin +NUXT_JWT_KEY=5741sktf1xfv5qocbbnhsy7az2ny353e497wom8up5nggc3qbnjbu5bj5k9m3nv7 +NUXT_PUBLIC_GOOGLE_CLIENT_ID=sample-fc72420db46b4bfaaba8ea97a74535a7.apps.googleusercontent.com +NUXT_APP_MIGRATION_ENABLE=true +NUXT_APP_MIGRATION_DIR= +NUXT_APP_API_AUTH_KEY=dy9ea7v24f9f46j94p4xp1gcozwn1qcmgweb7kdzhuxi9br7gi89t2uy2r1896ag diff --git a/.gitignore b/.gitignore index 8bc45fd..90cf942 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ server/prisma-client/ prisma/app.db* test-results/ playwright/.auth + +.temp \ No newline at end of file diff --git a/docker-compose.env b/docker-compose.env index 45e3509..f06ee65 100644 --- a/docker-compose.env +++ b/docker-compose.env @@ -1,6 +1,6 @@ # Generate key using openssl rand -base64 32 -NUXT_LOCAL_AUTHS=yunus1=a168746dc0bc427b9aac07a0c40c2efc;yunus2=d920d57cc4684580bee7f8db3a29e57c +NUXT_LOCAL_AUTHS=usertest1=a168746dc0bc427b9aac07a0c40c2efc:usertest2=d920d57cc4684580bee7f8db3a29e57c NUXT_PUBLIC_LOCAL_AUTH_ENABLED=true NUXT_APP_ENABLE_DRIZZLE_LOGGING=true NUXT_DB_URL=libsql://libsql.turso.io diff --git a/package.json b/package.json index f4f786a..0edc1df 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "drizzle:generate": "drizzle-kit generate", "drizzle:migrate": "bun run server/db/migrate.ts", "deploy": "bun run build --preset=cloudflare-pages && npx wrangler pages deploy dist/", - "e2e": "NODE_OPTIONS=--require=dotenv/config playwright test", + "e2e": "playwright test", + "e2e-ui": "bun run e2e --ui-port=8080 --ui-host=127.0.0.1", "tests": "vitest test", "build-cli": "bun build cli/cli.ts --target node > cli/cli.mjs" }, diff --git a/playwright.config.mts b/playwright.config.mts index 47676fc..a688c56 100644 --- a/playwright.config.mts +++ b/playwright.config.mts @@ -1,13 +1,12 @@ -import { fileURLToPath } from 'node:url' import { defineConfig, devices } from '@playwright/test' import type { ConfigOptions } from '@nuxt/test-utils/playwright' export default defineConfig({ webServer: { - command: 'bun run dev', + command: './setup-test.sh', url: 'http://localhost:3000', reuseExistingServer: !process.env.CI, - stdout: 'ignore', + stdout: 'pipe', stderr: 'pipe', }, use: { @@ -20,9 +19,10 @@ export default defineConfig({ timeout: 12000, }, projects: [ - { name: 'Setup', testMatch: '**/*.setup.mts' }, + { name: 'setup', testMatch: '**/*.setup.mts' }, { name: 'Chromium', + dependencies: ['setup'], use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/user.json', diff --git a/server/api/auth/sign-in-auth.post.ts b/server/api/auth/sign-in-auth.post.ts index 2f4ba4d..4733c60 100644 --- a/server/api/auth/sign-in-auth.post.ts +++ b/server/api/auth/sign-in-auth.post.ts @@ -30,7 +30,7 @@ export default defineEventHandler(async event => { }) export function getLocalAuths(localAuths: string): { username: string, password: string }[] { - return localAuths.split(';').map(e => { + return localAuths.split(':').map(e => { const s = e.split('=') return { username: s[0], diff --git a/setup-test.sh b/setup-test.sh new file mode 100755 index 0000000..83aace8 --- /dev/null +++ b/setup-test.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +dotenv() { + set -a + [ -f .env ] && . .env.test + set +a +} + +dotenv + +echo "Setup test" + +tempFolder=".temp" +rm -rf $tempFolder +mkdir -p $tempFolder + +minioFolder="$tempFolder/minio" +mkdir -p "$minioFolder/distapp" +minio server --address 127.0.0.1:9000 "$minioFolder" & + +for i in {1..10}; do + curl -s -IL 127.0.0.1:9000 + if [ $? -eq 0 ]; then + break + fi + sleep 1 +done + +mkdir -p "$tempFolder/sqld" +pushd "$tempFolder/sqld" +sqld --http-listen-addr "127.0.0.1:8888" --http-auth "basic:c3FsZDppOHJ3ZXlzNzBkN2Zh" & +for i in {1..10}; do + curl -s -IL 127.0.0.1:8888 + if [ $? -eq 0 ]; then + break + fi + sleep 1 +done + +popd + +echo "Finish setup test" + +bun run dev diff --git a/tests-e2e/home-menu.test.mts b/tests-e2e/home-menu.test.mts index dc5258c..b976c7a 100644 --- a/tests-e2e/home-menu.test.mts +++ b/tests-e2e/home-menu.test.mts @@ -1,6 +1,6 @@ import { expect, test } from '@nuxt/test-utils/playwright' -test('Changing org should not hide app menu when loading', async ({ page, goto, context }) => { +test.skip('Changing org should not hide app menu when loading', async ({ page, goto, context }) => { await goto('/apps') await expect(page.getByTestId('amenu-1')).toBeVisible() await page.getByTestId('amenu-1').click() diff --git a/tests-e2e/setup/auth.setup.mts b/tests-e2e/setup/auth.setup.mts index 0302b2e..1a4dd95 100644 --- a/tests-e2e/setup/auth.setup.mts +++ b/tests-e2e/setup/auth.setup.mts @@ -3,18 +3,12 @@ import path from 'path'; const authFile = path.join(import.meta.dirname, '../../playwright/.auth/user.json'); -setup('authenticate', async ({ page }) => { - const domain = process.env.TEST_APP_URL!.replaceAll('https://', '').replaceAll('http://', '').replaceAll(':3000', '') - await page.context().addCookies([{ - name: 'app-auth', - value: process.env.TEST_APP_AUTH_COOKIES!, - httpOnly: false, - secure: true, - sameSite: 'Lax', - path: '/', - domain: domain, - expires: -1, - }]) +setup('Authenticate', async ({ page }) => { + await page.goto('http://localhost:3000/signin') + await page.locator('[name="username"]').fill('usertest1') + await page.locator('[name="password"]').fill('a5756f781e0e433986364b82de545c3b') + await page.getByLabel('Sign In').click() + await expect(page.getByLabel('Sign In')).toHaveCount(0) - await page.context().storageState({ path: authFile }); + await page.context().storageState({ path: authFile }) }) \ No newline at end of file