-
Notifications
You must be signed in to change notification settings - Fork 151
fix: Aggressive Reporting support in resolveToTestingLibraryFn #1043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Belco90
merged 6 commits into
testing-library:main
from
y-hsgw:fix/resolve-to-testing-library-fn
Jul 28, 2025
+192
−29
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fa85582
fix: support for Aggressive Reporting
y-hsgw 5640b0d
test: update tests
y-hsgw ca754ce
feat: create isTestingLibraryModule function
y-hsgw 4d152aa
refactor: use isTestingLibraryModule for detection logic
y-hsgw b6b14fe
test: add tests for isTestingLibraryModule
y-hsgw 43290d7
test: avoid reusing synced constants in tests; use hardcoded values t…
y-hsgw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { TestingLibrarySettings } from '../create-testing-library-rule/detect-testing-library-utils'; | ||
|
||
import { LIBRARY_MODULES, OLD_LIBRARY_MODULES, USER_EVENT_MODULE } from '.'; | ||
|
||
export const isOfficialTestingLibraryModule = (importSourceName: string) => | ||
[...OLD_LIBRARY_MODULES, ...LIBRARY_MODULES, USER_EVENT_MODULE].includes( | ||
importSourceName | ||
); | ||
|
||
export const isCustomTestingLibraryModule = ( | ||
importSourceName: string, | ||
customModuleSetting: TestingLibrarySettings['testing-library/utils-module'] | ||
) => | ||
typeof customModuleSetting === 'string' && | ||
importSourceName.endsWith(customModuleSetting); | ||
|
||
export const isTestingLibraryModule = ( | ||
Belco90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
importSourceName: string, | ||
customModuleSetting?: TestingLibrarySettings['testing-library/utils-module'] | ||
) => | ||
isOfficialTestingLibraryModule(importSourceName) || | ||
isCustomTestingLibraryModule(importSourceName, customModuleSetting); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { | ||
isCustomTestingLibraryModule, | ||
isOfficialTestingLibraryModule, | ||
isTestingLibraryModule, | ||
} from '../../../lib/utils/is-testing-library-module'; | ||
|
||
const OLD_LIBRARY_MODULES = [ | ||
'dom-testing-library', | ||
'vue-testing-library', | ||
'react-testing-library', | ||
] as const; | ||
|
||
const LIBRARY_MODULES = [ | ||
'@testing-library/dom', | ||
'@testing-library/angular', | ||
'@testing-library/react', | ||
'@testing-library/preact', | ||
'@testing-library/vue', | ||
'@testing-library/svelte', | ||
'@marko/testing-library', | ||
] as const; | ||
|
||
const USER_EVENT_MODULE = '@testing-library/user-event'; | ||
|
||
describe('isOfficialTestingLibraryModule', () => { | ||
it.each([...OLD_LIBRARY_MODULES, ...LIBRARY_MODULES, USER_EVENT_MODULE])( | ||
Belco90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'returns true when arg is "%s"', | ||
(importSourceName) => { | ||
const result = isOfficialTestingLibraryModule(importSourceName); | ||
|
||
expect(result).toBe(true); | ||
} | ||
); | ||
|
||
it.each(['custom-modules', 'hoge-testing-library', '@testing-library/hoge'])( | ||
'returns false when arg is "%s"', | ||
(importSourceName) => { | ||
const result = isOfficialTestingLibraryModule(importSourceName); | ||
|
||
expect(result).toBe(false); | ||
} | ||
); | ||
}); | ||
|
||
describe('isCustomTestingLibraryModule', () => { | ||
it.each(['test-utils', '../test-utils', '@/test-utils'])( | ||
'returns true when arg is "%s"', | ||
(importSourceName) => { | ||
const result = isCustomTestingLibraryModule( | ||
importSourceName, | ||
'test-utils' | ||
); | ||
|
||
expect(result).toBe(true); | ||
} | ||
); | ||
|
||
it.each([ | ||
'custom-modules', | ||
'react-testing-library', | ||
'@testing-library/react', | ||
'test-util', | ||
'test-utils-module', | ||
])('returns false when arg is "%s"', (importSourceName) => { | ||
const result = isCustomTestingLibraryModule(importSourceName, 'test-utils'); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isTestingLibraryModule', () => { | ||
it.each([ | ||
...OLD_LIBRARY_MODULES, | ||
...LIBRARY_MODULES, | ||
USER_EVENT_MODULE, | ||
'test-utils', | ||
'../test-utils', | ||
'@/test-utils', | ||
])('returns true when arg is "%s"', (importSourceName) => { | ||
const result = isTestingLibraryModule(importSourceName, 'test-utils'); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it.each([ | ||
'custom-modules', | ||
'hoge-testing-library', | ||
'@testing-library/hoge', | ||
'test-util', | ||
'test-utils-module', | ||
])('returns false when arg is "%s"', (importSourceName) => { | ||
const result = isTestingLibraryModule(importSourceName, 'test-utils'); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.