-
Notifications
You must be signed in to change notification settings - Fork 8
feat: more mock api #290
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?
feat: more mock api #290
Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
1b13390
to
8fce7ef
Compare
f60d30b
to
b3a5824
Compare
It's good to be reviewed now. Although there is still more work to do, it can handle most common mock functionalities. This PR will be able to migrate Rslib mock test cases tested by linking them locally on my machine. |
const { RuntimeModule } = compiler.webpack; | ||
class RetestImportRuntimeModule extends RuntimeModule { | ||
constructor() { | ||
super('rstest runtime'); |
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.
@@ -43,30 +43,41 @@ export const createRstestUtilities: () => RstestUtilities = () => { | |||
return rstest; | |||
}, | |||
mock: () => { | |||
// TODO | |||
// The actual implementation is managed by the built-in Rstest plugin. |
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.
Maybe we can throw error, if some dynamic case is not processed by Rstest plugin.
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.
That will be the very ideal target, however, the hard part is: you can mock a module in a test entry file while import it in a nested imported source file, and they're isolated in compile time. So we had to throw an error in runtime.
I think this is still feasible with the following setups in the runtime solution:
- store all mocked module ids in runtime.
- monkey patch
__webpack_require__
(it can't be customized render by plugin IMO) to diversion mocked module and non found module, throw a user-friendly error for the later case.
Summary
Support most mock APIs.
Related Links
rs.mock
rs.importActual
rs.doMock
rs.importMock
rs.mockRequire
rs.requireActual
rs.doMockRequire
rs.requireMock
rs.resetModules
rs.unmock
rs.doUnmock
Checklist