Skip to content

Commit

Permalink
chore: add test for outdir of codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
Teages committed Apr 18, 2024
1 parent 6b5417a commit 746e3dc
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/codegen-outdir.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { $fetch, setup } from '@nuxt/test-utils/e2e'

describe('urql', async () => {
await setup({
rootDir: fileURLToPath(new URL('./fixtures/codegen-outdir', import.meta.url)),
})

it('useQuery and useAsyncQuery', async () => {
const html = await $fetch('/hello')
expect(html).toContain('AsyncQuery: hello, one')
expect(html).toContain('Query: hello, two')
expect(html).toContain('AsyncWithGettersQuery: hello, three')
expect(html).toContain('AsyncWithComputedQuery: hello, four')
})

it('useMutation', async () => {
const html = await $fetch('/again')
expect(html).toContain('Mutation: hello two from mutation')
})
})
5 changes: 5 additions & 0 deletions test/fixtures/codegen-outdir/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<NuxtPage />
</div>
</template>
18 changes: 18 additions & 0 deletions test/fixtures/codegen-outdir/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default defineNuxtConfig({
modules: ['../../../src/module'],
urqlClient: {
clients: {
hello: {
url: 'https://graphql-test.teages.xyz/graphql-hello',
credentials: 'include',
cookiesFilter: ['locale'],
fetchOptions: {
headers: {
Authorization: 'Bearer 123',
},
},
},
},
codegen: { outputDir: '.gql' },
},
})
5 changes: 5 additions & 0 deletions test/fixtures/codegen-outdir/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic",
"type": "module",
"private": true
}
13 changes: 13 additions & 0 deletions test/fixtures/codegen-outdir/pages/again.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script setup lang="ts">
const mutation = gqlhello(/* GraphQL */`
mutation testMutation($name: String!) {
helloAgain(name: $name)
}
`)
const { data } = useAsyncData(() => useMutation(mutation, { name: 'two' }))
</script>

<template>
<div> Mutation: {{ data.helloAgain }} </div>
</template>
22 changes: 22 additions & 0 deletions test/fixtures/codegen-outdir/pages/hello.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script setup lang="ts">
const query = gqlhello(/* GraphQL */`
query test($name: String!) {
hello(name: $name)
}
`)
const { data: asyncQueryDaya } = await useAsyncQuery(query, { name: 'one' })
const { data } = await useAsyncData(() => useQuery(query, { name: 'two' }))
const { data: asyncWithGettersQueryData } = await useAsyncQuery(query, () => ({ name: 'three' }))
const v = computed(() => ({ name: 'four' }))
const { data: asyncWithComputedQueryData } = await useAsyncQuery(query, v)
</script>

<template>
<div> AsyncQuery: {{ asyncQueryDaya.hello }} </div>
<div> Query: {{ data.hello }} </div>

<div> AsyncWithGettersQuery: {{ asyncWithGettersQueryData.hello }} </div>
<div> AsyncWithComputedQuery: {{ asyncWithComputedQueryData.hello }} </div>
</template>

0 comments on commit 746e3dc

Please sign in to comment.