-
-
Notifications
You must be signed in to change notification settings - Fork 281
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
docs(test-runner-module-mocking): ✏️ test-moduleMocking details on plugin import order #2642
base: master
Are you sure you want to change the base?
docs(test-runner-module-mocking): ✏️ test-moduleMocking details on plugin import order #2642
Conversation
…ugin import order Adding details on the order of plugin import in test config. Module mocking must be in first position to avoid conflict with modified path due to other plugins. + refactoring
🦋 Changeset detectedLatest commit: 1cac4c3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -37,15 +37,37 @@ export function moduleMockingPlugin(): Plugin { | |||
const namedExports = exports.map(e => e.n).filter(n => n !== 'default'); | |||
const hasDefaultExport = exports.some(e => e.n === 'default'); | |||
|
|||
body = ` | |||
body = generateInterceptedModuleBody(body, url, namedExports, hasDefaultExport); |
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.
There is no real reason to extract this in a separate method, right? Can you revert this change?
@@ -20,6 +20,14 @@ describe('moduleMockingPlugin', function test() { | |||
}); | |||
}); | |||
|
|||
it('can intercept server relative modules with stub', async () => { |
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.
All tests are using stubs. :-)
Example:
web/packages/test-runner-module-mocking/test/fixtures/server-relative/browser-test.js
Line 16 in 2d933bc
timeLibrary.getCurrentHour = () => 12; |
We don't want to test all different stubbing libraries.
So, you can remove this extra test.
@@ -38,6 +38,8 @@ export default { | |||
}; | |||
``` | |||
|
|||
Take care of the plugins order, some plugins can modify path of imported modules and moduleMockingPlugin may be not able to retreive them correctly, so it's advise to use it first in the list. |
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.
Take care of the plugins order, some plugins can modify path of imported modules and moduleMockingPlugin may be not able to retreive them correctly, so it's advise to use it first in the list. | |
When using multiple plugins, make sure `moduleMockingPlugin()` rune before any other plugin that changes import resolutions using the `resolveImport()` hook (eg. `rollupAdapter()`). The interception mechanism of `moduleMockingPlugin()` needs to run before those transformations. | |
Therefor, it is advised to have `moduleMockingPlugin()` as the first plugin. |
docs(test-runner-module-mocking): ✏️ test-moduleMocking details on plugin import order
Adding details on the order of plugin import in test config. Module mocking must be in first position to avoid conflict with modified path due to other plugins. + refactoring
What I did