Skip to content

Commit

Permalink
Improve e2e test to be more isolated
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed Dec 3, 2024
1 parent f2409d7 commit 0653d1b
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 22 deletions.
14 changes: 14 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:


# E2E tests
- name: Install minio
run: |
wget https://dl.min.io/server/minio/release/linux-amd64/archive/minio_20241107005220.0.0_amd64.deb -O minio.deb
sudo dpkg -i minio.deb
- run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/tursodatabase/libsql/releases/download/libsql-server-v0.24.28/libsql-server-installer.sh | sh
- name: Get installed Playwright version
id: playwright-version
run: |
Expand All @@ -36,5 +41,6 @@ jobs:
- name: Setup e2e env
run: echo "${{ secrets.ENV_TESTS_BASE64 }}" | base64 --decode >> .env
- run: bun run e2e

- name: Deploy
run: curl -X POST https://api.cloudflare.com/client/v4/pages/webhooks/deploy_hooks/344ca361-b2d3-48e6-b896-ffa2dd1e9a1b
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ server/prisma-client/
prisma/app.db*
test-results/
playwright/.auth

.temp
2 changes: 1 addition & 1 deletion docker-compose.env
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion pages/signin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<form class="w-full flex flex-col gap-3" v-if="LOCAL_AUTH_ENABLED" @submit.prevent="(e) => signInAuth(e)">
<InputText required name="username" placeholder="Username" fluid />
<InputText required name="password" placeholder="Password" type="password" fluid />
<Button type="submit" label="Sign In" :loading="isPending" />
<Button type="submit" data-testid="sign_in_btn" label="Sign In" :loading="isPending" />
</form>
<AppDivider :orientation="'horizontal'" v-if="LOCAL_AUTH_ENABLED" />
<div class="w-full flex justify-center" style="color-scheme: auto;">
Expand Down
8 changes: 4 additions & 4 deletions playwright.config.mts
Original file line number Diff line number Diff line change
@@ -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<ConfigOptions>({
webServer: {
command: 'bun run dev',
command: './setup-test.sh',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
stdout: 'ignore',
stdout: 'pipe',
stderr: 'pipe',
},
use: {
Expand All @@ -20,9 +19,10 @@ export default defineConfig<ConfigOptions>({
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',
Expand Down
2 changes: 1 addition & 1 deletion server/api/auth/sign-in-auth.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
44 changes: 44 additions & 0 deletions setup-test.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests-e2e/home-menu.test.mts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
20 changes: 7 additions & 13 deletions tests-e2e/setup/auth.setup.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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.getByTestId('sign_in_btn').click()
await expect(page.getByTestId('sign_in_btn')).toHaveCount(0)

await page.context().storageState({ path: authFile });
await page.context().storageState({ path: authFile })
})

0 comments on commit 0653d1b

Please sign in to comment.