@@ -23,7 +23,13 @@ import {
23
23
ASYNC_UTILS ,
24
24
DEBUG_UTILS ,
25
25
PRESENCE_MATCHERS ,
26
+ USER_EVENT_MODULE ,
26
27
} from '../utils' ;
28
+ import {
29
+ isCustomTestingLibraryModule ,
30
+ isOfficialTestingLibraryModule ,
31
+ isTestingLibraryModule ,
32
+ } from '../utils/is-testing-library-module' ;
27
33
28
34
const SETTING_OPTION_OFF = 'off' ;
29
35
@@ -133,7 +139,6 @@ export interface DetectionHelpers {
133
139
isNodeComingFromTestingLibrary : IsNodeComingFromTestingLibraryFn ;
134
140
}
135
141
136
- const USER_EVENT_PACKAGE = '@testing-library/user-event' ;
137
142
const REACT_DOM_TEST_UTILS_PACKAGE = 'react-dom/test-utils' ;
138
143
const FIRE_EVENT_NAME = 'fireEvent' ;
139
144
const CREATE_EVENT_NAME = 'createEvent' ;
@@ -960,12 +965,11 @@ export function detectTestingLibraryUtils<
960
965
}
961
966
962
967
const hasImportElementMatch = hasImportMatch ( importNode , identifierName ) ;
963
- const hasImportModuleMatch =
964
- / t e s t i n g - l i b r a r y / g. test ( importDeclarationName ) ||
965
- ( typeof customModuleSetting === 'string' &&
966
- importDeclarationName . endsWith ( customModuleSetting ) ) ;
967
968
968
- return hasImportElementMatch && hasImportModuleMatch ;
969
+ return (
970
+ hasImportElementMatch &&
971
+ isTestingLibraryModule ( importDeclarationName , customModuleSetting )
972
+ ) ;
969
973
} ;
970
974
971
975
const helpers : DetectionHelpers = {
@@ -1017,17 +1021,16 @@ export function detectTestingLibraryUtils<
1017
1021
}
1018
1022
// check only if testing library import not found yet so we avoid
1019
1023
// to override importedTestingLibraryNodes after it's found
1020
- if ( / t e s t i n g - l i b r a r y / g . test ( node . source . value ) ) {
1024
+ if ( isOfficialTestingLibraryModule ( node . source . value ) ) {
1021
1025
importedTestingLibraryNodes . push ( node ) ;
1022
1026
}
1023
1027
1024
1028
// check only if custom module import not found yet so we avoid
1025
1029
// to override importedCustomModuleNode after it's found
1026
1030
const customModule = getCustomModule ( ) ;
1027
1031
if (
1028
- customModule &&
1029
1032
! importedCustomModuleNode &&
1030
- node . source . value . endsWith ( customModule )
1033
+ isCustomTestingLibraryModule ( node . source . value , customModule )
1031
1034
) {
1032
1035
importedCustomModuleNode = node ;
1033
1036
}
@@ -1036,7 +1039,7 @@ export function detectTestingLibraryUtils<
1036
1039
// to override importedUserEventLibraryNode after it's found
1037
1040
if (
1038
1041
! importedUserEventLibraryNode &&
1039
- node . source . value === USER_EVENT_PACKAGE
1042
+ node . source . value === USER_EVENT_MODULE
1040
1043
) {
1041
1044
importedUserEventLibraryNode = node ;
1042
1045
}
@@ -1063,7 +1066,7 @@ export function detectTestingLibraryUtils<
1063
1066
( arg ) =>
1064
1067
isLiteral ( arg ) &&
1065
1068
typeof arg . value === 'string' &&
1066
- / t e s t i n g - l i b r a r y / g . test ( arg . value )
1069
+ isOfficialTestingLibraryModule ( arg . value )
1067
1070
)
1068
1071
) {
1069
1072
importedTestingLibraryNodes . push ( callExpression ) ;
@@ -1074,10 +1077,9 @@ export function detectTestingLibraryUtils<
1074
1077
! importedCustomModuleNode &&
1075
1078
args . some (
1076
1079
( arg ) =>
1077
- customModule &&
1078
1080
isLiteral ( arg ) &&
1079
1081
typeof arg . value === 'string' &&
1080
- arg . value . endsWith ( customModule )
1082
+ isCustomTestingLibraryModule ( arg . value , customModule )
1081
1083
)
1082
1084
) {
1083
1085
importedCustomModuleNode = callExpression ;
@@ -1089,7 +1091,7 @@ export function detectTestingLibraryUtils<
1089
1091
( arg ) =>
1090
1092
isLiteral ( arg ) &&
1091
1093
typeof arg . value === 'string' &&
1092
- arg . value === USER_EVENT_PACKAGE
1094
+ arg . value === USER_EVENT_MODULE
1093
1095
)
1094
1096
) {
1095
1097
importedUserEventLibraryNode = callExpression ;
0 commit comments