@@ -23,7 +23,13 @@ import {
2323 ASYNC_UTILS ,
2424 DEBUG_UTILS ,
2525 PRESENCE_MATCHERS ,
26+ USER_EVENT_MODULE ,
2627} from '../utils' ;
28+ import {
29+ isCustomTestingLibraryModule ,
30+ isOfficialTestingLibraryModule ,
31+ isTestingLibraryModule ,
32+ } from '../utils/is-testing-library-module' ;
2733
2834const SETTING_OPTION_OFF = 'off' ;
2935
@@ -133,7 +139,6 @@ export interface DetectionHelpers {
133139 isNodeComingFromTestingLibrary : IsNodeComingFromTestingLibraryFn ;
134140}
135141
136- const USER_EVENT_PACKAGE = '@testing-library/user-event' ;
137142const REACT_DOM_TEST_UTILS_PACKAGE = 'react-dom/test-utils' ;
138143const FIRE_EVENT_NAME = 'fireEvent' ;
139144const CREATE_EVENT_NAME = 'createEvent' ;
@@ -960,12 +965,11 @@ export function detectTestingLibraryUtils<
960965 }
961966
962967 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 ) ) ;
967968
968- return hasImportElementMatch && hasImportModuleMatch ;
969+ return (
970+ hasImportElementMatch &&
971+ isTestingLibraryModule ( importDeclarationName , customModuleSetting )
972+ ) ;
969973 } ;
970974
971975 const helpers : DetectionHelpers = {
@@ -1017,17 +1021,16 @@ export function detectTestingLibraryUtils<
10171021 }
10181022 // check only if testing library import not found yet so we avoid
10191023 // 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 ) ) {
10211025 importedTestingLibraryNodes . push ( node ) ;
10221026 }
10231027
10241028 // check only if custom module import not found yet so we avoid
10251029 // to override importedCustomModuleNode after it's found
10261030 const customModule = getCustomModule ( ) ;
10271031 if (
1028- customModule &&
10291032 ! importedCustomModuleNode &&
1030- node . source . value . endsWith ( customModule )
1033+ isCustomTestingLibraryModule ( node . source . value , customModule )
10311034 ) {
10321035 importedCustomModuleNode = node ;
10331036 }
@@ -1036,7 +1039,7 @@ export function detectTestingLibraryUtils<
10361039 // to override importedUserEventLibraryNode after it's found
10371040 if (
10381041 ! importedUserEventLibraryNode &&
1039- node . source . value === USER_EVENT_PACKAGE
1042+ node . source . value === USER_EVENT_MODULE
10401043 ) {
10411044 importedUserEventLibraryNode = node ;
10421045 }
@@ -1063,7 +1066,7 @@ export function detectTestingLibraryUtils<
10631066 ( arg ) =>
10641067 isLiteral ( arg ) &&
10651068 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 )
10671070 )
10681071 ) {
10691072 importedTestingLibraryNodes . push ( callExpression ) ;
@@ -1074,10 +1077,9 @@ export function detectTestingLibraryUtils<
10741077 ! importedCustomModuleNode &&
10751078 args . some (
10761079 ( arg ) =>
1077- customModule &&
10781080 isLiteral ( arg ) &&
10791081 typeof arg . value === 'string' &&
1080- arg . value . endsWith ( customModule )
1082+ isCustomTestingLibraryModule ( arg . value , customModule )
10811083 )
10821084 ) {
10831085 importedCustomModuleNode = callExpression ;
@@ -1089,7 +1091,7 @@ export function detectTestingLibraryUtils<
10891091 ( arg ) =>
10901092 isLiteral ( arg ) &&
10911093 typeof arg . value === 'string' &&
1092- arg . value === USER_EVENT_PACKAGE
1094+ arg . value === USER_EVENT_MODULE
10931095 )
10941096 ) {
10951097 importedUserEventLibraryNode = callExpression ;
0 commit comments