Skip to content

Commit f43ea43

Browse files
committed
fix(tests): prevent v8 coverage segfault on large codebase
Fixes segmentation fault when running `pnpm cover` by adding memory management and processing concurrency options. Changes: - Hoist logger to module scope in cover.mjs to fix ReferenceError - Use NODE_OPTIONS with --max-old-space-size=8192 for vitest coverage - Add processingConcurrency: 1 to vitest config to prevent v8 crashes - Add reportOnFailure: true and explicit reportsDirectory The segfault occurred because v8 coverage was processing too much data at once without sufficient memory. These changes allow the coverage command to complete successfully with 2,255 tests and 196 test files. Test Results: - 196 test files passed - 2,255 tests passed, 2 skipped - Type Coverage: 98.16% - Code Coverage: 37.17% - Cumulative: 67.66%
1 parent 229cb0f commit f43ea43

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"test:prepare": "dotenvx -q run -f .env.test -- pnpm build && del-cli 'test/**/node_modules'",
5757
"test:unit": "dotenvx -q run -f .env.test -- vitest run",
5858
"test:unit:update": "dotenvx -q run -f .env.test -- vitest run --update",
59-
"test:unit:coverage": "dotenvx -q run -f .env.test -- vitest run --coverage",
59+
"test:unit:coverage": "NODE_OPTIONS='--max-old-space-size=8192' dotenvx -q run -f .env.test -- vitest run --coverage",
6060
"test:validate": "node --import=./scripts/load.mjs scripts/validate-tests.mjs",
6161
"test:wrapper": "node --import=./scripts/load.mjs scripts/test-wrapper.mjs",
6262
"test-ci": "run-s test:*",

packages/cli/scripts/cover.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import { WIN32 } from '@socketsecurity/lib/constants/platform'
2020
import { getDefaultLogger } from '@socketsecurity/lib/logger'
2121
import { spawn } from '@socketsecurity/lib/spawn'
2222

23+
const logger = getDefaultLogger()
24+
2325
/**
2426
* Print a header message.
2527
*/
2628
function printHeader(message) {
27-
const logger = getDefaultLogger()
2829
logger.error(
2930
'\n═══════════════════════════════════════════════════════',
3031
)

packages/cli/vitest.config.mts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export default defineConfig({
8989
coverage: {
9090
provider: 'v8',
9191
reporter: ['text', 'json', 'html', 'lcov', 'clover'],
92+
// Prevent v8 coverage segfaults by processing in smaller chunks.
93+
processingConcurrency: 1,
94+
// Use less memory-intensive options.
95+
reportOnFailure: true,
96+
reportsDirectory: './coverage',
9297
exclude: [
9398
'**/*.config.*',
9499
'**/node_modules/**',

0 commit comments

Comments
 (0)