@@ -17,12 +17,9 @@ import {
17
17
isCallExpression ,
18
18
isImportDeclaration ,
19
19
isImportDefaultSpecifier ,
20
- isImportNamespaceSpecifier ,
21
20
isImportSpecifier ,
22
21
isLiteral ,
23
22
isMemberExpression ,
24
- isObjectPattern ,
25
- isProperty ,
26
23
} from '../node-utils' ;
27
24
import {
28
25
ABSENCE_MATCHERS ,
@@ -627,8 +624,15 @@ export function detectTestingLibraryUtils<
627
624
) ;
628
625
} ;
629
626
627
+ /**
628
+ * Determines whether a given node is some reportable `act` util.
629
+ *
630
+ * An `act` is reportable if some of these conditions is met:
631
+ * - it's related to Testing Library module (this depends on Aggressive Reporting)
632
+ * - it's related to React DOM Test Utils
633
+ */
630
634
const isActUtil = ( node : TSESTree . Identifier ) : boolean => {
631
- return isPotentialTestingLibraryFunction (
635
+ const isTestingLibraryAct = isPotentialTestingLibraryFunction (
632
636
node ,
633
637
( identifierNodeName , originalNodeName ) => {
634
638
return [ identifierNodeName , originalNodeName ]
@@ -637,7 +641,65 @@ export function detectTestingLibraryUtils<
637
641
}
638
642
) ;
639
643
640
- // TODO: check if `act` coming from 'react-dom/test-utils'
644
+ const isReactDomTestUtilsAct = ( ( ) => {
645
+ if ( ! importedReactDomTestUtilsNode ) {
646
+ return false ;
647
+ }
648
+ const referenceNode = getReferenceNode ( node ) ;
649
+ const referenceNodeIdentifier = getPropertyIdentifierNode (
650
+ referenceNode
651
+ ) ;
652
+ if ( ! referenceNodeIdentifier ) {
653
+ return false ;
654
+ }
655
+
656
+ const importedUtilSpecifier = findImportSpecifier (
657
+ node . name ,
658
+ importedReactDomTestUtilsNode
659
+ ) ;
660
+ if ( ! importedUtilSpecifier ) {
661
+ return false ;
662
+ }
663
+
664
+ const importDeclaration = ( ( ) => {
665
+ if ( isImportDeclaration ( importedUtilSpecifier . parent ) ) {
666
+ return importedUtilSpecifier . parent ;
667
+ }
668
+
669
+ const variableDeclarator = findClosestVariableDeclaratorNode (
670
+ importedUtilSpecifier
671
+ ) ;
672
+
673
+ if ( isCallExpression ( variableDeclarator ?. init ) ) {
674
+ return variableDeclarator ?. init ;
675
+ }
676
+
677
+ return undefined ;
678
+ } ) ( ) ;
679
+ if ( ! importDeclaration ) {
680
+ return false ;
681
+ }
682
+
683
+ const importDeclarationName = getImportModuleName ( importDeclaration ) ;
684
+ if ( ! importDeclarationName ) {
685
+ return false ;
686
+ }
687
+
688
+ if ( importDeclarationName !== REACT_DOM_TEST_UTILS_PACKAGE ) {
689
+ return false ;
690
+ }
691
+
692
+ const originalNodeName =
693
+ isImportSpecifier ( importedUtilSpecifier ) &&
694
+ importedUtilSpecifier . local . name !==
695
+ importedUtilSpecifier . imported . name
696
+ ? importedUtilSpecifier . imported . name
697
+ : undefined ;
698
+
699
+ return [ node . name , originalNodeName ] . filter ( Boolean ) . includes ( 'act' ) ;
700
+ } ) ( ) ;
701
+
702
+ return isTestingLibraryAct || isReactDomTestUtilsAct ;
641
703
} ;
642
704
643
705
const isTestingLibraryUtil = ( node : TSESTree . Identifier ) : boolean => {
@@ -938,6 +1000,18 @@ export function detectTestingLibraryUtils<
938
1000
) {
939
1001
importedUserEventLibraryNode = callExpression ;
940
1002
}
1003
+
1004
+ if (
1005
+ ! importedReactDomTestUtilsNode &&
1006
+ args . some (
1007
+ ( arg ) =>
1008
+ isLiteral ( arg ) &&
1009
+ typeof arg . value === 'string' &&
1010
+ arg . value === REACT_DOM_TEST_UTILS_PACKAGE
1011
+ )
1012
+ ) {
1013
+ importedReactDomTestUtilsNode = callExpression ;
1014
+ }
941
1015
} ,
942
1016
} ;
943
1017
0 commit comments