fix(runtime-utils): align mount options merge w/ vue-test-utils#1610
fix(runtime-utils): align mount options merge w/ vue-test-utils#1610danielroe merged 3 commits intonuxt:mainnuxt/test-utils:mainfrom yamachi4416:fix/stubbed-global-provideyamachi4416/test-utils:fix/stubbed-global-provideCopy head branch name to clipboard
Conversation
commit: |
…tils for mount + render helpers
3a9fcd0 to
1a32dd0
Compare
📝 WalkthroughWalkthroughAdds a new injectable array to the example app by exporting Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/runtime-utils/utils/suspended.ts (1)
231-238: Potential loss of nestedconfigproperties other thanglobalProperties.The current merge only explicitly handles
globalPropertieswithinconfig. Ifoptions.configcontains additional nested objects likecompilerOptions, the spread...options.configwill overwrite...defaults.configentirely for those keys rather than deep-merging them.Given the test at line 578-599 uses
config.compilerOptionsand the defaults don't setcompilerOptions, this works now. However, if future defaults includecompilerOptions, the user-provided values would fully replace defaults instead of merging.If deep-merging other config sub-properties is intended, consider extending the pattern used for
globalProperties.♻️ Optional: extend deep merge for compilerOptions if needed
config: { ...defaults.config, ...options.config, globalProperties: { ...defaults.config?.globalProperties, ...options.config?.globalProperties, } as NonNullable<typeof options['config']>['globalProperties'], + compilerOptions: { + ...defaults.config?.compilerOptions, + ...options.config?.compilerOptions, + }, },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/runtime-utils/utils/suspended.ts` around lines 231 - 238, The config merge currently only deep-merges globalProperties and shallowly spreads options.config over defaults.config, which will cause nested config objects (e.g., compilerOptions) to be overwritten rather than merged; update the merge logic around config to deep-merge any nested sub-objects you want preserved (at least include compilerOptions like globalProperties) by merging defaults.config, options.config, and then individually deep-merging nested keys such as globalProperties and compilerOptions (referencing the existing defaults.config, options.config, globalProperties, and compilerOptions symbols) so user-provided nested settings are merged with defaults rather than replaced.examples/app-vitest-full/tests/nuxt/compatibility-mount.spec.ts (1)
601-622: Consider adding tests formocksanddirectivesglobal options.The new
mergeComponentMountingGlobalOptionsfunction also handlesmocksanddirectives, but there are no dedicated tests in this suite for those options. Whilemocksis tested in the existingglobal.mockstest (line 48-57), adding explicit tests here would ensure comprehensive coverage of the merge behavior.This is optional since the existing test at line 48 does cover
mocksbehavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@examples/app-vitest-full/tests/nuxt/compatibility-mount.spec.ts` around lines 601 - 622, Add explicit tests for global.mocks and global.directives in this compatibility-mount.spec.ts suite similar to the existing config.globalProperties test: create a small Component via defineComponent that uses a mocked property (e.g., this.$mocked or a template reference) and a custom directive (e.g., v-test that mutates DOM/text), then mount it with options typed as Options<typeof Component> and compare outputs from mount(...) and await mountSuspended(...). Ensure the tests exercise the mergeComponentMountingGlobalOptions behavior by passing mocks and directives under the global option and asserting vWrapper.html() === nWrapper.html(); reference mount, mountSuspended, defineComponent, Options and mergeComponentMountingGlobalOptions to locate where to add them.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@examples/app-vitest-full/tests/nuxt/compatibility-mount.spec.ts`:
- Around line 601-622: Add explicit tests for global.mocks and global.directives
in this compatibility-mount.spec.ts suite similar to the existing
config.globalProperties test: create a small Component via defineComponent that
uses a mocked property (e.g., this.$mocked or a template reference) and a custom
directive (e.g., v-test that mutates DOM/text), then mount it with options typed
as Options<typeof Component> and compare outputs from mount(...) and await
mountSuspended(...). Ensure the tests exercise the
mergeComponentMountingGlobalOptions behavior by passing mocks and directives
under the global option and asserting vWrapper.html() === nWrapper.html();
reference mount, mountSuspended, defineComponent, Options and
mergeComponentMountingGlobalOptions to locate where to add them.
In `@src/runtime-utils/utils/suspended.ts`:
- Around line 231-238: The config merge currently only deep-merges
globalProperties and shallowly spreads options.config over defaults.config,
which will cause nested config objects (e.g., compilerOptions) to be overwritten
rather than merged; update the merge logic around config to deep-merge any
nested sub-objects you want preserved (at least include compilerOptions like
globalProperties) by merging defaults.config, options.config, and then
individually deep-merging nested keys such as globalProperties and
compilerOptions (referencing the existing defaults.config, options.config,
globalProperties, and compilerOptions symbols) so user-provided nested settings
are merged with defaults rather than replaced.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 160f3bfa-3599-41d4-bf92-0a9baa1711d9
📒 Files selected for processing (5)
examples/app-vitest-full/components/InjectedValueComponent.vueexamples/app-vitest-full/plugins/inject-value.tsexamples/app-vitest-full/tests/nuxt/compatibility-mount.spec.tsexamples/app-vitest-full/tests/nuxt/injected-value-component.spec.tssrc/runtime-utils/utils/suspended.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
examples/app-vitest-full/tests/nuxt/compatibility-mount.spec.ts (1)
586-590: Minor:el.textContentcan benullin TypeScript.
Element.textContenthas typestring | null. While the test template guarantees content exists, adding a non-null assertion or fallback would be more defensive.♻️ Proposed fix
directives: { repeatText: { beforeMount(el: Element, { value }: { value: number }) { - el.textContent = el.textContent.repeat(value) + el.textContent = (el.textContent ?? '').repeat(value) }, }, },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@examples/app-vitest-full/tests/nuxt/compatibility-mount.spec.ts` around lines 586 - 590, The custom directive repeatText's beforeMount handler uses el.textContent which is typed as string | null; update the handler (repeatText.beforeMount) to guard against null by either using a non-null assertion (el.textContent!) or providing a fallback (e.g., (el.textContent ?? '') ) before calling .repeat(value) so TypeScript no longer reports a possible null access.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@examples/app-vitest-full/tests/nuxt/compatibility-mount.spec.ts`:
- Around line 586-590: The custom directive repeatText's beforeMount handler
uses el.textContent which is typed as string | null; update the handler
(repeatText.beforeMount) to guard against null by either using a non-null
assertion (el.textContent!) or providing a fallback (e.g., (el.textContent ??
'') ) before calling .repeat(value) so TypeScript no longer reports a possible
null access.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3ed374b8-dd88-44f0-b6a4-ab4b8809d53a
📒 Files selected for processing (1)
examples/app-vitest-full/tests/nuxt/compatibility-mount.spec.ts
🔗 Linked issue
📚 Description