@@ -35,9 +35,28 @@ import {
3535 removeAllChildren ,
3636 findElement
3737} from '../utils/codemodHelpers'
38- import { expect } from 'vitest'
38+ import { expect , type MockInstance , vi } from 'vitest'
3939
4040describe ( 'test codemod helpers' , ( ) => {
41+ let consoleLogMock : ReturnType < typeof vi . spyOn >
42+ let consoleWarningMock : ReturnType < typeof vi . spyOn >
43+
44+ beforeEach ( ( ) => {
45+ // Mocking console to prevent test output pollution
46+ // comment these out to see the test output
47+ consoleLogMock = vi
48+ . spyOn ( console , 'log' )
49+ . mockImplementation ( ( ) => { } ) as MockInstance
50+ consoleWarningMock = vi
51+ . spyOn ( console , 'warn' )
52+ . mockImplementation ( ( ) => { } ) as MockInstance
53+ } )
54+
55+ afterEach ( ( ) => {
56+ consoleLogMock . mockRestore ( )
57+ consoleWarningMock . mockRestore ( )
58+ } )
59+
4160 it ( 'test findElement' , ( ) => {
4261 // Test finding simple elements by tag name
4362 const source = `
@@ -536,7 +555,13 @@ import { Modal } from "@instructure/ui-modal";`)
536555 }
537556 `
538557 let root = j ( source )
539- let result = renameImportAndUsages ( j , root , 'oldName' , 'newName' , '@import-path' )
558+ let result = renameImportAndUsages (
559+ j ,
560+ root ,
561+ 'oldName' ,
562+ 'newName' ,
563+ '@import-path'
564+ )
540565
541566 expect ( result ) . toBe ( true )
542567 expect ( root . toSource ( ) ) . toBe ( `
@@ -562,7 +587,13 @@ import { Modal } from "@instructure/ui-modal";`)
562587 }
563588 `
564589 root = j ( source )
565- result = renameImportAndUsages ( j , root , 'oldName' , 'newName' , '@import-path' )
590+ result = renameImportAndUsages (
591+ j ,
592+ root ,
593+ 'oldName' ,
594+ 'newName' ,
595+ '@import-path'
596+ )
566597
567598 expect ( result ) . toBe ( true )
568599 expect ( root . toSource ( ) ) . toBe ( `
@@ -586,7 +617,13 @@ import { Modal } from "@instructure/ui-modal";`)
586617 }
587618 `
588619 root = j . withParser ( 'tsx' ) ( source )
589- result = renameImportAndUsages ( j , root , 'oldName' , 'newName' , '@import-path' )
620+ result = renameImportAndUsages (
621+ j ,
622+ root ,
623+ 'oldName' ,
624+ 'newName' ,
625+ '@import-path'
626+ )
590627
591628 expect ( result ) . toBe ( true )
592629 expect ( root . toSource ( ) ) . toBe ( `
@@ -609,7 +646,13 @@ import { Modal } from "@instructure/ui-modal";`)
609646 }
610647 `
611648 root = j ( source )
612- result = renameImportAndUsages ( j , root , 'oldName' , 'newName' , '@import-path' )
649+ result = renameImportAndUsages (
650+ j ,
651+ root ,
652+ 'oldName' ,
653+ 'newName' ,
654+ '@import-path'
655+ )
613656
614657 expect ( result ) . toBe ( true )
615658 expect ( root . toSource ( ) ) . toBe ( `
@@ -632,7 +675,13 @@ import { Modal } from "@instructure/ui-modal";`)
632675 `
633676 root = j ( source )
634677 const originalSource = root . toSource ( )
635- result = renameImportAndUsages ( j , root , 'oldName' , 'newName' , '@import-path' )
678+ result = renameImportAndUsages (
679+ j ,
680+ root ,
681+ 'oldName' ,
682+ 'newName' ,
683+ '@import-path'
684+ )
636685
637686 expect ( result ) . toBe ( false )
638687 expect ( root . toSource ( ) ) . toBe ( originalSource )
@@ -649,7 +698,13 @@ import { Modal } from "@instructure/ui-modal";`)
649698 }
650699 `
651700 root = j ( source )
652- result = renameImportAndUsages ( j , root , 'oldName' , 'newName' , '@import-path' )
701+ result = renameImportAndUsages (
702+ j ,
703+ root ,
704+ 'oldName' ,
705+ 'newName' ,
706+ '@import-path'
707+ )
653708
654709 expect ( result ) . toBe ( true )
655710 expect ( root . toSource ( ) ) . toBe ( `
@@ -673,7 +728,13 @@ import { Modal } from "@instructure/ui-modal";`)
673728 }
674729 `
675730 root = j ( source )
676- result = renameImportAndUsages ( j , root , 'oldName' , 'newName' , '@import-path' )
731+ result = renameImportAndUsages (
732+ j ,
733+ root ,
734+ 'oldName' ,
735+ 'newName' ,
736+ '@import-path'
737+ )
677738
678739 expect ( result ) . toBe ( true )
679740 expect ( root . toSource ( ) ) . toBe ( `
@@ -696,7 +757,13 @@ import { Modal } from "@instructure/ui-modal";`)
696757 }
697758 `
698759 root = j ( source )
699- result = renameImportAndUsages ( j , root , 'oldName' , 'newName' , '@import-path' )
760+ result = renameImportAndUsages (
761+ j ,
762+ root ,
763+ 'oldName' ,
764+ 'newName' ,
765+ '@import-path'
766+ )
700767
701768 expect ( result ) . toBe ( true )
702769 expect ( root . toSource ( ) ) . toBe ( `
@@ -723,7 +790,13 @@ import { Modal } from "@instructure/ui-modal";`)
723790 }
724791 `
725792 root = j ( source )
726- result = renameImportAndUsages ( j , root , 'Button' , 'PrimaryButton' , '@instructure/ui-buttons' )
793+ result = renameImportAndUsages (
794+ j ,
795+ root ,
796+ 'Button' ,
797+ 'PrimaryButton' ,
798+ '@instructure/ui-buttons'
799+ )
727800
728801 expect ( result ) . toBe ( true )
729802 expect ( root . toSource ( ) ) . toBe ( `
@@ -748,7 +821,13 @@ import { Modal } from "@instructure/ui-modal";`)
748821 }
749822 `
750823 root = j ( source )
751- result = renameImportAndUsages ( j , root , 'Button' , 'PrimaryButton' , '@instructure/ui-buttons' )
824+ result = renameImportAndUsages (
825+ j ,
826+ root ,
827+ 'Button' ,
828+ 'PrimaryButton' ,
829+ '@instructure/ui-buttons'
830+ )
752831
753832 expect ( result ) . toBe ( true )
754833 expect ( root . toSource ( ) ) . toBe ( `
@@ -769,7 +848,13 @@ import { Modal } from "@instructure/ui-modal";`)
769848 }
770849 `
771850 root = j ( source )
772- result = renameImportAndUsages ( j , root , 'Button' , 'PrimaryButton' , '@instructure/ui-buttons' )
851+ result = renameImportAndUsages (
852+ j ,
853+ root ,
854+ 'Button' ,
855+ 'PrimaryButton' ,
856+ '@instructure/ui-buttons'
857+ )
773858
774859 expect ( result ) . toBe ( true )
775860 expect ( root . toSource ( ) ) . toBe ( `
@@ -795,7 +880,13 @@ import { Modal } from "@instructure/ui-modal";`)
795880 }
796881 `
797882 root = j ( source )
798- result = renameImportAndUsages ( j , root , 'Button' , 'PrimaryButton' , '@instructure/ui-buttons' )
883+ result = renameImportAndUsages (
884+ j ,
885+ root ,
886+ 'Button' ,
887+ 'PrimaryButton' ,
888+ '@instructure/ui-buttons'
889+ )
799890
800891 expect ( result ) . toBe ( true )
801892 expect ( root . toSource ( ) ) . toBe ( `
@@ -826,7 +917,13 @@ import { Modal } from "@instructure/ui-modal";`)
826917 }
827918 `
828919 root = j ( source )
829- result = renameImportAndUsages ( j , root , 'Button' , 'PrimaryButton' , '@instructure/ui-buttons' )
920+ result = renameImportAndUsages (
921+ j ,
922+ root ,
923+ 'Button' ,
924+ 'PrimaryButton' ,
925+ '@instructure/ui-buttons'
926+ )
830927
831928 expect ( result ) . toBe ( false )
832929 expect ( root . toSource ( ) ) . toBe ( source )
0 commit comments