@@ -123,6 +123,94 @@ describe('Jasmine to Vitest Schematic', () => {
123123 expect ( logs . some ( ( log ) => log . includes ( 'Transformed `spyOn` to `vi.spyOn`' ) ) ) . toBe ( true ) ;
124124 } ) ;
125125
126+ describe ( 'with `include` option' , ( ) => {
127+ beforeEach ( ( ) => {
128+ // Create a nested structure for testing directory-specific inclusion
129+ appTree . create (
130+ 'projects/bar/src/app/nested/nested.spec.ts' ,
131+ `describe('Nested', () => { it('should work', () => { spyOn(window, 'confirm'); }); });` ,
132+ ) ;
133+ appTree . overwrite (
134+ 'projects/bar/src/app/app.spec.ts' ,
135+ `describe('App', () => { it('should work', () => { spyOn(window, 'alert'); }); });` ,
136+ ) ;
137+ } ) ;
138+
139+ it ( 'should only transform the specified file' , async ( ) => {
140+ const tree = await schematicRunner . runSchematic (
141+ 'jasmine-to-vitest' ,
142+ { project : 'bar' , include : 'src/app/nested/nested.spec.ts' } ,
143+ appTree ,
144+ ) ;
145+
146+ const changedContent = tree . readContent ( 'projects/bar/src/app/nested/nested.spec.ts' ) ;
147+ expect ( changedContent ) . toContain ( `vi.spyOn(window, 'confirm');` ) ;
148+
149+ const unchangedContent = tree . readContent ( 'projects/bar/src/app/app.spec.ts' ) ;
150+ expect ( unchangedContent ) . toContain ( `spyOn(window, 'alert');` ) ;
151+ } ) ;
152+
153+ it ( 'should handle a Windows-style path' , async ( ) => {
154+ const tree = await schematicRunner . runSchematic (
155+ 'jasmine-to-vitest' ,
156+ { project : 'bar' , include : 'src\\app\\nested\\nested.spec.ts' } ,
157+ appTree ,
158+ ) ;
159+
160+ const changedContent = tree . readContent ( 'projects/bar/src/app/nested/nested.spec.ts' ) ;
161+ expect ( changedContent ) . toContain ( `vi.spyOn(window, 'confirm');` ) ;
162+
163+ const unchangedContent = tree . readContent ( 'projects/bar/src/app/app.spec.ts' ) ;
164+ expect ( unchangedContent ) . toContain ( `spyOn(window, 'alert');` ) ;
165+ } ) ;
166+
167+ it ( 'should only transform files in the specified directory' , async ( ) => {
168+ appTree . create (
169+ 'projects/bar/src/other/other.spec.ts' ,
170+ `describe('Other', () => { it('should work', () => { spyOn(window, 'close'); }); });` ,
171+ ) ;
172+
173+ const tree = await schematicRunner . runSchematic (
174+ 'jasmine-to-vitest' ,
175+ { project : 'bar' , include : 'src/app' } ,
176+ appTree ,
177+ ) ;
178+
179+ const changedAppContent = tree . readContent ( 'projects/bar/src/app/app.spec.ts' ) ;
180+ expect ( changedAppContent ) . toContain ( `vi.spyOn(window, 'alert');` ) ;
181+
182+ const changedNestedContent = tree . readContent ( 'projects/bar/src/app/nested/nested.spec.ts' ) ;
183+ expect ( changedNestedContent ) . toContain ( `vi.spyOn(window, 'confirm');` ) ;
184+
185+ const unchangedContent = tree . readContent ( 'projects/bar/src/other/other.spec.ts' ) ;
186+ expect ( unchangedContent ) . toContain ( `spyOn(window, 'close');` ) ;
187+ } ) ;
188+
189+ it ( 'should process all files if `include` is not provided' , async ( ) => {
190+ const tree = await schematicRunner . runSchematic (
191+ 'jasmine-to-vitest' ,
192+ { project : 'bar' } ,
193+ appTree ,
194+ ) ;
195+
196+ const changedAppContent = tree . readContent ( 'projects/bar/src/app/app.spec.ts' ) ;
197+ expect ( changedAppContent ) . toContain ( `vi.spyOn(window, 'alert');` ) ;
198+
199+ const changedNestedContent = tree . readContent ( 'projects/bar/src/app/nested/nested.spec.ts' ) ;
200+ expect ( changedNestedContent ) . toContain ( `vi.spyOn(window, 'confirm');` ) ;
201+ } ) ;
202+
203+ it ( 'should throw if the include path does not exist' , async ( ) => {
204+ await expectAsync (
205+ schematicRunner . runSchematic (
206+ 'jasmine-to-vitest' ,
207+ { project : 'bar' , include : 'src/non-existent' } ,
208+ appTree ,
209+ ) ,
210+ ) . toBeRejectedWithError ( `The specified include path 'src/non-existent' does not exist.` ) ;
211+ } ) ;
212+ } ) ;
213+
126214 it ( 'should print a summary report after running' , async ( ) => {
127215 const specFilePath = 'projects/bar/src/app/app.spec.ts' ;
128216 const content = `
@@ -138,7 +226,7 @@ describe('Jasmine to Vitest Schematic', () => {
138226 const logs : string [ ] = [ ] ;
139227 schematicRunner . logger . subscribe ( ( entry ) => logs . push ( entry . message ) ) ;
140228
141- await schematicRunner . runSchematic ( 'jasmine-to-vitest' , { include : specFilePath } , appTree ) ;
229+ await schematicRunner . runSchematic ( 'jasmine-to-vitest' , { } , appTree ) ;
142230
143231 expect ( logs ) . toContain ( 'Jasmine to Vitest Refactoring Summary:' ) ;
144232 expect ( logs ) . toContain ( '- 1 test file(s) scanned.' ) ;
0 commit comments