@@ -114,4 +114,61 @@ describe("writeLargeContentToFile", () => {
114114 const written = fs . readFileSync ( filepath , "utf8" ) ;
115115 expect ( written ) . toBe ( content ) ;
116116 } ) ;
117+
118+ it ( "should handle non-JSON content gracefully" , async ( ) => {
119+ const { writeLargeContentToFile } = await import ( "./write_large_content_to_file.cjs" ) ;
120+
121+ const content = "this is plain text, not JSON" ;
122+ const result = writeLargeContentToFile ( content ) ;
123+
124+ expect ( result . description ) . toBe ( "text content" ) ;
125+ const filepath = path . join ( testDir , result . filename ) ;
126+ expect ( fs . readFileSync ( filepath , "utf8" ) ) . toBe ( content ) ;
127+ } ) ;
128+
129+ it ( "should handle empty object" , async ( ) => {
130+ const { writeLargeContentToFile } = await import ( "./write_large_content_to_file.cjs" ) ;
131+
132+ const content = JSON . stringify ( { } ) ;
133+ const result = writeLargeContentToFile ( content ) ;
134+
135+ expect ( result . description ) . toBe ( "{}" ) ;
136+ } ) ;
137+
138+ it ( "should handle empty array" , async ( ) => {
139+ const { writeLargeContentToFile } = await import ( "./write_large_content_to_file.cjs" ) ;
140+
141+ const content = JSON . stringify ( [ ] ) ;
142+ const result = writeLargeContentToFile ( content ) ;
143+
144+ expect ( result . description ) . toBe ( "[]" ) ;
145+ } ) ;
146+
147+ it ( "should handle nested object (only top-level keys listed)" , async ( ) => {
148+ const { writeLargeContentToFile } = await import ( "./write_large_content_to_file.cjs" ) ;
149+
150+ const content = JSON . stringify ( { a : { b : 1 } , c : [ 1 , 2 ] } ) ;
151+ const result = writeLargeContentToFile ( content ) ;
152+
153+ expect ( result . description ) . toBe ( "{a, c}" ) ;
154+ } ) ;
155+
156+ it ( "should work when directory already exists" , async ( ) => {
157+ const { writeLargeContentToFile } = await import ( "./write_large_content_to_file.cjs" ) ;
158+
159+ fs . mkdirSync ( testDir , { recursive : true } ) ;
160+ expect ( fs . existsSync ( testDir ) ) . toBe ( true ) ;
161+
162+ const content = JSON . stringify ( { already : "there" } ) ;
163+ expect ( ( ) => writeLargeContentToFile ( content ) ) . not . toThrow ( ) ;
164+ } ) ;
165+
166+ it ( "should handle JSON primitive (number)" , async ( ) => {
167+ const { writeLargeContentToFile } = await import ( "./write_large_content_to_file.cjs" ) ;
168+
169+ const content = JSON . stringify ( 42 ) ;
170+ const result = writeLargeContentToFile ( content ) ;
171+
172+ expect ( result . description ) . toBe ( "number" ) ;
173+ } ) ;
117174} ) ;
0 commit comments