diff --git a/package.json b/package.json index bec8225..e159f1a 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,6 @@ "@nuxt/module-builder": "catalog:", "@nuxt/nitro-server": "catalog:", "@nuxt/schema": "catalog:", - "@nuxt/test-utils": "catalog:", "@types/node": "catalog:", "@typescript-eslint/parser": "catalog:", "@typescript-eslint/rule-tester": "catalog:", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8c5e70e..aa799a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -194,9 +194,6 @@ catalogs: '@nuxt/schema': specifier: 4.5.0 version: 4.5.0 - '@nuxt/test-utils': - specifier: ^4.3.4 - version: 4.3.4 '@standard-community/standard-json': specifier: ^0.3.7 version: 0.3.7 @@ -352,9 +349,6 @@ importers: '@nuxt/schema': specifier: 'catalog:' version: 4.5.0 - '@nuxt/test-utils': - specifier: 'catalog:' - version: 4.3.4(709c6734c97d0eb5b931baa759fe1459) '@types/node': specifier: 'catalog:' version: 24.19.2 @@ -452,16 +446,6 @@ importers: specifier: 'catalog:' version: 1.5.0(typescript@6.0.3) - test/fixtures/arktype: - dependencies: - arktype: - specifier: 'catalog:' - version: 2.2.9 - devDependencies: - nuxt: - specifier: 'catalog:' - version: 4.5.0(@babel/plugin-syntax-jsx@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@oxc-project/types@0.155.0)(@types/node@24.19.2)(@vue/compiler-sfc@3.5.44)(better-sqlite3@13.0.3)(cac@7.1.0)(db0@0.4.1)(esbuild@0.28.2)(eslint@10.13.0(jiti@2.7.0)(supports-color@10.2.2))(ioredis@5.11.1(supports-color@10.2.2))(lightningcss@1.33.0)(magicast@0.5.5)(optionator@0.9.4)(oxc-parser@0.151.0)(rollup-plugin-visualizer@7.1.1(rolldown@1.2.15)(rollup@4.65.0))(rollup@4.65.0)(srvx@1.0.7)(supports-color@10.2.2)(terser@5.51.2)(typescript@6.0.3)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1))(vue-tsc@3.3.13(typescript@6.0.3))(yaml@2.9.1) - test/fixtures/cloudflare-auto-import: dependencies: valibot: @@ -518,16 +502,6 @@ importers: specifier: 'catalog:' version: 4.5.0(@babel/plugin-syntax-jsx@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@oxc-project/types@0.155.0)(@types/node@24.19.2)(@vue/compiler-sfc@3.5.44)(better-sqlite3@13.0.3)(cac@7.1.0)(db0@0.4.1)(esbuild@0.28.2)(eslint@10.13.0(jiti@2.7.0)(supports-color@10.2.2))(ioredis@5.11.1(supports-color@10.2.2))(lightningcss@1.33.0)(magicast@0.5.5)(optionator@0.9.4)(oxc-parser@0.151.0)(rollup-plugin-visualizer@7.1.1(rolldown@1.2.15)(rollup@4.65.0))(rollup@4.65.0)(srvx@1.0.7)(supports-color@10.2.2)(terser@5.51.2)(typescript@6.0.3)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1))(vue-tsc@3.3.13(typescript@6.0.3))(yaml@2.9.1) - test/fixtures/valibot-runtime: - dependencies: - valibot: - specifier: 'catalog:' - version: 1.5.0(typescript@6.0.3) - devDependencies: - nuxt: - specifier: 'catalog:' - version: 4.5.0(@babel/plugin-syntax-jsx@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@oxc-project/types@0.155.0)(@types/node@24.19.2)(@vue/compiler-sfc@3.5.44)(better-sqlite3@13.0.3)(cac@7.1.0)(db0@0.4.1)(esbuild@0.28.2)(eslint@10.13.0(jiti@2.7.0)(supports-color@10.2.2))(ioredis@5.11.1(supports-color@10.2.2))(lightningcss@1.33.0)(magicast@0.5.5)(optionator@0.9.4)(oxc-parser@0.151.0)(rollup-plugin-visualizer@7.1.1(rolldown@1.2.15)(rollup@4.65.0))(rollup@4.65.0)(srvx@1.0.7)(supports-color@10.2.2)(terser@5.51.2)(typescript@6.0.3)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1))(vue-tsc@3.3.13(typescript@6.0.3))(yaml@2.9.1) - test/fixtures/validation-failure: dependencies: valibot: @@ -538,26 +512,6 @@ importers: specifier: 'catalog:' version: 4.5.0(@babel/plugin-syntax-jsx@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@oxc-project/types@0.155.0)(@types/node@24.19.2)(@vue/compiler-sfc@3.5.44)(better-sqlite3@13.0.3)(cac@7.1.0)(db0@0.4.1)(esbuild@0.28.2)(eslint@10.13.0(jiti@2.7.0)(supports-color@10.2.2))(ioredis@5.11.1(supports-color@10.2.2))(lightningcss@1.33.0)(magicast@0.5.5)(optionator@0.9.4)(oxc-parser@0.151.0)(rollup-plugin-visualizer@7.1.1(rolldown@1.2.15)(rollup@4.65.0))(rollup@4.65.0)(srvx@1.0.7)(supports-color@10.2.2)(terser@5.51.2)(typescript@6.0.3)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1))(vue-tsc@3.3.13(typescript@6.0.3))(yaml@2.9.1) - test/fixtures/validation-success: - dependencies: - valibot: - specifier: 'catalog:' - version: 1.5.0(typescript@6.0.3) - devDependencies: - nuxt: - specifier: 'catalog:' - version: 4.5.0(@babel/plugin-syntax-jsx@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@oxc-project/types@0.155.0)(@types/node@24.19.2)(@vue/compiler-sfc@3.5.44)(better-sqlite3@13.0.3)(cac@7.1.0)(db0@0.4.1)(esbuild@0.28.2)(eslint@10.13.0(jiti@2.7.0)(supports-color@10.2.2))(ioredis@5.11.1(supports-color@10.2.2))(lightningcss@1.33.0)(magicast@0.5.5)(optionator@0.9.4)(oxc-parser@0.151.0)(rollup-plugin-visualizer@7.1.1(rolldown@1.2.15)(rollup@4.65.0))(rollup@4.65.0)(srvx@1.0.7)(supports-color@10.2.2)(terser@5.51.2)(typescript@6.0.3)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1))(vue-tsc@3.3.13(typescript@6.0.3))(yaml@2.9.1) - - test/fixtures/zod-native: - dependencies: - zod: - specifier: 'catalog:' - version: 4.6.7 - devDependencies: - nuxt: - specifier: 'catalog:' - version: 4.5.0(@babel/plugin-syntax-jsx@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@oxc-project/types@0.155.0)(@types/node@24.19.2)(@vue/compiler-sfc@3.5.44)(better-sqlite3@13.0.3)(cac@7.1.0)(db0@0.4.1)(esbuild@0.28.2)(eslint@10.13.0(jiti@2.7.0)(supports-color@10.2.2))(ioredis@5.11.1(supports-color@10.2.2))(lightningcss@1.33.0)(magicast@0.5.5)(optionator@0.9.4)(oxc-parser@0.151.0)(rollup-plugin-visualizer@7.1.1(rolldown@1.2.15)(rollup@4.65.0))(rollup@4.65.0)(srvx@1.0.7)(supports-color@10.2.2)(terser@5.51.2)(typescript@6.0.3)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1))(vue-tsc@3.3.13(typescript@6.0.3))(yaml@2.9.1) - packages: '@ai-sdk/gateway@4.0.126': @@ -2096,49 +2050,6 @@ packages: peerDependencies: '@nuxt/kit': 4.5.0 - '@nuxt/test-utils@4.3.4': - resolution: {integrity: sha512-8x0w16DDUi1/6ZivL1zuOaDt9xtACZFHMQySBirUZNIU0H0qljjB5yyajXPtlb8YCQ5l6piFJqafK/zDpDcCnA==} - engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0} - peerDependencies: - '@cucumber/cucumber': '>=11.0.0' - '@jest/globals': '>=30.0.0' - '@playwright/test': ^1.43.1 - '@testing-library/vue': ^8.0.1 - '@vitest/ui': '*' - '@vue/test-utils': ^2.4.2 - h3: ^1.15.0 || ^2.0.0-0 - happy-dom: '>=20.0.11' - jsdom: '>=27.4.0' - nuxt: ^3.21.0 || ^4.0.0 || ^5.0.0-0 - playwright-core: ^1.43.1 - vitest: ^4.0.2 || ^5.0.0 - vue: ^3.5.0 - peerDependenciesMeta: - '@cucumber/cucumber': - optional: true - '@jest/globals': - optional: true - '@playwright/test': - optional: true - '@testing-library/vue': - optional: true - '@vitest/ui': - optional: true - '@vue/test-utils': - optional: true - h3: - optional: true - happy-dom: - optional: true - jsdom: - optional: true - nuxt: - optional: true - playwright-core: - optional: true - vitest: - optional: true - '@nuxt/ui@4.12.0': resolution: {integrity: sha512-e5g3RiFHTQc+PzBFZogpPLNetAMJDWq+5GPVUK88jIBgm/jnxYqMgbvyhfuLdL7spvyjA5ow5TtvIQVEAs3AMA==} engines: {node: ^20.19.0 || >=22.12.0} @@ -5606,10 +5517,6 @@ packages: extend@3.0.2: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} - fake-indexeddb@6.2.6: - resolution: {integrity: sha512-ihhmr0KoET51jT8R4YhbUYuLLvr1qqO6INISygtN16i8loR8kAxtAUr4+EKHTSMjL+lggaAn4OC7DRqzrNgnuQ==} - engines: {node: '>=18'} - fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -8941,9 +8848,6 @@ packages: yaml: optional: true - vitest-environment-nuxt@2.0.0: - resolution: {integrity: sha512-zEGFRiCAaRR3fHnqISHKMNTRvCzkQEI1XyFeqNgR2IBD0oYkfZ1rUHwi7C+h3Cns3KPykfB0av1B3MtLEbChDw==} - vitest@5.0.5: resolution: {integrity: sha512-cPODOMF8YnkiiYtDdHo6n4wWmBrOBBbOIYH2d33M4l3CdNn72h+qMmO6uXffUN6A5AZFXNND/d+krS9mgkXRfg==} engines: {node: ^22.12.0 || ^24.0.0 || >=26.0.0} @@ -11436,48 +11340,6 @@ snapshots: rc9: 3.1.0 std-env: 4.3.0 - '@nuxt/test-utils@4.3.4(709c6734c97d0eb5b931baa759fe1459)': - dependencies: - '@clack/prompts': 1.8.1 - '@nuxt/devtools-kit': 3.4.4(magic-string@1.4.3)(magicast@0.5.5)(oxc-parser@0.151.0)(rolldown@1.2.15)(unplugin@3.4.0(esbuild@0.28.2)(rolldown@1.2.15)(rollup@4.65.0)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1)))(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1)) - '@nuxt/kit': 4.5.0(magic-string@1.4.3)(magicast@0.5.5)(oxc-parser@0.151.0)(rolldown@1.2.15)(unplugin@3.4.0(esbuild@0.28.2)(rolldown@1.2.15)(rollup@4.65.0)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1))) - consola: 3.4.2 - defu: 6.1.7 - exsolve: 1.1.3 - fake-indexeddb: 6.2.6 - get-port-please: 3.2.0 - magic-string: 1.4.3 - ofetch: 1.5.1 - oxc-walker: 1.1.1(@oxc-project/types@0.155.0)(oxc-parser@0.151.0)(rolldown@1.2.15) - package-manager-detector: 1.9.0 - pathe: 2.0.3 - perfect-debounce: 2.1.0 - radix3: 1.1.2 - std-env: 4.3.0 - tinyexec: 1.3.1 - ufo: 1.6.4 - unplugin: 3.4.0(esbuild@0.28.2)(rolldown@1.2.15)(rollup@4.65.0)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1)) - vitest-environment-nuxt: 2.0.0 - vue: 3.5.44(typescript@6.0.3) - optionalDependencies: - h3: 1.15.11 - nuxt: 4.5.0(@babel/plugin-syntax-jsx@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.29.7(supports-color@10.2.2)))(@oxc-project/types@0.155.0)(@types/node@24.19.2)(@vue/compiler-sfc@3.5.44)(better-sqlite3@13.0.3)(cac@7.1.0)(db0@0.3.4(better-sqlite3@13.0.3))(esbuild@0.28.2)(eslint@10.13.0(jiti@2.7.0)(supports-color@10.2.2))(ioredis@5.11.1(supports-color@10.2.2))(lightningcss@1.33.0)(magicast@0.5.5)(optionator@0.9.4)(oxc-parser@0.151.0)(rollup-plugin-visualizer@7.1.1(rolldown@1.2.15)(rollup@4.65.0))(rollup@4.65.0)(srvx@0.11.22)(supports-color@10.2.2)(terser@5.51.2)(typescript@6.0.3)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1))(vue-tsc@3.3.13(typescript@6.0.3))(yaml@2.9.1) - vitest: 5.0.5(@types/node@24.19.2)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1)) - transitivePeerDependencies: - - '@farmfe/core' - - '@oxc-project/types' - - '@rsbuild/core' - - '@rspack/core' - - bun-types-no-globals - - esbuild - - magicast - - oxc-parser - - rolldown - - rollup - - unloader - - vite - - webpack - '@nuxt/ui@4.12.0(793004003cd93729875f0d6f9ff1b763)': dependencies: '@floating-ui/dom': 1.8.0 @@ -15187,8 +15049,6 @@ snapshots: extend@3.0.2: {} - fake-indexeddb@6.2.6: {} - fast-deep-equal@3.1.3: {} fast-diff@1.3.0: {} @@ -19864,10 +19724,6 @@ snapshots: terser: 5.51.2 yaml: 2.9.1 - vitest-environment-nuxt@2.0.0: - dependencies: - '@nuxt/test-utils': 4.3.4(709c6734c97d0eb5b931baa759fe1459) - vitest@5.0.5(@types/node@24.19.2)(vite@8.3.5(@types/node@24.19.2)(esbuild@0.28.2)(jiti@2.7.0)(terser@5.51.2)(yaml@2.9.1)): dependencies: '@types/chai': 5.2.3 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 266d075..b032754 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -47,7 +47,6 @@ catalog: '@nuxt/module-builder': ^1.0.3 '@nuxt/nitro-server': 4.5.0 '@nuxt/schema': 4.5.0 - '@nuxt/test-utils': ^4.3.4 '@standard-community/standard-json': ^0.3.7 '@standard-schema/spec': ^1.1.0 '@types/node': ^24.19.2 diff --git a/test/agent-context.test.ts b/test/agent-context.test.ts deleted file mode 100644 index e682ceb..0000000 --- a/test/agent-context.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { existsSync, readFileSync } from 'node:fs' -import { join } from 'node:path' -import { fileURLToPath } from 'node:url' -import { describe, expect, it } from 'vitest' - -const rootDir = fileURLToPath(new URL('..', import.meta.url)) - -describe('agent context metadata', () => { - it('advertises docs from package metadata', () => { - const pkg = JSON.parse(readFileSync(join(rootDir, 'package.json'), 'utf8')) as { - docs?: string - homepage?: string - } - - expect(pkg.homepage).toBe('https://nuxt-safe-runtime-config.onmax.me') - expect(pkg.docs).toBe('https://nuxt-safe-runtime-config.onmax.me') - }) - - it('publishes a well-known skill for module-specific context', () => { - const indexPath = join(rootDir, 'docs/public/.well-known/skills/index.json') - const compatibilitySkillPath = join(rootDir, 'docs/public/.well-known/skills/SKILL.md') - const skillPath = join(rootDir, 'docs/public/.well-known/skills/nuxt-safe-runtime-config/SKILL.md') - const index = JSON.parse(readFileSync(indexPath, 'utf8')) as { - skills?: Array<{ name?: string, description?: string, files?: string[] }> - } - - expect(existsSync(skillPath)).toBe(true) - expect(existsSync(compatibilitySkillPath)).toBe(true) - expect(index.skills).toEqual([ - { - name: 'nuxt-safe-runtime-config', - description: 'Use Nuxt Safe Runtime Config to validate Nuxt runtimeConfig with Standard Schema and consume it through typed generated helpers.', - files: ['SKILL.md'], - }, - ]) - - const skill = readFileSync(skillPath, 'utf8') - const compatibilitySkill = readFileSync(compatibilitySkillPath, 'utf8') - expect(compatibilitySkill).toBe(skill) - expect(skill).toContain('useSafeRuntimeConfig()') - expect(skill).toContain('safeRuntimeConfig.$schema') - }) -}) diff --git a/test/fixtures/arktype/app.vue b/test/fixtures/arktype/app.vue deleted file mode 100644 index 029ac71..0000000 --- a/test/fixtures/arktype/app.vue +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/test/fixtures/arktype/nuxt.config.ts b/test/fixtures/arktype/nuxt.config.ts deleted file mode 100644 index 994ff45..0000000 --- a/test/fixtures/arktype/nuxt.config.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { type } from 'arktype' -import SafeRuntimeConfig from '../../../src/module' - -const runtimeConfigSchema = type({ - 'public': { - 'apiBase': 'string', - 'appName?': 'string', - }, - 'databaseUrl': 'string', - 'secretKey': 'string', - 'port?': 'number', -}) - -export default defineNuxtConfig({ - modules: [SafeRuntimeConfig], - runtimeConfig: { - databaseUrl: 'postgresql://localhost:5432/app', - secretKey: 'test-secret', - port: 3000, - public: { - apiBase: 'https://api.example.com', - appName: 'ArkType Test', - }, - }, - safeRuntimeConfig: { - $schema: runtimeConfigSchema, - }, -}) diff --git a/test/fixtures/arktype/package.json b/test/fixtures/arktype/package.json deleted file mode 100644 index bab9e14..0000000 --- a/test/fixtures/arktype/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "nuxt-safe-runtime-config-test-arktype", - "type": "module", - "private": true, - "scripts": { - "prepare": "nuxt prepare" - }, - "dependencies": { - "arktype": "catalog:" - }, - "devDependencies": { - "nuxt": "catalog:" - } -} diff --git a/test/fixtures/env-var-validation/nuxt.config.ts b/test/fixtures/env-var-validation/nuxt.config.ts deleted file mode 100644 index 3c6a7df..0000000 --- a/test/fixtures/env-var-validation/nuxt.config.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { number, object, optional, string } from 'valibot' -import SafeRuntimeConfig from '../../../src/module' - -const runtimeConfigSchema = object({ - public: object({ - apiBase: string(), - appName: optional(string()), - }), - databaseUrl: string(), - secretKey: string(), - port: optional(number()), -}) - -export default defineNuxtConfig({ - modules: [SafeRuntimeConfig], - - runtimeConfig: { - databaseUrl: '', - secretKey: '', - port: 3000, - public: { - apiBase: '', - appName: 'Test App', - }, - }, - - safeRuntimeConfig: { - $schema: runtimeConfigSchema, - }, -}) diff --git a/test/fixtures/valibot-runtime/app.vue b/test/fixtures/valibot-runtime/app.vue deleted file mode 100644 index ef79a07..0000000 --- a/test/fixtures/valibot-runtime/app.vue +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/test/fixtures/valibot-runtime/nuxt.config.ts b/test/fixtures/valibot-runtime/nuxt.config.ts deleted file mode 100644 index 4921fb1..0000000 --- a/test/fixtures/valibot-runtime/nuxt.config.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { number, object, optional, string } from 'valibot' -import SafeRuntimeConfig from '../../../src/module' - -const runtimeConfigSchema = object({ - public: object({ - apiBase: string(), - }), - secretKey: string(), - port: optional(number()), -}) - -export default defineNuxtConfig({ - modules: [SafeRuntimeConfig], - - runtimeConfig: { - secretKey: 'test-secret-key', - port: 3000, - public: { - apiBase: 'https://api.test.com', - }, - }, - - safeRuntimeConfig: { - $schema: runtimeConfigSchema, - validateAtRuntime: true, - }, -}) diff --git a/test/fixtures/valibot-runtime/package.json b/test/fixtures/valibot-runtime/package.json deleted file mode 100644 index 3ec1bce..0000000 --- a/test/fixtures/valibot-runtime/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "nuxt-safe-runtime-config-test-valibot-runtime", - "type": "module", - "private": true, - "scripts": { - "prepare": "nuxt prepare" - }, - "dependencies": { - "valibot": "catalog:" - }, - "devDependencies": { - "nuxt": "catalog:" - } -} diff --git a/test/fixtures/validation-success/app.vue b/test/fixtures/validation-success/app.vue deleted file mode 100644 index 7142a0c..0000000 --- a/test/fixtures/validation-success/app.vue +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/test/fixtures/validation-success/nuxt.config.ts b/test/fixtures/validation-success/nuxt.config.ts deleted file mode 100644 index 1796e5f..0000000 --- a/test/fixtures/validation-success/nuxt.config.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { number, object, optional, string } from 'valibot' -import SafeRuntimeConfig from '../../../src/module' - -const runtimeConfigSchema = object({ - public: object({ - apiBase: string(), - appName: optional(string()), - }), - databaseUrl: string(), - secretKey: string(), - port: optional(number()), -}) - -export default defineNuxtConfig({ - modules: [SafeRuntimeConfig], - - runtimeConfig: { - databaseUrl: 'postgresql://localhost:5432/test', - secretKey: 'test-secret-key', - port: 3000, - public: { - apiBase: 'https://api.test.com', - appName: 'Test App', - }, - }, - - safeRuntimeConfig: { - $schema: runtimeConfigSchema, - }, -}) diff --git a/test/fixtures/validation-success/package.json b/test/fixtures/validation-success/package.json deleted file mode 100644 index 16049ab..0000000 --- a/test/fixtures/validation-success/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "nuxt-safe-runtime-config-test-success", - "type": "module", - "private": true, - "scripts": { - "prepare": "nuxt prepare" - }, - "dependencies": { - "valibot": "catalog:" - }, - "devDependencies": { - "nuxt": "catalog:" - } -} diff --git a/test/fixtures/zod-native/app.vue b/test/fixtures/zod-native/app.vue deleted file mode 100644 index e3249b0..0000000 --- a/test/fixtures/zod-native/app.vue +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/test/fixtures/zod-native/nuxt.config.ts b/test/fixtures/zod-native/nuxt.config.ts deleted file mode 100644 index 73b85dc..0000000 --- a/test/fixtures/zod-native/nuxt.config.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { z } from 'zod' -import SafeRuntimeConfig from '../../../src/module' - -const runtimeConfigSchema = z.object({ - public: z.object({ - apiBase: z.string(), - }), - secretKey: z.string(), -}) - -export default defineNuxtConfig({ - modules: [SafeRuntimeConfig], - - runtimeConfig: { - secretKey: 'test-secret-key', - public: { - apiBase: 'https://api.test.com', - }, - }, - - safeRuntimeConfig: { - $schema: runtimeConfigSchema, - validateAtRuntime: true, - jsonSchemaTarget: 'draft-2020-12', - }, -}) diff --git a/test/fixtures/zod-native/package.json b/test/fixtures/zod-native/package.json deleted file mode 100644 index 99e4908..0000000 --- a/test/fixtures/zod-native/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "nuxt-safe-runtime-config-test-zod-native", - "type": "module", - "private": true, - "scripts": { - "prepare": "nuxt prepare" - }, - "dependencies": { - "zod": "catalog:" - }, - "devDependencies": { - "nuxt": "catalog:" - } -} diff --git a/test/json-schema.test.ts b/test/json-schema.test.ts index e4ccb2f..448253a 100644 --- a/test/json-schema.test.ts +++ b/test/json-schema.test.ts @@ -32,11 +32,6 @@ describe('json-schema detection', () => { }) }) - it('does not detect native jsonSchema in Valibot', () => { - const schema = object({ name: string() }) - expect(hasNativeJSONSchema(schema)).toBe(false) - }) - it('generates JSON Schema from Zod', async () => { const schema = z.object({ name: z.string(), age: z.number().optional() }) const jsonSchema = await getJSONSchema(schema, 'draft-2020-12') diff --git a/test/runtime-coercion.test.ts b/test/runtime-coercion.test.ts index 75ce530..4626ac6 100644 --- a/test/runtime-coercion.test.ts +++ b/test/runtime-coercion.test.ts @@ -3,6 +3,7 @@ import { join } from 'node:path' import { fileURLToPath } from 'node:url' import { afterEach, describe, expect, it } from 'vitest' import { getFreePort } from './utils/free-port' +import { waitForResponse } from './utils/server' const fixtureDir = fileURLToPath(new URL('./fixtures/runtime-coercion', import.meta.url)) const nuxtBin = fileURLToPath(new URL('../node_modules/nuxt/bin/nuxt.mjs', import.meta.url)) @@ -15,25 +16,6 @@ afterEach(() => { children.length = 0 }) -async function waitForResponse(url: string, child: ReturnType): Promise { - let logs = '' - child.stdout?.on('data', chunk => logs += chunk.toString()) - child.stderr?.on('data', chunk => logs += chunk.toString()) - - for (let attempt = 0; attempt < 100; attempt++) { - try { - const response = await fetch(url) - if (response.ok) - return response - } - catch {} - if (child.exitCode !== null) - throw new Error(`Server exited with code ${child.exitCode}\n${logs}`) - await new Promise(resolve => setTimeout(resolve, 50)) - } - throw new Error(`Server did not respond at ${url}\n${logs}`) -} - describe('runtime env coercion with an inline schema', () => { it('builds without runtime secrets and serves coerced, event-scoped config', async () => { // validateAtRuntime turns build validation off by default, so the empty secret does not fail the build. diff --git a/test/runtime-transform.test.ts b/test/runtime-transform.test.ts index e963ef4..7ef5ac6 100644 --- a/test/runtime-transform.test.ts +++ b/test/runtime-transform.test.ts @@ -4,6 +4,7 @@ import { join } from 'node:path' import { fileURLToPath, pathToFileURL } from 'node:url' import { afterEach, describe, expect, it } from 'vitest' import { getFreePort } from './utils/free-port' +import { waitForResponse } from './utils/server' const fixtureDir = fileURLToPath(new URL('./fixtures/runtime-transform', import.meta.url)) const nuxtBin = fileURLToPath(new URL('../node_modules/nuxt/bin/nuxt.mjs', import.meta.url)) @@ -16,25 +17,6 @@ afterEach(() => { children.length = 0 }) -async function waitForResponse(url: string, child: ReturnType): Promise { - let logs = '' - child.stdout?.on('data', chunk => logs += chunk.toString()) - child.stderr?.on('data', chunk => logs += chunk.toString()) - - for (let attempt = 0; attempt < 100; attempt++) { - try { - const response = await fetch(url) - if (response.ok) - return response - } - catch {} - if (child.exitCode !== null) - throw new Error(`Server exited with code ${child.exitCode}\n${logs}`) - await new Promise(resolve => setTimeout(resolve, 50)) - } - throw new Error(`Server did not respond at ${url}\n${logs}`) -} - describe('runtime Standard Schema transformations', () => { it('preserves async schema output after string environment overrides', async () => { const build = spawnSync(process.execPath, [nuxtBin, 'build'], { diff --git a/test/runtime-validation.test.ts b/test/runtime-validation.test.ts index 18c706d..9477472 100644 --- a/test/runtime-validation.test.ts +++ b/test/runtime-validation.test.ts @@ -1,3 +1,4 @@ +import { type } from 'arktype' import { describe, expect, it, vi } from 'vitest' import { applyValidatedRuntimeConfig, mergeTransformedRuntimeConfig, useValidatedRuntimeConfig } from '../src/runtime/config-state' import { validateRuntimeConfig } from '../src/runtime/validate' @@ -38,6 +39,16 @@ describe('standard Schema runtime validation', () => { }) }) + it('validates callable ArkType schemas', () => { + const schema = type({ secretKey: 'string' }) + + expect(validateRuntimeConfig({ secretKey: 'test-secret' }, schema, 'ignore', logger)).toEqual({ + success: true, + value: { secretKey: 'test-secret' }, + }) + expect(validateRuntimeConfig({ secretKey: 1 }, schema, 'ignore', logger)).toEqual({ success: false }) + }) + it('keeps exact validated output when Nitro config is frozen', () => { const rawConfig = Object.freeze({ enabled: 'true', app: Object.freeze({ baseURL: '/' }) }) const output = { enabled: true } @@ -74,7 +85,7 @@ describe('standard Schema runtime validation', () => { }) }) - it('preserves raw config after ignored validation issues', () => { + it('reports failure without throwing when onError is ignore', () => { const schema = { '~standard': { version: 1 as const, diff --git a/test/utils/free-port.ts b/test/utils/free-port.ts index 4bd8e54..a13d2e2 100644 --- a/test/utils/free-port.ts +++ b/test/utils/free-port.ts @@ -1,7 +1,7 @@ import type { AddressInfo } from 'node:net' import { createServer } from 'node:net' -// Test files run in parallel next to @nuxt/test-utils servers on random ports, so a fixed port can already be taken. +// Test files start servers in parallel, so a fixed port can already be taken. export function getFreePort(): Promise { return new Promise((resolve, reject) => { const server = createServer() diff --git a/test/utils/server.ts b/test/utils/server.ts new file mode 100644 index 0000000..8768138 --- /dev/null +++ b/test/utils/server.ts @@ -0,0 +1,20 @@ +import type { spawn } from 'node:child_process' + +export async function waitForResponse(url: string, child: ReturnType): Promise { + let logs = '' + child.stdout?.on('data', chunk => logs += chunk.toString()) + child.stderr?.on('data', chunk => logs += chunk.toString()) + + for (let attempt = 0; attempt < 100; attempt++) { + try { + const response = await fetch(url) + if (response.ok) + return response + } + catch {} + if (child.exitCode !== null) + throw new Error(`Server exited with code ${child.exitCode}\n${logs}`) + await new Promise(resolve => setTimeout(resolve, 50)) + } + throw new Error(`Server did not respond at ${url}\n${logs}`) +} diff --git a/test/validation.test.ts b/test/validation.test.ts index a473614..1d6e33c 100644 --- a/test/validation.test.ts +++ b/test/validation.test.ts @@ -2,7 +2,7 @@ import { execSync, spawnSync } from 'node:child_process' import { existsSync, readFileSync, rmSync } from 'node:fs' import { join } from 'node:path' import { fileURLToPath } from 'node:url' -import { setup } from '@nuxt/test-utils/e2e' +import { Validator } from '@cfworker/json-schema' import { number, object, optional, string } from 'valibot' import { describe, expect, it } from 'vitest' import { z } from 'zod' @@ -23,66 +23,33 @@ const valibotRuntimeConfigSchema = object({ port: optional(number()), }) +function fixturePath(name: string): string { + return fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url)) +} + function cleanNuxtBuildOutputs(fixtureDir: string): void { rmSync(join(fixtureDir, '.nuxt'), { recursive: true, force: true }) rmSync(join(fixtureDir, '.output'), { recursive: true, force: true }) rmSync(join(fixtureDir, 'node_modules/.cache/nuxt'), { recursive: true, force: true }) } -async function createRuntimeValidationTemplate($schema: Parameters[0]['$schema']) { - const options = await resolveValidationOptions({ $schema, validateAtRuntime: true }) - const artifacts = await createRuntimeValidationArtifacts( - options, - () => {}, - ) - - expect(artifacts).not.toBeNull() - - return { - draft: artifacts!.draft, - onError: options.onError, - schema: artifacts!.jsonSchema, - } +function buildNuxt(fixtureDir: string) { + cleanNuxtBuildOutputs(fixtureDir) + const result = spawnSync('pnpm', ['nuxi', 'build'], { cwd: fixtureDir, encoding: 'utf8' }) + return { status: result.status, output: `${result.stdout}\n${result.stderr}` } } describe('build-time validation', () => { - it('validates successfully with valid hardcoded config (Valibot)', async () => { - await setup({ - rootDir: fileURLToPath(new URL('./fixtures/validation-success', import.meta.url)), - }) - expect(true).toBe(true) - }, 30000) + it('sets up without a schema', () => { + const fixtureDir = fixturePath('no-config') - it('skips validation when no schema provided', async () => { - await setup({ - rootDir: fileURLToPath(new URL('./fixtures/no-config', import.meta.url)), - }) - expect(true).toBe(true) - }, 30000) - - it('validates after merging .env variables', async () => { - await setup({ - rootDir: fileURLToPath(new URL('./fixtures/env-var-validation', import.meta.url)), - }) - expect(true).toBe(true) - }, 30000) - - it('validates with Zod native JSON Schema (build-time)', async () => { - await setup({ - rootDir: fileURLToPath(new URL('./fixtures/zod-native', import.meta.url)), - }) - expect(true).toBe(true) - }, 30000) + execSync('pnpm nuxi prepare', { cwd: fixtureDir, stdio: 'pipe' }) - it('validates with ArkType callable Standard Schema', async () => { - await setup({ - rootDir: fileURLToPath(new URL('./fixtures/arktype', import.meta.url)), - }) - expect(true).toBe(true) + expect(existsSync(join(fixtureDir, '.nuxt'))).toBe(true) }, 30000) it('does not validate during prepare', () => { - const fixtureDir = fileURLToPath(new URL('./fixtures/validation-failure', import.meta.url)) + const fixtureDir = fixturePath('validation-failure') execSync('pnpm nuxi prepare', { cwd: fixtureDir, stdio: 'pipe' }) @@ -90,123 +57,60 @@ describe('build-time validation', () => { }, 30000) it('fails Nuxt build validation through the Nitro module', () => { - const fixtureDir = fileURLToPath(new URL('./fixtures/validation-failure', import.meta.url)) - cleanNuxtBuildOutputs(fixtureDir) + const { status, output } = buildNuxt(fixturePath('validation-failure')) - const result = spawnSync('pnpm', ['nuxi', 'build'], { - cwd: fixtureDir, - encoding: 'utf8', - }) - - expect(result.status).not.toBe(0) - expect(`${result.stdout}\n${result.stderr}`).toContain('Runtime config validation failed') + expect(status).not.toBe(0) + expect(output).toContain('Runtime config validation failed') }, 60000) }) describe('runtime JSON Schema generation', () => { - it('uses portable runtime imports and types the value consumers receive', async () => { - const rootDir = fileURLToPath(new URL('.', import.meta.url)) + it('types transformed output only when runtime validation applies it', async () => { const options = await resolveValidationOptions({ $schema: './fixtures/runtime-transform/schema', validateAtBuild: false, validateAtRuntime: true, - }, rootDir) - const runtimeArtifacts = await createRuntimeValidationArtifacts(options, () => {}) - - expect(runtimeArtifacts!.validateTemplate).toContain('import runtimeSchema from \'#safe-runtime-config/runtime-schema\'') - expect(runtimeArtifacts!.validateTemplate).not.toContain(options.schemaPath!) - expect(runtimeArtifacts!.typeDeclaration).toContain('StandardSchemaV1.InferOutput') - - const buildOnlyArtifacts = await createRuntimeValidationArtifacts( - { ...options, validateAtRuntime: false }, - () => {}, - ) - expect(buildOnlyArtifacts!.typeDeclaration).toContain('StandardSchemaV1.InferInput') - // Transforms have no JSON Schema form, so this schema module receives raw values. - expect(runtimeArtifacts!.validateTemplate).toContain('export const coercionSchema = null\n') - }) + }, fileURLToPath(new URL('.', import.meta.url))) + + const runtime = await createRuntimeValidationArtifacts(options, () => {}) + const buildOnly = await createRuntimeValidationArtifacts({ ...options, validateAtRuntime: false }, () => {}) - it('exports the coercion schema in the runtime validation template', async () => { - const inline = await createRuntimeValidationArtifacts( - await resolveValidationOptions({ $schema: valibotRuntimeConfigSchema, validateAtRuntime: true }), - () => {}, - ) - expect(inline!.validateTemplate).toContain('export const coercionSchema = schema\n') - - const buildOnly = await createRuntimeValidationArtifacts( - await resolveValidationOptions({ $schema: valibotRuntimeConfigSchema }), - () => {}, - ) - expect(buildOnly!.validateTemplate).toContain('export const coercionSchema = null\n') + expect(runtime!.typeDeclaration).toContain('StandardSchemaV1.InferOutput') + expect(buildOnly!.typeDeclaration).toContain('StandardSchemaV1.InferInput') }) it('builds a Nuxt app with Nitro-owned runtime validation artifacts', () => { - const fixtureDir = fileURLToPath(new URL('./fixtures/runtime-invalid', import.meta.url)) - cleanNuxtBuildOutputs(fixtureDir) - - execSync('pnpm nuxi build', { cwd: fixtureDir, stdio: 'pipe' }) + const fixtureDir = fixturePath('runtime-invalid') + const { status, output } = buildNuxt(fixtureDir) + expect(status, output).toBe(0) const serverEntry = join(fixtureDir, '.output/server/index.mjs') const nitroChunk = join(fixtureDir, '.output/server/chunks/nitro/nitro.mjs') - expect(existsSync(serverEntry)).toBe(true) - const serverOutput = `${readFileSync(serverEntry, 'utf-8')}\n${readFileSync(nitroChunk, 'utf-8')}` expect(serverOutput).not.toContain('nitropack/runtime') expect(serverOutput).not.toContain('#nitro-internal-virtual') }, 60000) - it('generates runtime validation template (Zod native)', async () => { - const { draft, onError, schema } = await createRuntimeValidationTemplate(zodRuntimeConfigSchema) - - expect(schema).toHaveProperty('type', 'object') - expect(schema).toHaveProperty('properties') - expect(schema.properties).toHaveProperty('secretKey') - expect(schema.properties).toHaveProperty('public') - expect(draft).toBe('2020-12') - expect(onError).toBe('throw') - }, 30000) - - it('generates runtime validation template (Valibot fallback)', async () => { - const { draft, onError, schema } = await createRuntimeValidationTemplate(valibotRuntimeConfigSchema) - - expect(schema).toHaveProperty('type', 'object') - expect(schema).toHaveProperty('properties') - expect(draft).toBe('7') - expect(onError).toBe('throw') - }, 30000) - - it('zod native JSON Schema validates correctly', async () => { - const { Validator } = await import('@cfworker/json-schema') - const { draft, schema } = await createRuntimeValidationTemplate(zodRuntimeConfigSchema) - - const validator = new Validator(schema, draft as any) - const validConfig = { secretKey: 'test-key', public: { apiBase: 'https://api.test.com' } } - expect(validator.validate(validConfig).valid).toBe(true) - const invalidConfig = { secretKey: 123, public: { apiBase: 'https://api.test.com' } } - expect(validator.validate(invalidConfig).valid).toBe(false) - }, 30000) - - it('valibot fallback JSON Schema validates correctly', async () => { - const { Validator } = await import('@cfworker/json-schema') - const { draft, schema } = await createRuntimeValidationTemplate(valibotRuntimeConfigSchema) - - const validator = new Validator(schema, draft as any) - const validConfig = { secretKey: 'test-key', public: { apiBase: 'https://api.test.com' } } - expect(validator.validate(validConfig).valid).toBe(true) - const invalidConfig = { secretKey: 123, public: { apiBase: 'https://api.test.com' } } - expect(validator.validate(invalidConfig).valid).toBe(false) - }, 30000) + it.each([ + ['Zod native', zodRuntimeConfigSchema, '2020-12'], + ['Valibot fallback', valibotRuntimeConfigSchema, '7'], + ] as const)('emits a %s JSON Schema with a matching draft', async (_name, $schema, expectedDraft) => { + const options = await resolveValidationOptions({ $schema, validateAtRuntime: true }) + const { draft, jsonSchema } = (await createRuntimeValidationArtifacts(options, () => {}))! + const validator = new Validator(jsonSchema, draft) + + expect(options.onError).toBe('throw') + expect(draft).toBe(expectedDraft) + expect(validator.validate({ secretKey: 'test-key', public: { apiBase: 'https://api.test.com' } }).valid).toBe(true) + expect(validator.validate({ secretKey: 123, public: { apiBase: 'https://api.test.com' } }).valid).toBe(false) + }) - it('registers typed useSafeRuntimeConfig in server context', async () => { - const fixtureDir = fileURLToPath(new URL('./fixtures/server-typing', import.meta.url)) + it('registers typed useSafeRuntimeConfig in server context', () => { + const fixtureDir = fixturePath('server-typing') - await setup({ rootDir: fixtureDir }) execSync('pnpm nuxi prepare', { cwd: fixtureDir, stdio: 'pipe' }) - const nitroImportsPath = join(fixtureDir, '.nuxt/types/nitro-imports.d.ts') - expect(existsSync(nitroImportsPath)).toBe(true) - - const nitroImports = readFileSync(nitroImportsPath, 'utf-8') + const nitroImports = readFileSync(join(fixtureDir, '.nuxt/types/nitro-imports.d.ts'), 'utf-8') expect(nitroImports).toContain('useSafeRuntimeConfig') execSync('pnpm exec vue-tsc --noEmit --skipLibCheck -p .nuxt/tsconfig.server.json', { diff --git a/test/well-known-skill.test.ts b/test/well-known-skill.test.ts new file mode 100644 index 0000000..0be47be --- /dev/null +++ b/test/well-known-skill.test.ts @@ -0,0 +1,12 @@ +import { readFileSync } from 'node:fs' +import { describe, expect, it } from 'vitest' + +describe('well-known skill', () => { + it('serves the same skill at the compatibility path', () => { + const skillsDir = new URL('../docs/public/.well-known/skills/', import.meta.url) + const skill = readFileSync(new URL('nuxt-safe-runtime-config/SKILL.md', skillsDir), 'utf8') + const compatibilitySkill = readFileSync(new URL('SKILL.md', skillsDir), 'utf8') + + expect(compatibilitySkill).toBe(skill) + }) +})