Skip to content

Commit 7fb3f0e

Browse files
committed
cleanup
1 parent d02986b commit 7fb3f0e

File tree

7 files changed

+82
-652
lines changed

7 files changed

+82
-652
lines changed

CHANGELOG.md

Lines changed: 0 additions & 90 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@
112112
"node"
113113
],
114114
"testMatch": [
115-
"**/__tests__/**/*.test.ts",
116-
"**/__tests__/**/*.test.js"
115+
"**/__tests__/**/*.test.ts"
117116
],
118117
"verbose": false,
119118
"forceExit": true,

src/__tests__/converterManager.paths.test.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { describe, it, expect, jest, beforeEach } from '@jest/globals';
22
import { EventEmitter } from 'events';
3+
import {
4+
createFindBinaryMock,
5+
joinWithSeparator,
6+
} from './test-utils/pathResolutionMocks.js';
37

48
type PathStyle = 'posix' | 'win32';
59

@@ -8,11 +12,6 @@ type SetupOptions = {
812
isPackagedRuntime: boolean;
913
};
1014

11-
const makeJoin = (style: PathStyle) => {
12-
const sep = style === 'win32' ? '\\' : '/';
13-
return (...parts: string[]) => parts.join(sep);
14-
};
15-
1615
async function setupAndImportConverterManager(options: SetupOptions) {
1716
jest.resetModules();
1817

@@ -22,7 +21,8 @@ async function setupAndImportConverterManager(options: SetupOptions) {
2221
console.warn = jest.fn();
2322
console.error = jest.fn();
2423

25-
const join = makeJoin(options.pathStyle);
24+
const sep = options.pathStyle === 'win32' ? '\\' : '/';
25+
const join = joinWithSeparator(sep);
2626
const moduleDir = options.pathStyle === 'win32' ? 'C:\\MODDIR' : '/MODDIR';
2727
const cwdDir = options.pathStyle === 'win32' ? 'C:\\CWD' : '/CWD';
2828
const runtimeBaseDir =
@@ -78,18 +78,12 @@ async function setupAndImportConverterManager(options: SetupOptions) {
7878
getAnswer: jest.fn(async () => ''),
7979
runtimeBaseDir,
8080
isPackagedRuntime: options.isPackagedRuntime,
81-
findBinary: (name: string, subdirs: string[] = []) => {
82-
const roots = [runtimeBaseDir, cwdDir];
83-
for (const root of roots) {
84-
const direct = join(root, name);
85-
if (existsSyncMock(direct)) return direct;
86-
for (const sub of subdirs) {
87-
const candidate = join(root, sub, name);
88-
if (existsSyncMock(candidate)) return candidate;
89-
}
90-
}
91-
return null;
92-
},
81+
findBinary: createFindBinaryMock({
82+
sep,
83+
runtimeBaseDir,
84+
pathExists: (path: string) => existsSyncMock(path),
85+
includeCwd: true,
86+
}),
9387
}));
9488

9589
const cwdSpy = jest.spyOn(process, 'cwd').mockReturnValue(cwdDir);

src/__tests__/converterWorker.paths.test.ts

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { jest, describe, it, expect, afterEach } from '@jest/globals';
2+
import { createFindBinaryMock } from './test-utils/pathResolutionMocks.js';
23

34
type Config = {
45
sep: '/' | '\\';
@@ -69,32 +70,12 @@ jest.unstable_mockModule('../utils.js', () => ({
6970
},
7071
getErrorMessage: (error: unknown) =>
7172
error instanceof Error ? error.message : String(error || 'Unknown error'),
72-
findBinary: (name: string, subdirs: string[] = []) => {
73-
const sep = config.sep;
74-
const roots = [config.runtimeBaseDir];
75-
// Also check process.cwd() if it were relevant, but tests control via config.exists
76-
for (const root of roots) {
77-
const direct = [root, name].join(sep);
78-
if (config.exists.has(direct)) return direct;
79-
for (const sub of subdirs) {
80-
const candidate = [root, sub, name].join(sep);
81-
if (config.exists.has(candidate)) return candidate;
82-
}
83-
}
84-
// Check cwd-based paths too
85-
try {
86-
const cwd = process.cwd();
87-
const direct = [cwd, name].join(sep);
88-
if (config.exists.has(direct)) return direct;
89-
for (const sub of subdirs) {
90-
const candidate = [cwd, sub, name].join(sep);
91-
if (config.exists.has(candidate)) return candidate;
92-
}
93-
} catch {
94-
/* ignore */
95-
}
96-
return null;
97-
},
73+
findBinary: createFindBinaryMock({
74+
sep: config.sep,
75+
runtimeBaseDir: config.runtimeBaseDir,
76+
pathExists: (path: string) => config.exists.has(path),
77+
includeCwd: true,
78+
}),
9879
}));
9980

10081
jest.unstable_mockModule('../metadataService.js', () => ({

0 commit comments

Comments
 (0)