-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Rename mock and require file references #62834
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
base: main
Are you sure you want to change the base?
Rename mock and require file references #62834
Conversation
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
1 similar comment
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
|
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
@microsoft-github-policy-service agree |
…hjonasson/TypeScript into feature/rename-mock-and-require-imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Hi 👋
I am both forgetful and lazy. That has caused me to get a broken pipeline too many times when I move files, relying on auto-updates of file paths. That breaks other file references like
jest.mock("my-moved-file")orrequire("my-moved-file")I know these are not imports, but function calls. However, both are file references for practical purposes, and I would love for this to be covered. Did I use AI to help me with this? Yes. However, I also tested it extensively with a local build of tsserver in various projects, in addition the added unit tests. I also searched open and closed issues for this feature but couldn't find it. My apologies if this has been rejected before.
Before:
After:
Implementation Details
Changes Made
Added
updateImportsInTestFrameworkCallspreference (src/compiler/types.ts)UserPreferencesinterfaceExtended
getEditsForFileRenamefunctionality (src/services/getEditsForFileRename.ts)getModulePathArgument()function to detect module loading patternsupdateModuleLoadingCalls()function to traverse AST and update pathsforEachChildresultSupported Patterns
jest.mock(),jest.unmock(),jest.requireActual(),jest.requireMock(),jest.doMock(),jest.dontMock()vitest.mock(),vi.mock()import(),require()(already supported, now with improved coverage)Design Decisions
testFrameworkPatternsarrayjest.mock()), not nested property accessesSetto track already-processed imports, avoiding redundant updatesTesting
Files Changed
src/compiler/types.ts- Added new preference interfacesrc/services/getEditsForFileRename.ts- Implemented feature logic and bug fixtests/baselines/reference/api/typescript.d.ts- Updated API baselinetests/cases/fourslash/getEditsForFileRename_jestMock.ts- Added test coveragetests/cases/fourslash/getEditsForFileRename_requireInTs.ts- Added test coveragetests/cases/fourslash/getEditsForFileRename_dynamicImport.ts- Added test coveragePlease verify that:
Backlogmilestone (required) (sorry 🙏 Happy to create one if you like the idea)mainbranchhereby runtestslocally✅ Refer to CONTRIBUTING.MD for more details.
https://github.com/Microsoft/TypeScript/blob/main/CONTRIBUTING.md
#62835