Skip to content

Commit a5c42b9

Browse files
committed
test: Zod and AJV
1 parent 3171aa4 commit a5c42b9

File tree

4 files changed

+167
-145
lines changed

4 files changed

+167
-145
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@nuxt/module-builder": "^1.0.1",
6565
"@nuxt/test-utils": "^3.19.2",
6666
"@nuxtjs/eslint-config-typescript": "^12.1.0",
67+
"ajv": "^8.17.1",
6768
"changelogen": "^0.6.2",
6869
"eslint": "^9.31.0",
6970
"jiti": "^2.4.2",

pnpm-lock.yaml

Lines changed: 37 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/parser.test.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { describe, test, expect } from 'vitest'
22
import { getComponentMeta } from '../src/parser'
33
import { propsToJsonSchema } from '../src/utils/schema'
4-
import { jsonSchemaToZod } from 'json-schema-to-zod'
54

65
describe('ComponentMetaParser', () => {
76
test('should be able to fetch component meta', async () => {
@@ -17,50 +16,6 @@ describe('ComponentMetaParser', () => {
1716
expect(propsNames).toContain('numberProp')
1817
})
1918

20-
test('whole', async () => {
21-
const meta = getComponentMeta('playground/components/TestComponent.vue')
22-
const jsonSchema = propsToJsonSchema(meta.props)
23-
const zod = jsonSchemaToZod(jsonSchema, { module: "cjs" })
24-
25-
const data = [
26-
{
27-
match: true,
28-
data: {
29-
name: 'nuxt-component-meta',
30-
foo: 'bar',
31-
hello: 'world',
32-
booleanProp: true,
33-
numberProp: 42,
34-
data: {
35-
gello: "Gello"
36-
}
37-
}
38-
},
39-
{
40-
match: false,
41-
data: {
42-
name: 'nuxt-component-meta',
43-
foo: 12,
44-
hello: 'world',
45-
booleanProp: true,
46-
numberProp: 42,
47-
data: {
48-
gello: "Gello"
49-
}
50-
}
51-
}
52-
]
53-
54-
for (const item of data) {
55-
const schema = eval(zod)
56-
if (item.match) {
57-
schema.parse(item.data)
58-
} else {
59-
expect(() => schema.parse(data)).toThrow()
60-
}
61-
}
62-
})
63-
6419
test('propsToJsonSchema should convert props to JSON Schema format', async () => {
6520
const meta = getComponentMeta('playground/components/TestComponent.vue')
6621
const jsonSchema = propsToJsonSchema(meta.props)
@@ -138,7 +93,7 @@ describe('ComponentMetaParser', () => {
13893
expect(jsonSchema.required).toEqual(['name'])
13994
})
14095

141-
test('manual', () => {
96+
test('TestD.vue', () => {
14297
const meta = getComponentMeta('playground/components/TestD.vue')
14398
const result = propsToJsonSchema(meta.props)
14499

0 commit comments

Comments
 (0)