@@ -5,8 +5,8 @@ const fjs = require('..')
5
5
const fs = require ( 'fs' )
6
6
const path = require ( 'path' )
7
7
8
- function build ( opts ) {
9
- return fjs ( {
8
+ function build ( opts , schema ) {
9
+ return fjs ( schema || {
10
10
title : 'default string' ,
11
11
type : 'object' ,
12
12
properties : {
@@ -21,10 +21,10 @@ function build (opts) {
21
21
const tmpDir = 'test/fixtures'
22
22
23
23
test ( 'activate standalone mode' , async ( t ) => {
24
- t . plan ( 2 )
25
- let code = build ( { mode : 'standalone' } )
24
+ t . plan ( 3 )
25
+ const code = build ( { mode : 'standalone' } )
26
26
t . type ( code , 'string' )
27
- code = code . replace ( / f a s t - j s o n - s t r i n g i f y / g , '../..' )
27
+ t . equal ( code . indexOf ( 'ajv' ) , - 1 )
28
28
29
29
const destionation = path . resolve ( tmpDir , 'standalone.js' )
30
30
@@ -36,3 +36,86 @@ test('activate standalone mode', async (t) => {
36
36
const standalone = require ( destionation )
37
37
t . same ( standalone ( { firstName : 'Foo' , surname : 'bar' } ) , JSON . stringify ( { firstName : 'Foo' } ) , 'surname evicted' )
38
38
} )
39
+
40
+ test ( 'test ajv schema' , async ( t ) => {
41
+ t . plan ( 3 )
42
+ const code = build ( { mode : 'standalone' } , {
43
+ type : 'object' ,
44
+ properties : {
45
+ } ,
46
+ if : {
47
+ type : 'object' ,
48
+ properties : {
49
+ kind : { type : 'string' , enum : [ 'foobar' ] }
50
+ }
51
+ } ,
52
+ then : {
53
+ type : 'object' ,
54
+ properties : {
55
+ kind : { type : 'string' , enum : [ 'foobar' ] } ,
56
+ foo : { type : 'string' } ,
57
+ bar : { type : 'number' } ,
58
+ list : {
59
+ type : 'array' ,
60
+ items : {
61
+ type : 'object' ,
62
+ properties : {
63
+ name : { type : 'string' } ,
64
+ value : { type : 'string' }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ } ,
70
+ else : {
71
+ type : 'object' ,
72
+ properties : {
73
+ kind : { type : 'string' , enum : [ 'greeting' ] } ,
74
+ hi : { type : 'string' } ,
75
+ hello : { type : 'number' } ,
76
+ list : {
77
+ type : 'array' ,
78
+ items : {
79
+ type : 'object' ,
80
+ properties : {
81
+ name : { type : 'string' } ,
82
+ value : { type : 'string' }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ } )
89
+ t . type ( code , 'string' )
90
+ t . equal ( code . indexOf ( 'ajv' ) > 0 , true )
91
+
92
+ const destionation = path . resolve ( tmpDir , 'standalone2.js' )
93
+
94
+ t . teardown ( async ( ) => {
95
+ await fs . promises . rm ( destionation , { force : true } )
96
+ } )
97
+
98
+ await fs . promises . writeFile ( destionation , code )
99
+ const standalone = require ( destionation )
100
+ t . same ( standalone ( {
101
+ kind : 'foobar' ,
102
+ foo : 'FOO' ,
103
+ list : [ {
104
+ name : 'name' ,
105
+ value : 'foo'
106
+ } ] ,
107
+ bar : 42 ,
108
+ hi : 'HI' ,
109
+ hello : 45 ,
110
+ a : 'A' ,
111
+ b : 35
112
+ } ) , JSON . stringify ( {
113
+ kind : 'foobar' ,
114
+ foo : 'FOO' ,
115
+ bar : 42 ,
116
+ list : [ {
117
+ name : 'name' ,
118
+ value : 'foo'
119
+ } ]
120
+ } ) )
121
+ } )
0 commit comments