Skip to content

test: use vitest workspaces #32121

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

Merged
merged 8 commits into from
May 15, 2025
Merged

test: use vitest workspaces #32121

merged 8 commits into from
May 15, 2025

Conversation

danielroe
Copy link
Member

🔗 Linked issue

📚 Description

using new nuxt/test-utils v3.19, we can now adopt vitest workspaces for simpler configuration

@danielroe danielroe self-assigned this May 15, 2025
@Copilot Copilot AI review requested due to automatic review settings May 15, 2025 15:00
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

socket-security bot commented May 15, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​nuxt/​test-utils@​3.18.0 ⏵ 3.19.097 +110075 +196 +4100

View full report

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Vitest configuration to adopt workspaces using the new nuxt/test-utils v3.19, simplifying test setup.

  • Removed the standalone nuxt config file (vitest.nuxt.config.ts) since nuxt tests are now managed via a workspace in vitest.config.ts
  • Added workspace definitions for "fixtures", "unit", and "nuxt" projects in vitest.config.ts
  • Updated package.json test commands to target specific workspace projects

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
vitest.nuxt.config.ts Removed configuration as its functionality is merged into the workspace
vitest.config.ts Added and updated workspace definitions for test projects
package.json Adjusted test commands to support the new workspace-based configuration
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

coderabbitai bot commented May 15, 2025

Walkthrough

The Vitest testing configuration was refactored from a single global setup to a multi-workspace structure within vitest.config.ts. The new configuration defines separate workspaces for "benchmark", "fixtures", "unit", and "nuxt" tests, each with tailored settings, test file patterns, and environment configurations. The "nuxt" workspace is now integrated asynchronously using defineVitestProject from @nuxt/test-utils/config, consolidating its configuration into the main file and removing the standalone vitest.nuxt.config.ts. Coverage exclusions and some global options were adjusted, and the configuration now modularises test environments and setups for different project areas. Additionally, the GitHub workflows for testing were simplified by merging separate test commands into single steps that run multiple test projects concurrently.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2956734 and 24f12a4.

📒 Files selected for processing (1)
  • vitest.config.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • vitest.config.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: codeql (actions)
  • GitHub Check: build
  • GitHub Check: codeql (javascript-typescript)
  • GitHub Check: code
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
vitest.config.ts (2)

11-12: Duplicate or overly-broad coverage exclusion pattern

'**/test/' is already fully covered by Vitest’s default coverageConfigDefaults.exclude (test, **/*.test.*, etc.). Keeping redundant globs makes the list harder to maintain and slightly slows glob-resolution on large workspaces.

-      exclude: [...coverageConfigDefaults.exclude, 'playground', '**/test/', 'scripts', 'vitest.nuxt.config.ts'],
+      exclude: [...coverageConfigDefaults.exclude, 'playground', 'scripts', 'vitest.nuxt.config.ts'],

24-33: Alias points to built artefacts – consider targeting source for faster iteration

'#app': resolve('./packages/nuxt/dist/app') aliases the built output.
During unit tests it is usually faster (and yields better stack traces) to alias to the TypeScript source (./packages/nuxt/src/app) and let esbuild transform it on-the-fly.

If the dist path is intentional (e.g. to mimic production), add an inline comment explaining the choice to prevent accidental “optimisation”.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c45060 and 82f03eb.

⛔ Files ignored due to path filters (2)
  • package.json is excluded by !package.json, !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (2)
  • vitest.config.ts (1 hunks)
  • vitest.nuxt.config.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • vitest.nuxt.config.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: code
🔇 Additional comments (2)
vitest.config.ts (2)

15-22: Fixture workspace configuration looks solid

Test patterns, timeout differentiation for Windows, and explicit exclusion of e2e paths are all sensible. 👍


43-70:

✅ Verification successful

Top-level await inside a plain object risks breaking older Node/Vitest runners

Although Node ≥ 20 and recent Vitest versions accept top-level await, many CI images (and some editors’ TS servers) still pin older Node or use CommonJS transpilation for *.ts configs, leading to a syntax error.

Wrap the config in an async factory to guarantee support:

-export default defineConfig({
+export default defineConfig(async () => ({
   ...
-      await defineVitestProject({
+      await defineVitestProject({
         test: {
           name: 'nuxt',
           ...
         },
       }),
   ...
-})
+}))

Ensure the CI matrix uses a Node version that supports top-level await (≥ 14.8 when ESM, but ≥ 16 is safer) if you keep the current style.


Let’s verify the Node versions specified in our CI workflows to ensure top-level await is safe:


🏁 Script executed:

#!/bin/bash
set -e
# Search for Node.js setup in GitHub Actions workflows
rg -n "uses:.*actions/setup-node" -n .github/workflows || echo "No setup-node found in workflows"
# Search for explicit node-version fields
rg -n "node-version" -n .github/workflows || echo "No node-version fields found in workflows"

Length of output: 2751


Let’s inspect the Node matrix in .github/workflows/ci.yml to see which versions are tested:


🏁 Script executed:

#!/bin/bash
set -e
# Show the matrix definition around line 290
sed -n '250,330p' .github/workflows/ci.yml

Length of output: 2628


Top-level await is safe with Node 20 in CI
Verified that all GitHub Actions workflows (lts/* and the explicit node: [20] matrix) run on Node 20. Top-level await in vitest.config.ts is fully supported—no async factory wrapper is needed.

Copy link

pkg-pr-new bot commented May 15, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@32121

nuxt

npm i https://pkg.pr.new/nuxt@32121

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@32121

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@32121

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@32121

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@32121

commit: 24f12a4

Copy link

codspeed-hq bot commented May 15, 2025

CodSpeed Performance Report

Merging #32121 will not alter performance

Comparing wip/workspace (24f12a4) with main (9c45060)

Summary

✅ 10 untouched benchmarks

package.json Outdated
@@ -26,12 +26,12 @@
"play:preview": "nuxi preview playground",
"test": "pnpm test:fixtures && pnpm test:fixtures:dev && pnpm test:fixtures:webpack && pnpm test:unit && pnpm test:runtime && pnpm test:types && pnpm typecheck",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it shoud be possible to combine at least test:runtime, test:unit, test:fixtures into a single vitest run (or vitest run --project fixtures --project unit --project nuxt) command. I think this can speedup the tests because vitest can decide the order :)

Copy link
Member Author

Choose a reason for hiding this comment

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

it is indeed!

Copy link
Collaborator

@OrbisK OrbisK May 15, 2025

Choose a reason for hiding this comment

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

This might also speed up ci here:

- name: Test (unit)
run: pnpm test:unit
- name: Test (runtime unit)
run: pnpm test:runtime

Copy link
Collaborator

@OrbisK OrbisK May 15, 2025

Choose a reason for hiding this comment

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

sadly vitest workspace extend is limited to configs, not other workspace projects. But I think we can even get the dev and webpack variants as separate projects (to put them into one command):

pseudo code:

const fixturesProject =  {
  test: {
    // config here
  },
}
export default defineConfig({
  test: {
    workspace: [
      defu(fixturesProject, { test: {env: {name: 'fixtures'}),
      defu(fixturesProject, { test: {env: {TEST_ENV: 'dev', name: 'fixtures:dev'})
    ],
  },
})

Copy link
Member Author

Choose a reason for hiding this comment

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

there are a lot of variants and I'm not sure they we should add them all as separate projects

@danielroe danielroe merged commit c65550c into main May 15, 2025
48 checks passed
@danielroe danielroe deleted the wip/workspace branch May 15, 2025 21:05
@github-actions github-actions bot mentioned this pull request May 15, 2025
@github-actions github-actions bot mentioned this pull request May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy