Skip to content

Commit f583700

Browse files
authored
Merge pull request #36 from lindentechde/ci/windows-re-enable
ci(tests): re-enable CLI / examples suites on Windows via shared helpers
2 parents 04a3e79 + c8b8ee4 commit f583700

6 files changed

Lines changed: 809 additions & 810 deletions

File tree

jest.config.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,14 @@ const baseConfig = {
88

99
coverageDirectory: 'coverage',
1010
coverageReporters: ['text', 'lcov', 'html', 'json'],
11-
// On Windows CI several CLI/integration suites are skipped (see
12-
// tests/cli-*.test.ts TODO(windows-ci) markers), which would otherwise
13-
// drop coverage below thresholds and mask the real signal. Skip the
14-
// coverage gate on win32.
15-
coverageThreshold:
16-
process.platform === 'win32'
17-
? undefined
18-
: {
19-
global: {
20-
branches: 55,
21-
functions: 75,
22-
lines: 68,
23-
statements: 68,
24-
},
25-
},
11+
coverageThreshold: {
12+
global: {
13+
branches: 55,
14+
functions: 75,
15+
lines: 68,
16+
statements: 68,
17+
},
18+
},
2619
testTimeout: 10000,
2720
verbose: true,
2821
maxWorkers: 1,

tests/cli-program.test.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jest.mock('chokidar', () => {
3535

3636
import * as fs from 'fs';
3737
import * as path from 'path';
38-
import * as os from 'os';
3938
import * as cliProgram from '../src/cli/program';
39+
import { canonicalTmpDir } from './helpers/paths';
4040

4141
const { createProgram, compileFile } = cliProgram;
4242

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

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

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

7472
afterEach(() => {
73+
// Restore cwd FIRST — on Windows, rmSync on the current working
74+
// directory raises EBUSY, which would throw and leave the next suite
75+
// with a stale cwd pointing at a deleted temp dir.
76+
try {
77+
process.chdir(originalCwd);
78+
} catch {
79+
// originalCwd may itself be gone in pathological cases; swallow and
80+
// keep going so we still restore spies and exit code.
81+
}
82+
7583
// Cleanup temp dir
7684
if (!skipCleanup && fs.existsSync(tempDir)) {
77-
fs.rmSync(tempDir, { recursive: true, force: true });
85+
try {
86+
fs.rmSync(tempDir, { recursive: true, force: true });
87+
} catch {
88+
// Windows occasionally keeps file handles open briefly after a
89+
// subprocess exits; the OS will reclaim the temp dir, and a failed
90+
// cleanup here must not break subsequent suites.
91+
}
7892
}
7993

80-
// Restore cwd
81-
process.chdir(originalCwd);
8294
// Reset any exit code left by CLI handlers during tests
8395
process.exitCode = originalExitCode ?? 0;
8496
consoleLogSpy.mockRestore();

0 commit comments

Comments
 (0)