Skip to content

Commit 4799551

Browse files
authored
test: align mocks with CommandExecutor options (#172)
* test: align mocks with CommandExecutor options * Expand filesystem DI and typecheck tests * test: deslop mocks and assertions * test: align nitpick test conventions
1 parent d50d826 commit 4799551

File tree

68 files changed

+1452
-1216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1452
-1216
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
"lint:fix": "eslint 'src/**/*.{js,ts}' --fix",
2828
"format": "prettier --write 'src/**/*.{js,ts}'",
2929
"format:check": "prettier --check 'src/**/*.{js,ts}'",
30-
"typecheck": "npx tsc --noEmit",
31-
"typecheck:tests": "npx tsc -p tsconfig.tests.json --noEmit",
32-
"typecheck:all": "npm run typecheck && npm run typecheck:tests",
30+
"typecheck": "npx tsc --noEmit && npx tsc -p tsconfig.test.json",
31+
"typecheck:tests": "npx tsc -p tsconfig.test.json",
3332
"verify:smithery-bundle": "bash scripts/verify-smithery-bundle.sh",
3433
"inspect": "npx @modelcontextprotocol/inspector node build/index.js",
3534
"doctor": "node build/doctor-cli.js",

src/mcp/resources/__tests__/simulators.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { describe, it, expect, beforeEach } from 'vitest';
22
import * as z from 'zod';
33

44
import simulatorsResource, { simulatorsResourceLogic } from '../simulators.ts';
5-
import { createMockExecutor } from '../../../test-utils/mock-executors.ts';
5+
import {
6+
createMockCommandResponse,
7+
createMockExecutor,
8+
} from '../../../test-utils/mock-executors.ts';
69

710
describe('simulators resource', () => {
811
describe('Export Field Validation', () => {
@@ -73,21 +76,19 @@ describe('simulators resource', () => {
7376
const mockExecutor = async (command: string[]) => {
7477
// JSON command returns invalid JSON
7578
if (command.includes('--json')) {
76-
return {
79+
return createMockCommandResponse({
7780
success: true,
7881
output: 'invalid json',
7982
error: undefined,
80-
process: { pid: 12345 },
81-
};
83+
});
8284
}
8385

8486
// Text command returns valid text output
85-
return {
87+
return createMockCommandResponse({
8688
success: true,
8789
output: mockTextOutput,
8890
error: undefined,
89-
process: { pid: 12345 },
90-
};
91+
});
9192
};
9293

9394
const result = await simulatorsResourceLogic(mockExecutor);

src/mcp/tools/device/__tests__/build_device.test.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import { describe, it, expect, beforeEach } from 'vitest';
88
import * as z from 'zod';
9-
import { createMockExecutor, createNoopExecutor } from '../../../../test-utils/mock-executors.ts';
9+
import {
10+
createMockCommandResponse,
11+
createMockExecutor,
12+
createNoopExecutor,
13+
} from '../../../../test-utils/mock-executors.ts';
1014
import buildDevice, { buildDeviceLogic } from '../build_device.ts';
1115
import { sessionStore } from '../../../../utils/session-store.ts';
1216

@@ -130,24 +134,24 @@ describe('build_device plugin', () => {
130134
it('should verify workspace command generation with mock executor', async () => {
131135
const commandCalls: Array<{
132136
args: string[];
133-
logPrefix: string;
134-
silent: boolean;
137+
logPrefix?: string;
138+
silent?: boolean;
135139
opts: { cwd?: string } | undefined;
136140
}> = [];
137141

138142
const stubExecutor = async (
139143
args: string[],
140-
logPrefix: string,
141-
silent: boolean,
144+
logPrefix?: string,
145+
silent?: boolean,
142146
opts?: { cwd?: string },
147+
_detached?: boolean,
143148
) => {
144149
commandCalls.push({ args, logPrefix, silent, opts });
145-
return {
150+
return createMockCommandResponse({
146151
success: true,
147152
output: 'Build succeeded',
148153
error: undefined,
149-
process: { pid: 12345 },
150-
};
154+
});
151155
};
152156

153157
await buildDeviceLogic(
@@ -182,24 +186,24 @@ describe('build_device plugin', () => {
182186
it('should verify command generation with mock executor', async () => {
183187
const commandCalls: Array<{
184188
args: string[];
185-
logPrefix: string;
186-
silent: boolean;
189+
logPrefix?: string;
190+
silent?: boolean;
187191
opts: { cwd?: string } | undefined;
188192
}> = [];
189193

190194
const stubExecutor = async (
191195
args: string[],
192-
logPrefix: string,
193-
silent: boolean,
196+
logPrefix?: string,
197+
silent?: boolean,
194198
opts?: { cwd?: string },
199+
_detached?: boolean,
195200
) => {
196201
commandCalls.push({ args, logPrefix, silent, opts });
197-
return {
202+
return createMockCommandResponse({
198203
success: true,
199204
output: 'Build succeeded',
200205
error: undefined,
201-
process: { pid: 12345 },
202-
};
206+
});
203207
};
204208

205209
await buildDeviceLogic(
@@ -291,24 +295,24 @@ describe('build_device plugin', () => {
291295
it('should include optional parameters in command', async () => {
292296
const commandCalls: Array<{
293297
args: string[];
294-
logPrefix: string;
295-
silent: boolean;
298+
logPrefix?: string;
299+
silent?: boolean;
296300
opts: { cwd?: string } | undefined;
297301
}> = [];
298302

299303
const stubExecutor = async (
300304
args: string[],
301-
logPrefix: string,
302-
silent: boolean,
305+
logPrefix?: string,
306+
silent?: boolean,
303307
opts?: { cwd?: string },
308+
_detached?: boolean,
304309
) => {
305310
commandCalls.push({ args, logPrefix, silent, opts });
306-
return {
311+
return createMockCommandResponse({
307312
success: true,
308313
output: 'Build succeeded',
309314
error: undefined,
310-
process: { pid: 12345 },
311-
};
315+
});
312316
};
313317

314318
await buildDeviceLogic(

0 commit comments

Comments
 (0)