Skip to content

Conversation

@poltorak
Copy link
Collaborator

@poltorak poltorak commented Sep 5, 2025

Centralize and Standardize Vitest Configurations

What Changed

  • New centralized configuration system: Created testing/test-setup-config package with a factory-based approach for generating Vitest configurations
  • Setup presets: Introduced modular setup file presets that can be composed for different test types (unit, integration, e2e)
  • Simplified configuration files: Refactored 6 existing Vitest config files to use the new centralized system, reducing them from verbose configurations to simple function calls

Benefits

  • Eliminates duplication: Removes repetitive boilerplate across multiple vitest config files
  • Ensures consistency: Standardizes test configurations, coverage settings, and setup files across all packages
  • Improves maintainability: Changes to test configuration defaults now only need to be made in one place
  • Better developer experience: New configs are more readable and easier to customize with sensible defaults and preset combinations

The new system provides createUnitConfig, createIntConfig, and createE2eConfig factory functions that automatically handle common configuration patterns while still allowing customization through override parameters.

Relates to first part of #1065

@github-actions github-actions bot added 📖 Project documentation improvements or additions to the project documentation 🔬 testing writing tests 🛠️ tooling labels Sep 5, 2025
@nx-cloud
Copy link

nx-cloud bot commented Sep 5, 2025

View your CI Pipeline Execution ↗ for commit 2772f2b

Command Status Duration Result
nx code-pushup --nx-bail -- compare ✅ Succeeded 54s View ↗
nx code-pushup --nx-bail -- ✅ Succeeded 1m 3s View ↗
nx code-pushup --nx-bail -- print-config --outp... ✅ Succeeded 3m 57s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-05 09:12:11 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 5, 2025

Open in StackBlitz

@code-pushup/ci

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/ci@1107

@code-pushup/cli

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/cli@1107

@code-pushup/core

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/core@1107

@code-pushup/create-cli

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/create-cli@1107

@code-pushup/models

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/models@1107

@code-pushup/coverage-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/coverage-plugin@1107

@code-pushup/nx-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/nx-plugin@1107

@code-pushup/eslint-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/eslint-plugin@1107

@code-pushup/js-packages-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/js-packages-plugin@1107

@code-pushup/jsdocs-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/jsdocs-plugin@1107

@code-pushup/lighthouse-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/lighthouse-plugin@1107

@code-pushup/typescript-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/typescript-plugin@1107

@code-pushup/utils

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/utils@1107

@code-pushup/models-transformers

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/models-transformers@1107

commit: 2772f2b

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2025

Code PushUp

🤨 Code PushUp report has both improvements and regressions – compared current commit a7b988f with previous commit c4b025c.

🕵️ See full comparison in Code PushUp portal 🔍

🏷️ Categories

🏷️ Category ⭐ Previous score ⭐ Current score 🔄 Score change
Performance 🔴 35 🔴 32 ↓ −2.9
Code coverage 🟢 90 🟡 88 ↓ −2.3
Security 🟡 56 🟡 56
Updates 🟡 73 🟡 73
Accessibility 🟢 92 🟢 92
Best Practices 🟢 100 🟢 100
SEO 🟡 61 🟡 61
Type Safety 🟢 100 🟢 100
Bug prevention 🟢 100 🟢 100
Miscellaneous 🟢 100 🟢 100
Code style 🟢 100 🟢 100
Documentation 🔴 36 🔴 36
👎 2 groups regressed, 👍 1 audit improved, 👎 7 audits regressed, 14 audits changed without impacting score

🗃️ Groups

🔌 Plugin 🗃️ Group ⭐ Previous score ⭐ Current score 🔄 Score change
Lighthouse Performance 🔴 35 🔴 32 ↓ −2.9
Code coverage Code coverage metrics 🟢 90 🟡 88 ↓ −2.3

19 other groups are unchanged.

🛡️ Audits

🔌 Plugin 🛡️ Audit 📏 Previous value 📏 Current value 🔄 Value change
Lighthouse Initial server response time was short 🟩 Root document took 590 ms 🟥 Root document took 1,520 ms ↑ +157.2 %
Lighthouse Speed Index 🟥 7.7 s 🟥 8.7 s ↑ +12.8 %
Lighthouse Total Blocking Time 🟥 1,810 ms 🟥 2,510 ms ↑ +38.7 %
Lighthouse First Contentful Paint 🟥 3.1 s 🟥 3.3 s ↑ +4.8 %
Code coverage Function coverage 🟩 93.1 % 🟨 89.4 % ↓ −4 %
Code coverage Line coverage 🟨 86.8 % 🟨 84.6 % ↓ −2.6 %
Lighthouse Time to Interactive 🟥 13.4 s 🟥 14.1 s ↑ +4.9 %
Code coverage Branch coverage 🟨 86 % 🟨 86.4 % ↑ +0.4 %
Lighthouse Avoids enormous network payloads 🟩 Total size was 2,037 KiB 🟩 Total size was 2,099 KiB ↑ +3 %
Lighthouse Minimizes main-thread work 🟥 13.0 s 🟥 14.5 s ↑ +11 %
Lighthouse Largest Contentful Paint 🟥 11.8 s 🟥 12.6 s ↑ +6 %
Lighthouse Metrics 🟩 100% 🟩 100% ↑ +5 %
Lighthouse Uses efficient cache policy on static assets 🟨 30 resources found 🟨 30 resources found ↑ +0.1 %
Lighthouse Remove duplicate modules in JavaScript bundles 🟥 Potential savings of 103 KiB 🟥 Potential savings of 86 KiB ↑ +43.8 %
Lighthouse Reduce unused JavaScript 🟥 Potential savings of 181 KiB 🟥 Potential savings of 180 KiB ↑ +16.5 %
Lighthouse Server Backend Latencies 🟩 1,480 ms 🟩 1,600 ms ↑ +8.2 %
Lighthouse Avoids an excessive DOM size 🟥 2,255 elements 🟥 2,371 elements ↑ +5.1 %
Lighthouse JavaScript execution time 🟥 5.4 s 🟥 5.3 s ↓ −0.6 %
Lighthouse Network Round Trip Times 🟩 30 ms 🟩 60 ms ↑ +118.2 %
Lighthouse Max Potential First Input Delay 🟥 1,430 ms 🟥 1,450 ms ↑ +2 %
Lighthouse Reduce unused CSS 🟥 Potential savings of 103 KiB 🟥 Potential savings of 62 KiB ↓ −4.2 %
JS Packages Outdated NPM prod dependencies. 🟨 17 outdated package versions (6 major, 7 minor, 4 patch) 🟨 18 outdated package versions (6 major, 7 minor, 5 patch) ↑ +5.9 %

588 other audits are unchanged.

Copy link
Collaborator

@BioPhoton BioPhoton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning up our test config mess :)

I left some comments.

  • please add a proper PR description that contains the scope and planned changes
  • move the config code under a Nx project in testing/vitest-setup. I updated the issue accordingly.

@poltorak poltorak marked this pull request as ready for review September 10, 2025 06:45
Copy link
Collaborator

@BioPhoton BioPhoton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! Nice testing tool! There is Readme, and tests, lovely.
I left some first comments and will wait for one feedback on the override logic for further comments.

@poltorak poltorak force-pushed the refactor/vitest-configurations branch from 9433ca5 to 7008a48 Compare October 6, 2025 15:17
Copy link
Collaborator

@matejchalk matejchalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your contribution 🙂 I think it looks promising, but ...

I don't think this PR goes far enough towards unification. Ideally, only 2 parameters1 would determine the entire Vitest config:

  • Nx project name (e.g., cli, plugin-eslint, ci-e2e) 2
  • test kind ('unit' | 'int' | 'e2e')

My main criticism of this PR is that it doesn't commit to unification over flexibility. I believe we need less flexibility than it may appear, so I would go all in on unification. If we find some exception, we should question whether that exception is justified and get rid of it if possible.

In the current implementation, some things are automatically inferred, but there are many (IMHO unnecessary) optional arguments, and anything can be overridden by providing a Vitest config object. To me, this is a leaky abstraction.

I've suggested specifics on what can be unified in my comments. Let me know if I can clarify anything 🙂 I realize you couldn't reasonably have known many of these things, so no worries.

Footnotes

  1. By "parameter", I don't strictly mean a function parameter. Your approach of exporting different factory functions for each test kind also works, for example.

  2. It may turn out we also need something like projectRoot (e.g., 'packages/core'). In that case, we could either derive it via @nx/devkit's createProjectGraphAsync, provide the project folder instead and derive its name using path.basename, or add another parameter.

@poltorak poltorak force-pushed the refactor/vitest-configurations branch 2 times, most recently from a11d027 to 38b7a6e Compare October 29, 2025 15:36
Copy link
Collaborator

@matejchalk matejchalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is headed in the right direction. I also reviewed the internal implementation this time, where I have some minor suggestions.

However, I think the pattern is now fairly clear, so please go ahead and apply it to other Vitest configs. 🙏

@poltorak poltorak force-pushed the refactor/vitest-configurations branch from 026b301 to 11d7699 Compare October 30, 2025 10:01
@poltorak poltorak force-pushed the refactor/vitest-configurations branch from e57bec1 to 4a71c54 Compare October 30, 2025 15:06
@poltorak poltorak force-pushed the refactor/vitest-configurations branch from 4a71c54 to 307217d Compare October 30, 2025 15:14
@poltorak poltorak force-pushed the refactor/vitest-configurations branch from a455669 to cef39d3 Compare October 31, 2025 15:37
Copy link
Collaborator

@matejchalk matejchalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there 🤞

Copy link
Collaborator

@matejchalk matejchalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, thanks for your persistence 👏

@matejchalk matejchalk merged commit a72e87c into main Nov 5, 2025
21 checks passed
@matejchalk matejchalk deleted the refactor/vitest-configurations branch November 5, 2025 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧩 models 📖 Project documentation improvements or additions to the project documentation 🔬 testing writing tests 🛠️ tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants