Skip to content

Commit 1f90910

Browse files
Remove app server setup and related code from global test setup
Co-authored-by: me <[email protected]>
1 parent 95bc36b commit 1f90910

File tree

1 file changed

+7
-83
lines changed

1 file changed

+7
-83
lines changed

exercises/02.start/01.solution/test/globalSetup.ts

Lines changed: 7 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ export default async function setup(project: TestProject) {
1313

1414
project.provide('mcpServerPort', mcpServerPort)
1515

16-
let appServerProcess: ReturnType<typeof execa> | null = null
1716
let mcpServerProcess: ReturnType<typeof execa> | null = null
1817

1918
// Buffers to store output for potential error display
20-
const appServerOutput: Array<string> = []
2119
const mcpServerOutput: Array<string> = []
2220

2321
/**
@@ -74,12 +72,6 @@ export default async function setup(project: TestProject) {
7472
* Display buffered output when there's a failure
7573
*/
7674
function displayBufferedOutput() {
77-
if (appServerOutput.length > 0) {
78-
console.log('=== App Server Output ===')
79-
for (const line of appServerOutput) {
80-
process.stdout.write(line)
81-
}
82-
}
8375
if (mcpServerOutput.length > 0) {
8476
console.log('=== MCP Server Output ===')
8577
for (const line of mcpServerOutput) {
@@ -88,42 +80,9 @@ export default async function setup(project: TestProject) {
8880
}
8981
}
9082

91-
async function startAppServerIfNecessary() {
92-
const isAppRunning = await fetch('http://localhost:7788/healthcheck').catch(
93-
() => ({ ok: false }),
94-
)
95-
if (isAppRunning.ok) {
96-
return
97-
}
98-
99-
const rootDir = process.cwd().replace(/exercises\/.*$/, '')
100-
101-
// Start the app server from the root directory
102-
console.log(`Starting app server on port 7788...`)
103-
appServerProcess = execa(
104-
'npm',
105-
[
106-
'run',
107-
'dev',
108-
'--prefix',
109-
'./epicshop/epic-me',
110-
'--',
111-
'--clearScreen=false',
112-
'--strictPort',
113-
],
114-
{
115-
cwd: rootDir,
116-
stdio: ['ignore', 'pipe', 'pipe'],
117-
},
118-
)
119-
}
120-
12183
async function startServers() {
12284
console.log('Starting servers...')
12385

124-
// Start app server if necessary
125-
await startAppServerIfNecessary()
126-
12786
// Start the MCP server from the exercise directory
12887
console.log(`Starting MCP server on port ${mcpServerPort}...`)
12988
mcpServerProcess = execa(
@@ -140,23 +99,13 @@ export default async function setup(project: TestProject) {
14099
)
141100

142101
try {
143-
// Wait for both servers to be ready simultaneously
144-
await Promise.all([
145-
appServerProcess
146-
? waitForServerReady({
147-
process: appServerProcess,
148-
textMatch: ':7788',
149-
name: '[APP-SERVER]',
150-
outputBuffer: appServerOutput,
151-
})
152-
: Promise.resolve(),
153-
waitForServerReady({
154-
process: mcpServerProcess,
155-
textMatch: `:${mcpServerPort.toString()}`,
156-
name: '[MCP-SERVER]',
157-
outputBuffer: mcpServerOutput,
158-
}),
159-
])
102+
// Wait for MCP server to be ready
103+
await waitForServerReady({
104+
process: mcpServerProcess,
105+
textMatch: `:${mcpServerPort.toString()}`,
106+
name: '[MCP-SERVER]',
107+
outputBuffer: mcpServerOutput,
108+
})
160109

161110
console.log('Servers started successfully')
162111
} catch (error) {
@@ -193,28 +142,6 @@ export default async function setup(project: TestProject) {
193142
)
194143
}
195144

196-
if (appServerProcess && !appServerProcess.killed) {
197-
cleanupPromises.push(
198-
(async () => {
199-
appServerProcess.kill('SIGTERM')
200-
// Give it 2 seconds to gracefully shutdown, then force kill
201-
const timeout = setTimeout(() => {
202-
if (appServerProcess && !appServerProcess.killed) {
203-
appServerProcess.kill('SIGKILL')
204-
}
205-
}, 2000)
206-
207-
try {
208-
await appServerProcess
209-
} catch {
210-
// Process was killed, which is expected
211-
} finally {
212-
clearTimeout(timeout)
213-
}
214-
})(),
215-
)
216-
}
217-
218145
// Wait for all cleanup to complete, but with an overall timeout
219146
try {
220147
await Promise.race([
@@ -232,9 +159,6 @@ export default async function setup(project: TestProject) {
232159
if (mcpServerProcess && !mcpServerProcess.killed) {
233160
mcpServerProcess.kill('SIGKILL')
234161
}
235-
if (appServerProcess && !appServerProcess.killed) {
236-
appServerProcess.kill('SIGKILL')
237-
}
238162
}
239163

240164
console.log('Servers cleaned up')

0 commit comments

Comments
 (0)