Skip to content

✅ Add tests for vitest setupFiles duplication fix#84

Merged
Robdel12 merged 1 commit intomainfrom
test/setupfiles-duplication
Nov 28, 2025
Merged

✅ Add tests for vitest setupFiles duplication fix#84
Robdel12 merged 1 commit intomainfrom
test/setupfiles-duplication

Conversation

@Robdel12
Copy link
Contributor

@Robdel12 Robdel12 commented Nov 28, 2025

Summary

  • Adds regression tests validating that the Vitest plugin doesn't duplicate user-provided setupFiles
  • Tests both array and string setupFiles configurations

Context

These tests validate the fix from #82. Vitest automatically merges plugin config with user config, so the plugin should only return its own setup file—not spread the user's files into its return value.

Test plan

@claude
Copy link

claude bot commented Nov 28, 2025

Code Review ✅

Overall Assessment: This PR adds excellent regression tests for the setupFiles duplication fix from #82. The tests are well-written, clearly documented, and validate the correct behavior.


Strengths

  1. Clear Test Intent: The test names and inline comments clearly explain why the plugin shouldn't duplicate setupFiles—because Vitest handles the merging automatically. This makes the tests self-documenting.

  2. Edge Case Coverage: Testing both array and string setupFiles configurations is thorough. Users can configure setupFiles either way, and both should work correctly.

  3. Focused Assertions: The tests verify:

    • Plugin only returns its own setup file (length check)
    • Plugin's setup file is present (toContain('setup.js'))
    • User's setup files are NOT included in plugin's return value

    This validates the exact contract between plugin and Vitest's config merging.

  4. Consistent Style: Follows the existing test patterns in vitest-plugin.spec.js (structure, variable naming, assertion style).


💡 Suggestions

1. Consider Testing the Merged Result

The current tests verify what the plugin returns, but don't verify what Vitest actually sees after merging. Consider adding a test that validates the final merged config to prove setupFiles aren't duplicated:

it('should result in correct merged config after vitest merging', async () => {
  const { vizzlyPlugin } = await import('../src/index.js');
  
  const userConfig = {
    test: {
      setupFiles: ['./user-setup.js'],
    },
  };
  
  const plugin = vizzlyPlugin();
  const pluginConfig = plugin.config(userConfig, { mode: 'test' });
  
  // Simulate Vitest's merging behavior
  const mergedSetupFiles = [
    ...(userConfig.test.setupFiles || []),
    ...(pluginConfig.test.setupFiles || []),
  ];
  
  // Should have exactly 2 files (user's + plugin's), not 3
  expect(mergedSetupFiles).toHaveLength(2);
  expect(mergedSetupFiles).toContain('./user-setup.js');
  expect(mergedSetupFiles.some(f => f.includes('setup.js'))).toBe(true);
});

This would make the regression test even more explicit about the bug that was fixed.

2. Minor: Variable Naming Consistency

In the first test you use userConfig and pluginConfig, but in the second test you reuse userConfig. Consider using consistent names across both tests for readability:

// First test
let userConfig = { test: { setupFiles: ['./user-setup.js'] } };
let pluginConfig = plugin.config(userConfig, { mode: 'test' });

// Second test - could also use pluginConfig for consistency
let userConfig = { test: { setupFiles: './user-setup.js' } };
let pluginConfig = plugin.config(userConfig, { mode: 'test' });

3. Documentation Enhancement

Consider adding a brief comment at the top of these tests explaining the Vitest plugin config merging behavior for future maintainers:

// Vitest's plugin system automatically merges plugin config with user config.
// When a plugin returns { test: { setupFiles: [...] } }, Vitest merges it with
// the user's test.setupFiles array. If the plugin spreads the user's files into
// its return value, those files would run twice.
// See: https://vitest.dev/guide/using-plugins.html

🔒 Security & Performance

  • ✅ No security concerns
  • ✅ No performance impact (tests run in milliseconds)

🧪 Test Coverage


📝 Final Recommendation

Approve with optional improvements. The tests are solid as-is and ready to merge. The suggestions above would make them even more robust but aren't blockers.

Great work validating the fix! 🎉

@Robdel12 Robdel12 force-pushed the test/setupfiles-duplication branch from 938a3b7 to 138d7ed Compare November 28, 2025 14:23
@Robdel12 Robdel12 changed the title ✅ Add tests for setupFiles duplication fix ✅ Add tests for vitest setupFiles duplication fix Nov 28, 2025
Adds regression tests to verify the plugin doesn't duplicate
user-provided setupFiles. Vitest automatically merges plugin
config with user config, so the plugin should only return its
own setup file.

These tests will pass after PR #82 is merged.
@Robdel12 Robdel12 force-pushed the test/setupfiles-duplication branch from 138d7ed to 44f610a Compare November 28, 2025 14:24
@Robdel12 Robdel12 merged commit c279d97 into main Nov 28, 2025
18 checks passed
@Robdel12 Robdel12 deleted the test/setupfiles-duplication branch November 28, 2025 14:27
Robdel12 added a commit that referenced this pull request Nov 28, 2025
- Adds regression tests validating that the Vitest plugin doesn't
duplicate user-provided `setupFiles`
- Tests both array and string `setupFiles` configurations

These tests validate the fix from #82. Vitest automatically merges
plugin config with user config, so the plugin should only return its own
setup file—not spread the user's files into its return value.

- [x] Merge #82 first
- [x] Rebase this branch onto main
- [ ] Tests should pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant