Skip to content

Commit 016c339

Browse files
authored
test: improve tests and integrity (#163)
1 parent 9c7be8f commit 016c339

File tree

21 files changed

+129
-14
lines changed

21 files changed

+129
-14
lines changed

src/features.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function setupOpenAPI(nuxt: Nuxt) {
9898
// Fallback to custom placeholder when openAPI is disabled
9999
nuxt.options.alias['#hub/openapi'] = nuxt.options.nitro?.experimental?.openAPI === true
100100
? '#internal/nitro/routes/openapi'
101-
: resolve('./runtime/openapi/templates/openapi')
101+
: resolve('./runtime/openapi/server/templates/openapi')
102102

103103
addServerScanDir(resolve('./runtime/openapi/server'))
104104
}

src/module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { version } from '../package.json'
99
import { generateWrangler } from './utils/wrangler'
1010
import { setupCache, setupAnalytics, setupBlob, setupOpenAPI, setupDatabase, setupKV, setupBase, setupRemote } from './features'
1111
import type { ModuleOptions } from './types/module'
12+
import { addBuildHooks } from './utils/build'
1213

1314
export * from './types'
1415

@@ -85,6 +86,8 @@ export default defineNuxtModule<ModuleOptions>({
8586
return
8687
}
8788

89+
addBuildHooks(nuxt, hub)
90+
8891
if (hub.remote) {
8992
await setupRemote(nuxt, hub)
9093
return

src/runtime/base/server/api/_hub/manifest.get.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useRuntimeConfig } from '#imports'
77

88
export default eventHandler(async (event) => {
99
await requireNuxtHubAuthorization(event)
10-
const { version, cache, blob, kv, database } = useRuntimeConfig().hub
10+
const { version, cache, analytics, blob, kv, database } = useRuntimeConfig().hub
1111
const [dbCheck, kvCheck, blobCheck] = await Promise.all([
1212
falseIfFail(() => database && hubDatabase().exec('PRAGMA table_list')),
1313
falseIfFail(() => kv && hubKV().getKeys('__check__')),
@@ -22,6 +22,7 @@ export default eventHandler(async (event) => {
2222
blob: Array.isArray(blobCheck?.blobs)
2323
},
2424
features: {
25+
analytics,
2526
cache
2627
}
2728
}

test/analytics.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { fileURLToPath } from 'node:url'
2+
import { describe, it, expect } from 'vitest'
3+
import { setup, $fetch } from '@nuxt/test-utils'
4+
5+
describe('Analytics', async () => {
6+
await setup({
7+
rootDir: fileURLToPath(new URL('./fixtures/analytics', import.meta.url)),
8+
dev: true
9+
})
10+
11+
it('Check manifest (Analytics is enabled)', async () => {
12+
const manifest = await $fetch('/api/_hub/manifest')
13+
expect(manifest).toMatchObject({
14+
storage: {
15+
database: false,
16+
kv: false,
17+
blob: false
18+
},
19+
features: {
20+
analytics: true,
21+
cache: false
22+
}
23+
})
24+
})
25+
})

test/basic.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { fileURLToPath } from 'node:url'
22
import { describe, it, expect } from 'vitest'
33
import { setup, $fetch } from '@nuxt/test-utils/e2e'
4-
import { version } from '../package.json'
54

65
describe('ssr', async () => {
76
await setup({
@@ -12,7 +11,6 @@ describe('ssr', async () => {
1211
it('Fetch Hub manifetst', async () => {
1312
const manifest = await $fetch('/api/_hub/manifest')
1413
expect(manifest).toMatchObject({
15-
version,
1614
storage: {
1715
database: false,
1816
kv: false,

test/blob.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { fileURLToPath } from 'node:url'
22
import fs from 'node:fs/promises'
33
import { describe, it, expect } from 'vitest'
44
import { setup, $fetch, url } from '@nuxt/test-utils'
5-
import { version } from '../package.json'
65
import type { BlobListResult } from '../src/types/blob'
76
import { useUpload } from '../src/runtime/blob/app/composables/useUpload'
87
import { useMultipartUpload } from '../src/runtime/blob/app/composables/useMultipartUpload'
@@ -35,7 +34,6 @@ describe('Blob', async () => {
3534
it('Check manifest (Blob is enabled)', async () => {
3635
const manifest = await $fetch('/api/_hub/manifest')
3736
expect(manifest).toMatchObject({
38-
version,
3937
storage: {
4038
database: false,
4139
kv: false,

test/cache.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { fileURLToPath } from 'node:url'
22
import fs from 'node:fs/promises'
33
import { describe, it, expect } from 'vitest'
44
import { setup, $fetch } from '@nuxt/test-utils'
5-
import { version } from '../package.json'
65

76
const cacheListFields = ['duration', 'expires', 'integrity', 'key', 'mtime', 'size']
87

@@ -18,7 +17,6 @@ describe('KV', async () => {
1817
it('Check manifest (Cache is enabled)', async () => {
1918
const manifest = await $fetch('/api/_hub/manifest')
2019
expect(manifest).toMatchObject({
21-
version,
2220
storage: {
2321
database: false,
2422
kv: false,

test/fixtures/analytics/app.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script setup lang="ts">
2+
import { useFetch } from '#app'
3+
4+
const { data: manifest } = useFetch<Record<string, any>>('/api/_hub/manifest')
5+
</script>
6+
7+
<template>
8+
<h3>Data storage enabled:</h3>
9+
<ul>
10+
<li
11+
v-for="primitive in Object.keys(manifest?.storage || {})"
12+
:key="primitive"
13+
>
14+
{{ primitive }}
15+
</li>
16+
</ul>
17+
</template>

0 commit comments

Comments
 (0)