@@ -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
@@ -136,7 +142,6 @@ export interface DetectionHelpers {
136142 isNodeComingFromTestingLibrary : IsNodeComingFromTestingLibraryFn ;
137143}
138144
139- const USER_EVENT_PACKAGE = '@testing-library/user-event' ;
140145const REACT_DOM_TEST_UTILS_PACKAGE = 'react-dom/test-utils' ;
141146const FIRE_EVENT_NAME = 'fireEvent' ;
142147const CREATE_EVENT_NAME = 'createEvent' ;
@@ -977,12 +982,11 @@ export function detectTestingLibraryUtils<
977982 }
978983
979984 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 ) ) ;
984985
985- return hasImportElementMatch && hasImportModuleMatch ;
986+ return (
987+ hasImportElementMatch &&
988+ isTestingLibraryModule ( importDeclarationName , customModuleSetting )
989+ ) ;
986990 } ;
987991
988992 const helpers : DetectionHelpers = {
@@ -1034,17 +1038,16 @@ export function detectTestingLibraryUtils<
10341038 }
10351039 // check only if testing library import not found yet so we avoid
10361040 // 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 ) ) {
10381042 importedTestingLibraryNodes . push ( node ) ;
10391043 }
10401044
10411045 // check only if custom module import not found yet so we avoid
10421046 // to override importedCustomModuleNode after it's found
10431047 const customModule = getCustomModule ( ) ;
10441048 if (
1045- customModule &&
10461049 ! importedCustomModuleNode &&
1047- node . source . value . endsWith ( customModule )
1050+ isCustomTestingLibraryModule ( node . source . value , customModule )
10481051 ) {
10491052 importedCustomModuleNode = node ;
10501053 }
@@ -1053,7 +1056,7 @@ export function detectTestingLibraryUtils<
10531056 // to override importedUserEventLibraryNode after it's found
10541057 if (
10551058 ! importedUserEventLibraryNode &&
1056- node . source . value === USER_EVENT_PACKAGE
1059+ node . source . value === USER_EVENT_MODULE
10571060 ) {
10581061 importedUserEventLibraryNode = node ;
10591062 }
@@ -1080,7 +1083,7 @@ export function detectTestingLibraryUtils<
10801083 ( arg ) =>
10811084 isLiteral ( arg ) &&
10821085 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 )
10841087 )
10851088 ) {
10861089 importedTestingLibraryNodes . push ( callExpression ) ;
@@ -1091,10 +1094,9 @@ export function detectTestingLibraryUtils<
10911094 ! importedCustomModuleNode &&
10921095 args . some (
10931096 ( arg ) =>
1094- customModule &&
10951097 isLiteral ( arg ) &&
10961098 typeof arg . value === 'string' &&
1097- arg . value . endsWith ( customModule )
1099+ isCustomTestingLibraryModule ( arg . value , customModule )
10981100 )
10991101 ) {
11001102 importedCustomModuleNode = callExpression ;
@@ -1106,7 +1108,7 @@ export function detectTestingLibraryUtils<
11061108 ( arg ) =>
11071109 isLiteral ( arg ) &&
11081110 typeof arg . value === 'string' &&
1109- arg . value === USER_EVENT_PACKAGE
1111+ arg . value === USER_EVENT_MODULE
11101112 )
11111113 ) {
11121114 importedUserEventLibraryNode = callExpression ;
0 commit comments