From 63f872670c2c2ae4cac09c3c8df9c9304ff6cf41 Mon Sep 17 00:00:00 2001 From: Gerben Mulder Date: Wed, 8 Jul 2026 12:06:42 +0200 Subject: [PATCH 1/5] feat(fixtures): add server-backed vue fixture --- pnpm-lock.yaml | 6 + test/fixtures/_shared/.env | 6 +- .../_shared/docker/docker-compose.yml | 4 +- test/fixtures/nuxt/.env | 4 +- test/fixtures/nuxt/app/app.vue | 16 ++- test/fixtures/nuxt/app/composables/zero.ts | 11 +- test/fixtures/nuxt/nuxt.config.ts | 4 +- test/fixtures/nuxt/package.json | 2 +- test/fixtures/nuxt/server/api/login.get.ts | 11 +- test/fixtures/nuxt/test/e2e.test.ts | 5 +- test/fixtures/vue/.env | 5 +- test/fixtures/vue/package.json | 4 +- test/fixtures/vue/server/auth.ts | 49 ++++++++ test/fixtures/vue/server/index.ts | 19 +++ test/fixtures/vue/server/mutate.ts | 34 ++++++ test/fixtures/vue/server/query.ts | 21 ++++ test/fixtures/vue/src/app.vue | 22 ++-- test/fixtures/vue/src/zero.shared.ts | 107 +++++++++++++++++ test/fixtures/vue/src/zero.ts | 113 +----------------- test/fixtures/vue/tsconfig.node.json | 1 + test/fixtures/vue/vite.config.ts | 51 ++++++-- 21 files changed, 337 insertions(+), 158 deletions(-) create mode 100644 test/fixtures/vue/server/auth.ts create mode 100644 test/fixtures/vue/server/index.ts create mode 100644 test/fixtures/vue/server/mutate.ts create mode 100644 test/fixtures/vue/server/query.ts create mode 100644 test/fixtures/vue/src/zero.shared.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b0566a7..1e755e7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -97,9 +97,15 @@ importers: '@vueuse/integrations': specifier: ^14.3.0 version: 14.3.0(change-case@5.4.4)(fuse.js@7.4.2)(universal-cookie@8.1.2)(vue@3.5.39(typescript@6.0.3)) + h3: + specifier: ^1.15.11 + version: 1.15.11 jose: specifier: ^6.2.3 version: 6.2.3 + postgres: + specifier: ^3.4.7 + version: 3.4.7 universal-cookie: specifier: ^8.1.2 version: 8.1.2 diff --git a/test/fixtures/_shared/.env b/test/fixtures/_shared/.env index e238df5..1ef2ffa 100644 --- a/test/fixtures/_shared/.env +++ b/test/fixtures/_shared/.env @@ -4,11 +4,9 @@ ZERO_LOG_LEVEL="debug" ZERO_ADMIN_PASSWORD="password" ZERO_MUTATE_FORWARD_COOKIES="true" -# ZERO_MUTATE_URL="http://localhost:3000/api/zero/mutate" +ZERO_MUTATE_URL="http://localhost:3000/api/mutate" ZERO_QUERY_FORWARD_COOKIES="true" -# ZERO_QUERY_URL="http://localhost:3000/api/zero/query" - -# ZERO_AUTH_SECRET="secretkey" +ZERO_QUERY_URL="http://localhost:3000/api/query" ZERO_REPLICA_FILE="/tmp/zstart_replicas.db" diff --git a/test/fixtures/_shared/docker/docker-compose.yml b/test/fixtures/_shared/docker/docker-compose.yml index 90f62ec..4a5baa9 100644 --- a/test/fixtures/_shared/docker/docker-compose.yml +++ b/test/fixtures/_shared/docker/docker-compose.yml @@ -1,3 +1,5 @@ +name: zero-vue + services: zstart_postgres: image: postgres:18.3-alpine @@ -23,7 +25,7 @@ services: -c hot_standby=on -c hot_standby_feedback=on volumes: - - zstart_pgdata:/var/lib/postgresql/data + - zstart_pgdata:/var/lib/postgresql - ./:/docker-entrypoint-initdb.d volumes: diff --git a/test/fixtures/nuxt/.env b/test/fixtures/nuxt/.env index 82b41c0..b762c64 100644 --- a/test/fixtures/nuxt/.env +++ b/test/fixtures/nuxt/.env @@ -1,2 +1,2 @@ -# NUXT_ZERO_AUTH_SECRET="secretkey" -# NUXT_PUBLIC_ZERO_CACHE_URL="http://localhost:4848" +# NUXT_AUTH_SECRET can be set to keep login cookies stable across dev server restarts. +NUXT_PUBLIC_ZERO_CACHE_URL="http://localhost:4848" diff --git a/test/fixtures/nuxt/app/app.vue b/test/fixtures/nuxt/app/app.vue index a896491..5bf962c 100644 --- a/test/fixtures/nuxt/app/app.vue +++ b/test/fixtures/nuxt/app/app.vue @@ -20,6 +20,7 @@ const { data: filteredMessages } = useQuery(() => queries.messages.filtered({ })) const hasFilters = computed(() => filterUser.value || filterText.value) +const canAddMessages = computed(() => !!zero.value.userID && users.value.length > 0 && mediums.value.length > 0) function deleteRandomMessage() { if (allMessages.value.length === 0) { @@ -32,6 +33,10 @@ function deleteRandomMessage() { } function addRandomMessage() { + if (!canAddMessages.value) { + return false + } + zero.value.mutate(mutators.message.insert( randomMessage(users.value, mediums.value), )) @@ -68,7 +73,7 @@ function handleAddAction() { } function handleRemoveAction(e: MouseEvent | TouchEvent) { - if (zero.value.userID === 'anon' && 'shiftKey' in e && !e.shiftKey) { + if (!zero.value.userID && 'shiftKey' in e && !e.shiftKey) { // eslint-disable-next-line no-alert alert('You must be logged in to delete. Hold shift to try anyway.') return @@ -106,7 +111,7 @@ function editMessage(e: MouseEvent, id: string, senderID: string, prev: string) const jwt = useCookie('jwt') async function toggleLogin() { - if (zero.value.userID === 'anon') { + if (!zero.value.userID) { await $fetch('/api/login') } else { @@ -115,7 +120,7 @@ async function toggleLogin() { location.reload() } -const user = computed(() => users.value.find(user => user.id === zero.value.userID)?.name ?? 'anon') +const user = computed(() => users.value.find(user => user.id === zero.value.userID)?.name)