@@ -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
@@ -136,7 +142,6 @@ export interface DetectionHelpers {
136
142
isNodeComingFromTestingLibrary : IsNodeComingFromTestingLibraryFn ;
137
143
}
138
144
139
- const USER_EVENT_PACKAGE = '@testing-library/user-event' ;
140
145
const REACT_DOM_TEST_UTILS_PACKAGE = 'react-dom/test-utils' ;
141
146
const FIRE_EVENT_NAME = 'fireEvent' ;
142
147
const CREATE_EVENT_NAME = 'createEvent' ;
@@ -977,12 +982,11 @@ export function detectTestingLibraryUtils<
977
982
}
978
983
979
984
const hasImportElementMatch = hasImportMatch ( importNode , identifierName ) ;
980
- const hasImportModuleMatch =
981
- / t e s t i n g - l i b r a r y / g. test ( importDeclarationName ) ||
982
- ( typeof customModuleSetting === 'string' &&
983
- importDeclarationName . endsWith ( customModuleSetting ) ) ;
984
985
985
- return hasImportElementMatch && hasImportModuleMatch ;
986
+ return (
987
+ hasImportElementMatch &&
988
+ isTestingLibraryModule ( importDeclarationName , customModuleSetting )
989
+ ) ;
986
990
} ;
987
991
988
992
const helpers : DetectionHelpers = {
@@ -1034,17 +1038,16 @@ export function detectTestingLibraryUtils<
1034
1038
}
1035
1039
// check only if testing library import not found yet so we avoid
1036
1040
// to override importedTestingLibraryNodes after it's found
1037
- if ( / t e s t i n g - l i b r a r y / g . test ( node . source . value ) ) {
1041
+ if ( isOfficialTestingLibraryModule ( node . source . value ) ) {
1038
1042
importedTestingLibraryNodes . push ( node ) ;
1039
1043
}
1040
1044
1041
1045
// check only if custom module import not found yet so we avoid
1042
1046
// to override importedCustomModuleNode after it's found
1043
1047
const customModule = getCustomModule ( ) ;
1044
1048
if (
1045
- customModule &&
1046
1049
! importedCustomModuleNode &&
1047
- node . source . value . endsWith ( customModule )
1050
+ isCustomTestingLibraryModule ( node . source . value , customModule )
1048
1051
) {
1049
1052
importedCustomModuleNode = node ;
1050
1053
}
@@ -1053,7 +1056,7 @@ export function detectTestingLibraryUtils<
1053
1056
// to override importedUserEventLibraryNode after it's found
1054
1057
if (
1055
1058
! importedUserEventLibraryNode &&
1056
- node . source . value === USER_EVENT_PACKAGE
1059
+ node . source . value === USER_EVENT_MODULE
1057
1060
) {
1058
1061
importedUserEventLibraryNode = node ;
1059
1062
}
@@ -1080,7 +1083,7 @@ export function detectTestingLibraryUtils<
1080
1083
( arg ) =>
1081
1084
isLiteral ( arg ) &&
1082
1085
typeof arg . value === 'string' &&
1083
- / t e s t i n g - l i b r a r y / g . test ( arg . value )
1086
+ isOfficialTestingLibraryModule ( arg . value )
1084
1087
)
1085
1088
) {
1086
1089
importedTestingLibraryNodes . push ( callExpression ) ;
@@ -1091,10 +1094,9 @@ export function detectTestingLibraryUtils<
1091
1094
! importedCustomModuleNode &&
1092
1095
args . some (
1093
1096
( arg ) =>
1094
- customModule &&
1095
1097
isLiteral ( arg ) &&
1096
1098
typeof arg . value === 'string' &&
1097
- arg . value . endsWith ( customModule )
1099
+ isCustomTestingLibraryModule ( arg . value , customModule )
1098
1100
)
1099
1101
) {
1100
1102
importedCustomModuleNode = callExpression ;
@@ -1106,7 +1108,7 @@ export function detectTestingLibraryUtils<
1106
1108
( arg ) =>
1107
1109
isLiteral ( arg ) &&
1108
1110
typeof arg . value === 'string' &&
1109
- arg . value === USER_EVENT_PACKAGE
1111
+ arg . value === USER_EVENT_MODULE
1110
1112
)
1111
1113
) {
1112
1114
importedUserEventLibraryNode = callExpression ;
0 commit comments