Skip to content

Handle absolute Vitest test roots#1650

Merged
webpro merged 10 commits into
webpro-nl:mainfrom
filipw01:fix-vitest-absolute-root
Mar 31, 2026
Merged

Handle absolute Vitest test roots#1650
webpro merged 10 commits into
webpro-nl:mainfrom
filipw01:fix-vitest-absolute-root

Conversation

@filipw01

@filipw01 filipw01 commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

This fixes Vitest configs that set test.root to an absolute path.

For example, this shape was not handled correctly:

import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';

const root = join(fileURLToPath(new URL('.', import.meta.url)), 'tests');

export default defineConfig({
  test: {
    root,
    include: ['*.test.ts'],
    setupFiles: ['./setup.ts'],
  },
});

Knip resolved test.root as if it were always relative to the config file directory, so an already-absolute root ended up being joined again and produced invalid paths.

This change uses toAbsolute(...) for Vitest test.root handling in:

  • config dependency resolution
  • test entry path resolution
  • build lib entry resolution

It also adds a regression fixture covering an absolute test.root.

@filipw01 filipw01 marked this pull request as draft March 30, 2026 12:38
@pkg-pr-new

pkg-pr-new Bot commented Mar 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@1650
npm i https://pkg.pr.new/@knip/language-server@1650
npm i https://pkg.pr.new/@knip/mcp@1650

commit: 9bab6c0

@filipw01 filipw01 marked this pull request as ready for review March 30, 2026 13:12
@webpro webpro merged commit 898a412 into webpro-nl:main Mar 31, 2026
29 checks passed
@webpro

webpro commented Mar 31, 2026

Copy link
Copy Markdown
Member

Thanks Filip!

@webpro

webpro commented Mar 31, 2026

Copy link
Copy Markdown
Member

🚀 This pull request is included in v6.1.1. See Release 6.1.1 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

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.

2 participants