Skip to content

Modernize vitest.config.ts: remove manual __dirname, refine test exclusion pattern#422

Merged
jamespepper81 merged 3 commits into
devfrom
copilot/update-vitest-config-path
Jan 2, 2026
Merged

Modernize vitest.config.ts: remove manual __dirname, refine test exclusion pattern#422
jamespepper81 merged 3 commits into
devfrom
copilot/update-vitest-config-path

Conversation

Copilot AI commented Jan 2, 2026

Copy link
Copy Markdown

Removes legacy Node.js compatibility code and tightens test file exclusion pattern in vitest configuration.

Changes

  • Replace manual __dirname construction with process.cwd(): Removes fileURLToPath import and manual dirname computation. process.cwd() is standard for project root resolution in Node 20+.

  • Expand test exclusion pattern specificity: Changes **/tests/**/*.spec.ts to **/tests/**/*.{spec,e2e}.{ts,tsx} to explicitly match both .spec and .e2e test files in TypeScript/TSX formats, preventing accidental exclusion of unit tests with non-standard naming.

Before/After

- import { fileURLToPath } from 'url';
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
  
  resolve: {
    alias: {
-     '@': path.resolve(__dirname, './src'),
+     '@': path.resolve(process.cwd(), './src'),
    }
  }
  
  exclude: [
-   '**/tests/**/*.spec.ts',
+   '**/tests/**/*.{spec,e2e}.{ts,tsx}',
  ]
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The manual __dirname creation is unnecessary in modern Node.js environments. Consider using import.meta.dirname directly if targeting Node.js 20.11+ or use a more standard approach with process.cwd() for the project root.","fixFiles":[{"filePath":"vitest.config.ts","diff":"diff --git a/vitest.config.ts b/vitest.config.ts\n--- a/vitest.config.ts\n+++ b/vitest.config.ts\n@@ -2,8 +2,6 @@\n import path from 'path';\n import { fileURLToPath } from 'url';\n \n-const __dirname = path.dirname(fileURLToPath(import.meta.url));\n-\n export default defineConfig({\n   test: {\n     // Exclude Playwright tests from vitest\n@@ -19,7 +17,7 @@\n   },\n   resolve: {\n     alias: {\n-      '@': path.resolve(__dirname, './src'),\n+      '@': path.resolve(process.cwd(), './src'),\n     },\n   },\n });\n"}]},{"message":"[nitpick] The exclude pattern for Playwright tests may be too broad. Consider using a more specific pattern like '**/tests/**/*.{spec,e2e}.{ts,tsx}' to avoid accidentally excluding legitimate test files that might follow different naming conventions.","fixFiles":[{"filePath":"vitest.config.ts","diff":"diff --git a/vitest.config.ts b/vitest.config.ts\n--- a/vitest.config.ts\n+++ b/vitest.config.ts\n@@ -12,7 +12,7 @@\n       '**/dist/**',\n       '**/.{idea,git,cache,output,temp}/**',\n       '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',\n-      '**/tests/**/*.spec.ts', // Exclude Playwright test files\n+      '**/tests/**/*.{spec,e2e}.{ts,tsx}', // Exclude Playwright test files\n     ],\n     // Include only unit test files in src\n     include: ['src/**/*.test.ts', 'src/**/*.test.tsx'],\n"}]}]

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…on pattern

Co-authored-by: jamespepper81 <84083764+jamespepper81@users.noreply.github.com>
Copilot AI changed the title [WIP] Update vitest config to use process.cwd instead of __dirname Modernize vitest.config.ts: remove manual __dirname, refine test exclusion pattern Jan 2, 2026
Copilot AI requested a review from jamespepper81 January 2, 2026 12:06
@jamespepper81 jamespepper81 marked this pull request as ready for review January 2, 2026 12:18
@jamespepper81 jamespepper81 merged commit a069463 into dev Jan 2, 2026
@jamespepper81 jamespepper81 deleted the copilot/update-vitest-config-path branch January 2, 2026 12:18
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