Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ const baseConfig = {

coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html', 'json'],
// On Windows CI several CLI/integration suites are skipped (see
// tests/cli-*.test.ts TODO(windows-ci) markers), which would otherwise
// drop coverage below thresholds and mask the real signal. Skip the
// coverage gate on win32.
coverageThreshold:
process.platform === 'win32'
? undefined
: {
global: {
branches: 55,
functions: 75,
lines: 68,
statements: 68,
},
},
coverageThreshold: {
global: {
branches: 55,
functions: 75,
lines: 68,
statements: 68,
},
},
testTimeout: 10000,
verbose: true,
maxWorkers: 1,
Expand Down
28 changes: 20 additions & 8 deletions tests/cli-program.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jest.mock('chokidar', () => {

import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import * as cliProgram from '../src/cli/program';
import { canonicalTmpDir } from './helpers/paths';

const { createProgram, compileFile } = cliProgram;

Expand All @@ -47,9 +47,7 @@ const { createProgram, compileFile } = cliProgram;
* We stub process.exit and console to keep the test runner alive and to assert outputs.
*/

// TODO(windows-ci): this suite uses Windows 8.3 short paths and npm init in a temp
// directory; it needs explicit long-path handling before it can pass on win32.
(process.platform === 'win32' ? describe.skip : describe)('CLI Program (in-process)', () => {
describe('CLI Program (in-process)', () => {
let tempDir: string;
let originalCwd: string;
let originalExitCode: number | undefined;
Expand All @@ -59,7 +57,7 @@ const { createProgram, compileFile } = cliProgram;
let skipCleanup = false;

beforeEach(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'somon-cli-program-'));
tempDir = canonicalTmpDir('somon-cli-program-');
originalCwd = process.cwd();
originalExitCode = process.exitCode;
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
Expand All @@ -72,13 +70,27 @@ const { createProgram, compileFile } = cliProgram;
// Config loader behavior is covered in tests/config.test.ts.

afterEach(() => {
// Restore cwd FIRST β€” on Windows, rmSync on the current working
// directory raises EBUSY, which would throw and leave the next suite
// with a stale cwd pointing at a deleted temp dir.
try {
process.chdir(originalCwd);
} catch {
// originalCwd may itself be gone in pathological cases; swallow and
// keep going so we still restore spies and exit code.
}

// Cleanup temp dir
if (!skipCleanup && fs.existsSync(tempDir)) {
fs.rmSync(tempDir, { recursive: true, force: true });
try {
fs.rmSync(tempDir, { recursive: true, force: true });
} catch {
// Windows occasionally keeps file handles open briefly after a
// subprocess exits; the OS will reclaim the temp dir, and a failed
// cleanup here must not break subsequent suites.
}
}

// Restore cwd
process.chdir(originalCwd);
// Reset any exit code left by CLI handlers during tests
process.exitCode = originalExitCode ?? 0;
consoleLogSpy.mockRestore();
Expand Down
Loading
Loading