11/* eslint-disable no-unused-expressions */
22import { expect } from "chai" ;
33import fs from "fs" ;
4+ import type { JSONSchema7 } from "json-schema" ;
45import path from "path" ;
56
67import generateShemaMixin from "../../src/js/generateSchemaMixin" ;
78
89describe ( "generateSchemaMixin Tests" , ( ) => {
910 const tempDir = path . join ( __dirname , "temp_test_output" ) ;
1011
11- beforeEach ( ( ) => {
12+ // Mock schemas for testing
13+ const mockSchemas : JSONSchema7 [ ] = [
14+ {
15+ $id : "property/holder" ,
16+ title : "Property Holder" ,
17+ type : "object" ,
18+ properties : {
19+ metadata : { type : "object" } ,
20+ name : { type : "string" } ,
21+ description : { type : "string" } ,
22+ } ,
23+ required : [ "name" ] ,
24+ } ,
25+ ] ;
26+
27+ beforeEach ( function setupTests ( ) {
28+ // Increase timeout to 10 seconds because generateShemaMixin runs ESLint autofix
29+ // which can take several seconds to complete, especially on first run
30+ this . timeout ( 10000 ) ;
1231 // Create a temporary directory for test files
1332 if ( ! fs . existsSync ( tempDir ) ) {
1433 fs . mkdirSync ( tempDir , { recursive : true } ) ;
@@ -41,7 +60,7 @@ describe("generateSchemaMixin Tests", () => {
4160 it ( "should handle empty output paths object" , ( ) => {
4261 const outputPaths = { } ;
4362
44- const result = generateShemaMixin ( outputPaths ) ;
63+ const result = generateShemaMixin ( mockSchemas , outputPaths ) ;
4564
4665 expect ( result . successCount ) . to . equal ( 0 ) ;
4766 expect ( result . errorCount ) . to . equal ( 0 ) ;
@@ -53,7 +72,7 @@ describe("generateSchemaMixin Tests", () => {
5372 "property/holder" : path . join ( nestedDir , "PropertyHolderSchemaMixin.ts" ) ,
5473 } ;
5574
56- generateShemaMixin ( outputPaths ) ;
75+ generateShemaMixin ( mockSchemas , outputPaths ) ;
5776
5877 // The function should attempt to create the directory
5978 expect ( fs . existsSync ( nestedDir ) ) . to . be . true ;
@@ -67,7 +86,7 @@ describe("generateSchemaMixin Tests", () => {
6786
6887 // This should not throw an error even if the schema doesn't exist
6988 expect ( ( ) => {
70- generateShemaMixin ( outputPaths , skipFields ) ;
89+ generateShemaMixin ( mockSchemas , outputPaths , skipFields ) ;
7190 } ) . to . not . throw ( ) ;
7291 } ) ;
7392 } ) ;
@@ -78,7 +97,7 @@ describe("generateSchemaMixin Tests", () => {
7897 "non/existent" : path . join ( tempDir , "NonExistentSchemaMixin.ts" ) ,
7998 } ;
8099
81- const result = generateShemaMixin ( outputPaths ) ;
100+ const result = generateShemaMixin ( mockSchemas , outputPaths ) ;
82101
83102 expect ( result . successCount ) . to . equal ( 0 ) ;
84103 expect ( result . errorCount ) . to . equal ( 1 ) ;
@@ -89,7 +108,7 @@ describe("generateSchemaMixin Tests", () => {
89108 "property/holder" : undefined as unknown as string ,
90109 } ;
91110
92- const result = generateShemaMixin ( outputPaths ) ;
111+ const result = generateShemaMixin ( mockSchemas , outputPaths ) ;
93112
94113 expect ( result . successCount ) . to . equal ( 0 ) ;
95114 expect ( result . errorCount ) . to . equal ( 1 ) ;
@@ -100,7 +119,7 @@ describe("generateSchemaMixin Tests", () => {
100119 "property/holder" : "" ,
101120 } ;
102121
103- const result = generateShemaMixin ( outputPaths ) ;
122+ const result = generateShemaMixin ( mockSchemas , outputPaths ) ;
104123
105124 expect ( result . successCount ) . to . equal ( 0 ) ;
106125 expect ( result . errorCount ) . to . equal ( 1 ) ;
@@ -111,7 +130,7 @@ describe("generateSchemaMixin Tests", () => {
111130 it ( "should return an object with successCount and errorCount" , ( ) => {
112131 const outputPaths = { } ;
113132
114- const result = generateShemaMixin ( outputPaths ) ;
133+ const result = generateShemaMixin ( mockSchemas , outputPaths ) ;
115134
116135 expect ( result ) . to . have . property ( "successCount" ) ;
117136 expect ( result ) . to . have . property ( "errorCount" ) ;
@@ -125,36 +144,44 @@ describe("generateSchemaMixin Tests", () => {
125144 "another/non/existent" : path . join ( tempDir , "AnotherNonExistentSchemaMixin.ts" ) ,
126145 } ;
127146
128- const result = generateShemaMixin ( outputPaths ) ;
147+ const result = generateShemaMixin ( mockSchemas , outputPaths ) ;
129148
130149 expect ( result . successCount ) . to . equal ( 0 ) ;
131150 expect ( result . errorCount ) . to . equal ( 2 ) ;
132151 } ) ;
133152 } ) ;
134153
135154 describe ( "generateShemaMixin - Function Interface" , ( ) => {
136- it ( "should accept outputPaths as first parameter" , ( ) => {
155+ it ( "should accept schemas as first parameter" , ( ) => {
137156 const outputPaths = { } ;
138157
139158 expect ( ( ) => {
140- generateShemaMixin ( outputPaths ) ;
159+ generateShemaMixin ( mockSchemas , outputPaths ) ;
141160 } ) . to . not . throw ( ) ;
142161 } ) ;
143162
144- it ( "should accept skipFields as optional second parameter" , ( ) => {
163+ it ( "should accept outputPaths as second parameter" , ( ) => {
164+ const outputPaths = { } ;
165+
166+ expect ( ( ) => {
167+ generateShemaMixin ( mockSchemas , outputPaths ) ;
168+ } ) . to . not . throw ( ) ;
169+ } ) ;
170+
171+ it ( "should accept skipFields as optional third parameter" , ( ) => {
145172 const outputPaths = { } ;
146173 const skipFields = [ "field1" , "field2" ] ;
147174
148175 expect ( ( ) => {
149- generateShemaMixin ( outputPaths , skipFields ) ;
176+ generateShemaMixin ( mockSchemas , outputPaths , skipFields ) ;
150177 } ) . to . not . throw ( ) ;
151178 } ) ;
152179
153180 it ( "should work without skipFields parameter" , ( ) => {
154181 const outputPaths = { } ;
155182
156183 expect ( ( ) => {
157- generateShemaMixin ( outputPaths ) ;
184+ generateShemaMixin ( mockSchemas , outputPaths ) ;
158185 } ) . to . not . throw ( ) ;
159186 } ) ;
160187 } ) ;
0 commit comments