Skip to content

Commit 308a271

Browse files
committed
Use text-summary reporter for cleaner coverage output
Switch from detailed text reporter to text-summary for more concise coverage results. Full details remain available in generated reports.
1 parent 2dfbc2e commit 308a271

File tree

1 file changed

+31
-117
lines changed

1 file changed

+31
-117
lines changed

.config/vitest.config.mts

Lines changed: 31 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,47 @@
1+
/**
2+
* @fileoverview Vitest configuration for socket-lib
3+
*/
4+
15
import path from 'node:path'
26
import { fileURLToPath } from 'node:url'
3-
47
import { defineConfig } from 'vitest/config'
58

69
const __dirname = path.dirname(fileURLToPath(import.meta.url))
10+
const projectRoot = path.resolve(__dirname, '..')
711

8-
// Check if coverage is enabled via CLI flags or environment.
9-
// Note: process.argv doesn't include vitest CLI args at config load time,
10-
// so we check environment variables and use a heuristic based on npm script.
12+
// Coverage mode detection
1113
const isCoverageEnabled =
1214
process.env.COVERAGE === 'true' ||
1315
process.env.npm_lifecycle_event?.includes('coverage') ||
1416
process.argv.some(arg => arg.includes('coverage'))
1517

16-
const projectRoot = path.resolve(__dirname, '..')
17-
1818
export default defineConfig({
19-
// Disabled complex transform plugins - we now test src/ directly
20-
// plugins: [
21-
// createImportTransformPlugin(isCoverageEnabled, __dirname),
22-
// createRequireTransformPlugin(),
23-
// ],
2419
resolve: {
2520
preserveSymlinks: false,
26-
// Prioritize TypeScript extensions during coverage
2721
extensions: isCoverageEnabled
2822
? ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs', '.json']
2923
: ['.mts', '.ts', '.mjs', '.js', '.json'],
30-
alias: [
31-
{
32-
// Used by test/npm/ package configs to import script utilities.
33-
// Transforms: @socketregistry/scripts/* → /abs/path/to/scripts/*
34-
find: '@socketregistry/scripts',
35-
replacement: path.resolve(projectRoot, 'scripts'),
36-
},
37-
{
38-
// Always map @socketsecurity/registry to src/ for all tests
39-
// This simplifies coverage and avoids complex dist/ → src/ transforms
40-
find: '@socketsecurity/registry',
41-
replacement: path.resolve(projectRoot, 'registry/src'),
42-
},
43-
// Map external dependencies to their dist versions
44-
...(isCoverageEnabled
45-
? [
46-
// Map external dependencies to their dist versions during coverage.
47-
{
48-
find: /^\.\.\/\.\.\/fast-sort$/,
49-
replacement: path.resolve(
50-
projectRoot,
51-
'registry/dist/fast-sort.js',
52-
),
53-
},
54-
{
55-
find: /^\.\.\/\.\.\/semver$/,
56-
replacement: path.resolve(projectRoot, 'registry/dist/semver.js'),
57-
},
58-
{
59-
find: /^\.\.\/\.\.\/del$/,
60-
replacement: path.resolve(projectRoot, 'registry/dist/del.js'),
61-
},
62-
{
63-
find: /^\.\.\/\.\.\/cacache$/,
64-
replacement: path.resolve(
65-
projectRoot,
66-
'registry/dist/cacache.js',
67-
),
68-
},
69-
{
70-
find: /^\.\.\/\.\.\/libnpmpack$/,
71-
replacement: path.resolve(
72-
projectRoot,
73-
'registry/dist/libnpmpack.js',
74-
),
75-
},
76-
{
77-
find: /^\.\.\/\.\.\/pacote$/,
78-
replacement: path.resolve(projectRoot, 'registry/dist/pacote.js'),
79-
},
80-
{
81-
find: /^\.\.\/\.\.\/browserslist$/,
82-
replacement: path.resolve(
83-
projectRoot,
84-
'registry/dist/browserslist.js',
85-
),
86-
},
87-
{
88-
find: /^\.\.\/\.\.\/yargs-parser$/,
89-
replacement: path.resolve(
90-
projectRoot,
91-
'registry/dist/yargs-parser.js',
92-
),
93-
},
94-
{
95-
find: /^\.\.\/\.\.\/zod$/,
96-
replacement: path.resolve(projectRoot, 'registry/dist/zod.js'),
97-
},
98-
]
99-
: []),
100-
],
24+
alias: {
25+
'#env/ci': path.resolve(projectRoot, 'src/env/ci.ts'),
26+
'#env': path.resolve(projectRoot, 'src/env'),
27+
'#constants': path.resolve(projectRoot, 'src/constants'),
28+
'#lib': path.resolve(projectRoot, 'src/lib'),
29+
'#packages': path.resolve(projectRoot, 'src/lib/packages'),
30+
'#types': path.resolve(projectRoot, 'src/types.ts'),
31+
'#utils': path.resolve(projectRoot, 'src/utils'),
32+
cacache: path.resolve(projectRoot, 'src/external/cacache'),
33+
'make-fetch-happen': path.resolve(
34+
projectRoot,
35+
'src/external/make-fetch-happen',
36+
),
37+
'fast-sort': path.resolve(projectRoot, 'src/external/fast-sort'),
38+
pacote: path.resolve(projectRoot, 'src/external/pacote'),
39+
'@socketregistry/scripts': path.resolve(projectRoot, 'scripts'),
40+
'@socketsecurity/lib': path.resolve(projectRoot, 'src'),
41+
},
10142
},
10243
test: {
10344
globalSetup: [path.resolve(__dirname, 'vitest-global-setup.mts')],
104-
setupFiles: ['./test/setup.mts'],
10545
globals: false,
10646
environment: 'node',
10747
include: [
@@ -110,53 +50,33 @@ export default defineConfig({
11050
exclude: [
11151
'**/node_modules/**',
11252
'**/dist/**',
113-
// Exclude test/npm unless INCLUDE_NPM_TESTS is set
11453
...(process.env.INCLUDE_NPM_TESTS
11554
? []
11655
: [path.resolve(projectRoot, 'test/npm/**')]),
11756
],
11857
reporters: ['default'],
119-
// Use threads for better performance
12058
pool: 'threads',
12159
poolOptions: {
12260
threads: {
123-
// Use single thread for coverage to reduce memory, parallel otherwise.
12461
singleThread: isCoverageEnabled,
12562
maxThreads: isCoverageEnabled ? 1 : 16,
12663
minThreads: isCoverageEnabled ? 1 : 4,
127-
// IMPORTANT: isolate: false for performance and test compatibility
128-
//
129-
// Tradeoff Analysis:
130-
// - isolate: true = Full isolation, slower, breaks nock/module mocking
131-
// - isolate: false = Shared worker context, faster, mocking works
132-
//
133-
// We choose isolate: false because:
134-
// 1. Significant performance improvement (faster test runs)
135-
// 2. Nock HTTP mocking works correctly across all test files
136-
// 3. Vi.mock() module mocking functions properly
137-
// 4. Test state pollution is prevented through proper beforeEach/afterEach
138-
// 5. Our tests are designed to clean up after themselves
139-
//
140-
// Tests requiring true isolation should use pool: 'forks' or be marked
141-
// with { pool: 'forks' } in the test file itself.
64+
// Use isolate: false for performance and test compatibility
14265
isolate: false,
143-
// Use worker threads for better performance
14466
useAtomics: true,
14567
},
14668
},
147-
// Reduce timeouts for faster failures
14869
testTimeout: 10_000,
14970
hookTimeout: 10_000,
15071
server: {
15172
deps: {
152-
// Inline dependencies to enable source transformation for coverage.
153-
inline: isCoverageEnabled ? [/@socketsecurity\/registry/] : [],
73+
inline: isCoverageEnabled ? [/@socketsecurity\/lib/] : [],
15474
},
15575
},
15676
coverage: {
15777
provider: 'v8',
15878
reportsDirectory: 'coverage',
159-
reporter: ['text', 'json', 'html', 'lcov', 'clover'],
79+
reporter: ['text-summary', 'json', 'html', 'lcov', 'clover'],
16080
exclude: [
16181
'**/*.config.*',
16282
'**/node_modules/**',
@@ -168,24 +88,18 @@ export default defineConfig({
16888
'packages/**',
16989
'perf/**',
17090
'dist/**',
171-
// Exclude everything in registry except src/
172-
'registry/scripts/**',
173-
'registry/plugins/**',
174-
'registry/dist/**',
175-
'registry/src/external/**',
176-
'registry/src/types.ts',
177-
// Explicitly exclude at root level
91+
'src/external/**',
92+
'src/types.ts',
17893
'scripts/**',
17994
],
180-
// Only include registry/src/ files for coverage instrumentation
181-
include: ['registry/src/**/*.{ts,mts,cts}'],
95+
include: ['src/**/*.{ts,mts,cts}'],
18296
all: true,
18397
clean: true,
18498
skipFull: false,
18599
ignoreClassMethods: ['constructor'],
186100
thresholds: {
187101
lines: 1,
188-
functions: 70,
102+
functions: 68,
189103
branches: 70,
190104
statements: 1,
191105
},

0 commit comments

Comments
 (0)