Skip to content

Commit 3a120f3

Browse files
committed
DEV stash
1 parent 6ed8e18 commit 3a120f3

File tree

5 files changed

+192
-78
lines changed

5 files changed

+192
-78
lines changed

jest.setupTests.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
// Shared helpers for all Jest tests
2+
3+
// Set NODE_ENV to test for all tests
4+
process.env.NODE_ENV = 'test';

src/server.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ const runServer = async (options = OPTIONS, {
4949
running = false;
5050
console.log('PatternFly MCP server stopped');
5151
process.exit(0);
52+
/*
53+
try {
54+
// Close the server first
55+
await server?.close();
56+
57+
// Close the transport if it exists
58+
if (transport) {
59+
// StdioServerTransport doesn't have a close method, but we can set it to null
60+
transport = null;
61+
}
62+
63+
running = false;
64+
console.log('PatternFly MCP server stopped');
65+
66+
// Only exit process if not in test environment
67+
if (process.env.NODE_ENV !== 'test') {
68+
process.exit(0);
69+
}
70+
} catch (error) {
71+
console.error('Error stopping server:', error);
72+
running = false;
73+
}
74+
*/
5275
}
5376
};
5477

@@ -72,7 +95,7 @@ const runServer = async (options = OPTIONS, {
7295
server?.registerTool(name, schema, callback);
7396
});
7497

75-
if (enableSigint) {
98+
if (enableSigint && process.env.NODE_ENV !== 'test') {
7699
process.on('SIGINT', async () => stopServer());
77100
}
78101

tests/cli.test.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,29 @@
44
* Focuses on CLI-specific functionality and parsing behavior.
55
*/
66

7+
import { start, type ServerInstance } from '../src/index';
78
import { OPTIONS, parseCliOptions, setOptions } from '../src/options';
89

910
describe('CLI Functionality', () => {
1011
let originalArgv: string[];
12+
let serverInstances: ServerInstance[] = [];
1113

1214
beforeEach(() => {
1315
// Store original process.argv
1416
originalArgv = process.argv;
17+
// Clear server instances array
18+
serverInstances = [];
1519
});
1620

17-
afterEach(() => {
21+
afterEach(async () => {
22+
// Clean up all server instances
23+
for (const server of serverInstances) {
24+
if (server.isRunning()) {
25+
await server.stop();
26+
}
27+
}
28+
serverInstances = [];
29+
1830
// Restore original process.argv
1931
process.argv = originalArgv;
2032
});
@@ -28,9 +40,11 @@ describe('CLI Functionality', () => {
2840

2941
expect(cliOptions.docsHost).toBe(true);
3042

31-
// Test setOptions() with CLI options
32-
setOptions(cliOptions);
43+
// Test start() with CLI options
44+
const server = await start(cliOptions);
45+
serverInstances.push(server);
3346
expect(OPTIONS.docsHost).toBe(true);
47+
expect(server.isRunning()).toBe(true);
3448
});
3549

3650
it('should handle CLI without --docs-host flag', async () => {
@@ -41,13 +55,11 @@ describe('CLI Functionality', () => {
4155

4256
expect(cliOptions.docsHost).toBe(false);
4357

44-
// Test setOptions with CLI options
45-
setOptions(cliOptions);
46-
expect(OPTIONS.docsHost).toBe(false);
47-
48-
// Test setOptions() with CLI options
49-
setOptions(cliOptions);
58+
// Test start() with CLI options
59+
const server = await start(cliOptions);
60+
serverInstances.push(server);
5061
expect(OPTIONS.docsHost).toBe(false);
62+
expect(server.isRunning()).toBe(true);
5163
});
5264

5365
it('should handle CLI with other arguments', async () => {
@@ -58,35 +70,35 @@ describe('CLI Functionality', () => {
5870

5971
expect(cliOptions.docsHost).toBe(false);
6072

61-
// Test setOptions with CLI options
62-
setOptions(cliOptions);
63-
expect(OPTIONS.docsHost).toBe(false);
64-
65-
// Test setOptions() with CLI options
66-
setOptions(cliOptions);
73+
// Test start() with CLI options
74+
const server = await start(cliOptions);
75+
serverInstances.push(server);
6776
expect(OPTIONS.docsHost).toBe(false);
77+
expect(server.isRunning()).toBe(true);
6878
});
6979

7080
it('should handle multiple CLI calls', async () => {
7181
// First CLI call with --docs-host
7282
process.argv = ['node', 'script.js', '--docs-host'];
7383
const cliOptions1 = parseCliOptions();
7484

75-
setOptions(cliOptions1);
76-
setOptions(cliOptions1);
85+
const server1 = await start(cliOptions1);
86+
serverInstances.push(server1);
7787

7888
expect(cliOptions1.docsHost).toBe(true);
7989
expect(OPTIONS.docsHost).toBe(true);
90+
expect(server1.isRunning()).toBe(true);
8091

8192
// Second CLI call without --docs-host
8293
process.argv = ['node', 'script.js'];
8394
const cliOptions2 = parseCliOptions();
8495

85-
setOptions(cliOptions2);
86-
setOptions(cliOptions2);
96+
const server2 = await start(cliOptions2);
97+
serverInstances.push(server2);
8798

8899
expect(cliOptions2.docsHost).toBe(false);
89100
expect(OPTIONS.docsHost).toBe(false);
101+
expect(server2.isRunning()).toBe(true);
90102
});
91103
});
92104
});

0 commit comments

Comments
 (0)