fix: MSW running on prod#162
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Summary by CodeRabbit
WalkthroughThe logic for enabling mocking in the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Suggested labels
Poem
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Redundant nested conditions ▹ view | ✅ Fix detected |
Files scanned
| File Path | Reviewed |
|---|---|
| mocks/init.ts | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
__mocks__/init.ts
Outdated
| if (appConfig.isDev && !appConfig.isMockingEnabled) { | ||
| console.log(`MSW mocking disabled: ${appConfig.isDev}, ${appConfig.isMockingEnabled} `) | ||
| if (!(appConfig.isDev && appConfig.isMockingEnabled)) { | ||
| if (appConfig.isDev && !appConfig.isMockingEnabled) { |
There was a problem hiding this comment.
if (!appConfig.isDev || !appConfig.isMockingEnabled) {
if (appConfig.isDev) {
console.log(
`[MSW] Mocking disabled → Environment: Development, Mocking Enabled: ${appConfig.isMockingEnabled}`,
)
}
return
}
There was a problem hiding this comment.
made the changes sir
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
__mocks__/init.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
__mocks__/init.ts (1)
config/app-config.ts (1)
appConfig(13-19)
🔇 Additional comments (1)
__mocks__/init.ts (1)
4-4: LGTM! Conditional logic correctly prevents MSW from running in production.The inverted condition
!(appConfig.isDev && appConfig.isMockingEnabled)properly ensures MSW only runs when both development environment and mocking are explicitly enabled, fixing the production issue.
Date: 26 Jul 2025
Developer Name: @Hariom01010
Issue Ticket Number
Closes #161
Description
Currently, there is a conditional check bug that allows MSW to run in production. Added an extra check to run MSW only when the environment is development and the mocking variable is set to true. In all other cases, the MSW setup does not run.
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
When the app is run in production mode using pnpm start:

When the app is run in development mode using pnpm run dev:

When the app is run in development mode and api mocking variable is false:

Test Coverage
Screenshot 1
Additional Notes
Description by Korbit AI
What change is being made?
Update the logic in
enableMockingto prevent MSW (Mock Service Worker) from running in production environments by enhancing the console log for better context when mocking is disabled.Why are these changes being made?
Previously, the console message was incorrect in non-dev environments and did not reflect the accurate state when mocking was disabled; the updated check clarifies that mocking will only run when both
isDevandisMockingEnabledare true, reducing the risk of accidentally enabling mocks in production.