Skip to content

Commit ca754ce

Browse files
committed
feat: create isTestingLibraryModule function
1 parent 5640b0d commit ca754ce

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/utils/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ const LIBRARY_MODULES = [
3333

3434
const USER_EVENT_MODULE = '@testing-library/user-event';
3535

36+
const OLD_LIBRARY_MODULES = [
37+
'dom-testing-library',
38+
'vue-testing-library',
39+
'react-testing-library',
40+
] as const;
41+
3642
const SYNC_QUERIES_VARIANTS = [
3743
'getBy',
3844
'getAllBy',
@@ -154,4 +160,5 @@ export {
154160
ABSENCE_MATCHERS,
155161
EVENT_HANDLER_METHODS,
156162
USER_EVENT_MODULE,
163+
OLD_LIBRARY_MODULES,
157164
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { TestingLibrarySettings } from '../create-testing-library-rule/detect-testing-library-utils';
2+
3+
import { LIBRARY_MODULES, OLD_LIBRARY_MODULES, USER_EVENT_MODULE } from '.';
4+
5+
export const isOfficialTestingLibraryModule = (importSourceName: string) =>
6+
[...OLD_LIBRARY_MODULES, ...LIBRARY_MODULES, USER_EVENT_MODULE].includes(
7+
importSourceName
8+
);
9+
10+
export const isCustomTestingLibraryModule = (
11+
importSourceName: string,
12+
customModuleSetting: TestingLibrarySettings['testing-library/utils-module']
13+
) =>
14+
typeof customModuleSetting === 'string' &&
15+
importSourceName.endsWith(customModuleSetting);
16+
17+
export const isTestingLibraryModule = (
18+
importSourceName: string,
19+
customModuleSetting?: TestingLibrarySettings['testing-library/utils-module']
20+
) =>
21+
isOfficialTestingLibraryModule(importSourceName) ||
22+
isCustomTestingLibraryModule(importSourceName, customModuleSetting);

0 commit comments

Comments
 (0)