chore: refactor Vitest configuration for unit and integration tests

- Split the main Vitest configuration into separate unit and integration configurations for better clarity and management.
- Update CLI and MCP package scripts to use the new configuration files.
- Remove legacy configuration files from CLI and MCP packages.
This commit is contained in:
Ralph Khreish
2026-01-27 19:30:39 +01:00
parent c7dff2c5e5
commit 526cb581ef
9 changed files with 128 additions and 162 deletions

View File

@@ -16,8 +16,8 @@
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"test:unit": "vitest run '**/*.spec.ts'",
"test:integration": "vitest run '**/*.test.ts'",
"test:unit": "vitest run --config ../../vitest.unit.config.ts",
"test:integration": "vitest run --config ../../vitest.integration.config.ts",
"test:e2e": "vitest run --dir tests/e2e",
"test:ci": "vitest run --coverage --reporter=dot"
},

View File

@@ -1,28 +0,0 @@
import { defineConfig, mergeConfig } from 'vitest/config';
import rootConfig from '../../vitest.config';
/**
* CLI package Vitest configuration
* Extends root config with CLI-specific settings
*
* Integration tests (.test.ts) spawn CLI processes and need more time.
* The 30s timeout is reasonable now that auto-update network calls are skipped
* when TASKMASTER_SKIP_AUTO_UPDATE=1 or NODE_ENV=test.
*/
export default mergeConfig(
rootConfig,
defineConfig({
test: {
// CLI-specific test patterns
include: [
'tests/**/*.test.ts',
'tests/**/*.spec.ts',
'src/**/*.test.ts',
'src/**/*.spec.ts'
],
// Integration tests spawn CLI processes - 30s is reasonable with optimized startup
testTimeout: 30000,
hookTimeout: 15000
}
})
);

View File

@@ -17,8 +17,8 @@
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"test:unit": "vitest run '**/*.spec.ts'",
"test:integration": "vitest run '**/*.test.ts'",
"test:unit": "vitest run --config ../../vitest.unit.config.ts",
"test:integration": "vitest run --config ../../vitest.integration.config.ts",
"test:ci": "vitest run --coverage --reporter=dot"
},
"dependencies": {

View File

@@ -1,21 +0,0 @@
import { defineConfig, mergeConfig } from 'vitest/config';
import rootConfig from '../../vitest.config';
/**
* MCP package Vitest configuration
* Extends root config with MCP-specific settings
*/
export default mergeConfig(
rootConfig,
defineConfig({
test: {
// MCP-specific test patterns
include: [
'tests/**/*.test.ts',
'tests/**/*.spec.ts',
'src/**/*.test.ts',
'src/**/*.spec.ts'
]
}
})
);

View File

@@ -21,8 +21,8 @@
},
"scripts": {
"test": "vitest run",
"test:unit": "vitest run '**/*.spec.ts'",
"test:integration": "vitest run '**/*.test.ts'",
"test:unit": "vitest run --config ../../vitest.unit.config.ts",
"test:integration": "vitest run --config ../../vitest.integration.config.ts",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"lint": "biome check --write",

View File

@@ -1,57 +0,0 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig, mergeConfig } from 'vitest/config';
import rootConfig from '../../vitest.config';
// __dirname in ESM
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* Core package Vitest configuration
* Extends root config with core-specific settings including:
* - Path aliases for cleaner imports
* - Test setup file
* - Higher coverage thresholds (80%)
*/
export default mergeConfig(
rootConfig,
defineConfig({
test: {
// Core-specific test patterns
include: [
'tests/**/*.test.ts',
'tests/**/*.spec.ts',
'tests/{unit,integration,e2e}/**/*.{test,spec}.ts',
'src/**/*.test.ts',
'src/**/*.spec.ts'
],
// Core-specific setup
setupFiles: ['./tests/setup.ts'],
// Higher coverage thresholds for core package
coverage: {
thresholds: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
}
},
// Path aliases for cleaner imports
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@/types': path.resolve(__dirname, './src/types'),
'@/providers': path.resolve(__dirname, './src/providers'),
'@/storage': path.resolve(__dirname, './src/storage'),
'@/parser': path.resolve(__dirname, './src/parser'),
'@/utils': path.resolve(__dirname, './src/utils'),
'@/errors': path.resolve(__dirname, './src/errors')
}
}
})
);

View File

@@ -1,61 +1,93 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* Root Vitest configuration for Task Master monorepo
* Provides shared defaults for all packages
* Individual packages can extend this config with package-specific settings
* Vitest workspace configuration for Task Master monorepo
*
* Convention: .spec.ts = unit tests, .test.ts = integration tests
*/
export default defineConfig({
test: {
// Enable global test APIs (describe, it, expect, etc.)
globals: true,
projects: [
// Core package
{
test: {
name: 'core:unit',
root: './packages/tm-core',
include: ['tests/**/*.spec.ts', 'src/**/*.spec.ts'],
setupFiles: ['./tests/setup.ts']
},
resolve: {
alias: {
'@': path.resolve(__dirname, './packages/tm-core/src'),
'@/types': path.resolve(__dirname, './packages/tm-core/src/types'),
'@/providers': path.resolve(__dirname, './packages/tm-core/src/providers'),
'@/storage': path.resolve(__dirname, './packages/tm-core/src/storage'),
'@/parser': path.resolve(__dirname, './packages/tm-core/src/parser'),
'@/utils': path.resolve(__dirname, './packages/tm-core/src/utils'),
'@/errors': path.resolve(__dirname, './packages/tm-core/src/errors')
}
}
},
{
test: {
name: 'core:integration',
root: './packages/tm-core',
include: ['tests/**/*.test.ts', 'src/**/*.test.ts'],
setupFiles: ['./tests/setup.ts']
},
resolve: {
alias: {
'@': path.resolve(__dirname, './packages/tm-core/src'),
'@/types': path.resolve(__dirname, './packages/tm-core/src/types'),
'@/providers': path.resolve(__dirname, './packages/tm-core/src/providers'),
'@/storage': path.resolve(__dirname, './packages/tm-core/src/storage'),
'@/parser': path.resolve(__dirname, './packages/tm-core/src/parser'),
'@/utils': path.resolve(__dirname, './packages/tm-core/src/utils'),
'@/errors': path.resolve(__dirname, './packages/tm-core/src/errors')
}
}
},
// Default environment for all packages (Node.js)
environment: 'node',
// CLI app
{
test: {
name: 'cli:unit',
root: './apps/cli',
include: ['tests/**/*.spec.ts', 'src/**/*.spec.ts']
}
},
{
test: {
name: 'cli:integration',
root: './apps/cli',
include: ['tests/**/*.test.ts', 'src/**/*.test.ts'],
// Integration tests spawn CLI processes - need longer timeouts
testTimeout: 30000,
hookTimeout: 15000
}
},
// Common test file patterns
include: [
'tests/**/*.test.ts',
'tests/**/*.spec.ts',
'src/**/*.test.ts',
'src/**/*.spec.ts'
],
// Common exclusions
exclude: ['node_modules', 'dist', '.git', '.cache', '**/node_modules/**'],
// Coverage configuration
coverage: {
provider: 'v8',
enabled: true,
reporter: ['text', 'json', 'html'],
include: ['src/**/*.ts'],
exclude: [
'node_modules/',
'dist/',
'tests/',
'**/*.test.ts',
'**/*.spec.ts',
'**/*.d.ts',
'**/mocks/**',
'**/fixtures/**',
'**/types/**',
'vitest.config.ts',
'src/index.ts'
],
// Default thresholds (can be overridden per package)
thresholds: {
branches: 70,
functions: 70,
lines: 70,
statements: 70
// MCP app
{
test: {
name: 'mcp:unit',
root: './apps/mcp',
include: ['tests/**/*.spec.ts', 'src/**/*.spec.ts']
}
},
{
test: {
name: 'mcp:integration',
root: './apps/mcp',
include: ['tests/**/*.test.ts', 'src/**/*.test.ts']
}
}
},
// Test execution settings
testTimeout: 10000,
clearMocks: true,
restoreMocks: true,
mockReset: true
]
}
});

View File

@@ -0,0 +1,20 @@
import { defineConfig } from 'vitest/config';
/**
* Integration test configuration
* Runs .test.ts files only, no coverage
*/
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['tests/**/*.test.ts', 'src/**/*.test.ts'],
exclude: ['node_modules', 'dist', '.git', '.cache', '**/node_modules/**'],
coverage: { enabled: false },
passWithNoTests: true,
testTimeout: 30000,
clearMocks: true,
restoreMocks: true,
mockReset: true
}
});

20
vitest.unit.config.ts Normal file
View File

@@ -0,0 +1,20 @@
import { defineConfig } from 'vitest/config';
/**
* Unit test configuration
* Runs .spec.ts files only, no coverage
*/
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['tests/**/*.spec.ts', 'src/**/*.spec.ts'],
exclude: ['node_modules', 'dist', '.git', '.cache', '**/node_modules/**'],
coverage: { enabled: false },
passWithNoTests: true,
testTimeout: 10000,
clearMocks: true,
restoreMocks: true,
mockReset: true
}
});