11import { spawn } from 'node:child_process' ;
22import { EventEmitter } from 'node:events' ;
33import { OpenApiToolsGenerator } from './openapi-tools-generator' ;
4- import { buildCommandArgs } from './utils/build-command' ;
5- import { GeneratorContext } from '@nx-plugin-openapi/core' ;
4+ import {
5+ buildCommandArgs ,
6+ OpenApiGeneratorOptions ,
7+ } from './utils/build-command' ;
8+ import { GenerateOptionsBase , GeneratorContext } from '@nx-plugin-openapi/core' ;
69
710// Mock node:child_process
811jest . mock ( 'node:child_process' , ( ) => ( {
@@ -14,10 +17,17 @@ jest.mock('./utils/build-command', () => ({
1417 buildCommandArgs : jest . fn ( ) ,
1518} ) ) ;
1619
20+ type MockChildProcess = EventEmitter & { on : jest . Mock } ;
21+ type GeneratorWithCleanOutput = {
22+ cleanOutput : ( ...args : unknown [ ] ) => unknown ;
23+ } ;
24+
1725describe ( 'OpenApiToolsGenerator' , ( ) => {
1826 let generator : OpenApiToolsGenerator ;
1927 let mockContext : GeneratorContext ;
20- let mockChildProcess : any ;
28+ let mockChildProcess : MockChildProcess ;
29+ let generatorWithCleanOutput : GeneratorWithCleanOutput ;
30+ let cleanOutputSpy : jest . SpyInstance ;
2131
2232 beforeEach ( ( ) => {
2333 jest . clearAllMocks ( ) ;
@@ -28,7 +38,7 @@ describe('OpenApiToolsGenerator', () => {
2838 } ;
2939
3040 // Create a mock child process
31- mockChildProcess = new EventEmitter ( ) ;
41+ mockChildProcess = new EventEmitter ( ) as MockChildProcess ;
3242 mockChildProcess . on = jest . fn ( mockChildProcess . on . bind ( mockChildProcess ) ) ;
3343 ( spawn as jest . Mock ) . mockReturnValue ( mockChildProcess ) ;
3444
@@ -42,7 +52,10 @@ describe('OpenApiToolsGenerator', () => {
4252 ] ) ;
4353
4454 // Mock cleanOutput method
45- jest . spyOn ( generator as any , 'cleanOutput' ) . mockImplementation ( ( ) => { } ) ;
55+ generatorWithCleanOutput = generator as unknown as GeneratorWithCleanOutput ;
56+ cleanOutputSpy = jest
57+ . spyOn ( generatorWithCleanOutput , 'cleanOutput' )
58+ . mockImplementation ( ( ) => { } ) ;
4659 } ) ;
4760
4861 describe ( 'name' , ( ) => {
@@ -69,7 +82,7 @@ describe('OpenApiToolsGenerator', () => {
6982
7083 await generatePromise ;
7184
72- expect ( ( generator as any ) . cleanOutput ) . toHaveBeenCalledWith (
85+ expect ( cleanOutputSpy ) . toHaveBeenCalledWith (
7386 mockContext ,
7487 'src/generated'
7588 ) ;
@@ -176,31 +189,31 @@ describe('OpenApiToolsGenerator', () => {
176189 generatorOptions : {
177190 generator : 'typescript-axios' ,
178191 } ,
179- } as any ;
192+ } as unknown as OpenApiGeneratorOptions & GenerateOptionsBase ;
180193
181194 const generatePromise = generator . generate ( options , mockContext ) ;
182195
183196 // Simulate successful execution for all three
184197 const emitClose = ( ) => mockChildProcess . emit ( 'close' , 0 ) ;
185198 await emitClose ( ) ;
186- await new Promise ( resolve => setTimeout ( resolve , 0 ) ) ;
199+ await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
187200 await emitClose ( ) ;
188- await new Promise ( resolve => setTimeout ( resolve , 0 ) ) ;
201+ await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
189202 await emitClose ( ) ;
190203
191204 await generatePromise ;
192205
193206 // Should clean output for each service
194- expect ( ( generator as any ) . cleanOutput ) . toHaveBeenCalledTimes ( 3 ) ;
195- expect ( ( generator as any ) . cleanOutput ) . toHaveBeenCalledWith (
207+ expect ( cleanOutputSpy ) . toHaveBeenCalledTimes ( 3 ) ;
208+ expect ( cleanOutputSpy ) . toHaveBeenCalledWith (
196209 mockContext ,
197210 'src/api/users'
198211 ) ;
199- expect ( ( generator as any ) . cleanOutput ) . toHaveBeenCalledWith (
212+ expect ( cleanOutputSpy ) . toHaveBeenCalledWith (
200213 mockContext ,
201214 'src/api/products'
202215 ) ;
203- expect ( ( generator as any ) . cleanOutput ) . toHaveBeenCalledWith (
216+ expect ( cleanOutputSpy ) . toHaveBeenCalledWith (
204217 mockContext ,
205218 'src/api/orders'
206219 ) ;
@@ -234,7 +247,7 @@ describe('OpenApiToolsGenerator', () => {
234247 products : 'products.yaml' ,
235248 } ,
236249 outputPath : 'src/api' ,
237- } as any ;
250+ } as unknown as OpenApiGeneratorOptions & GenerateOptionsBase ;
238251
239252 const generatePromise = generator . generate ( options , mockContext ) ;
240253
@@ -254,7 +267,7 @@ describe('OpenApiToolsGenerator', () => {
254267 'product-service' : 'specs/products.yaml' ,
255268 } ,
256269 outputPath : 'generated' ,
257- } as any ;
270+ } as unknown as OpenApiGeneratorOptions & GenerateOptionsBase ;
258271
259272 const generatePromise = generator . generate ( options , mockContext ) ;
260273
0 commit comments