MCPcopy Create free account
hub / github.com/vercel/vercel / withDevServer

Function withDevServer

packages/python/test/middleware.test.ts:13–76  ·  view source on GitHub ↗
(
  workPath: string,
  fn: (url: string) => Promise<void>
)

Source from the content-addressed store, hash-verified

11const fixturePath = path.join(fixturesPath, '42-fastapi-middleware');
12
13async function withDevServer(
14 workPath: string,
15 fn: (url: string) => Promise<void>
16) {
17 const entrypoint = 'app.py';
18 const config = { framework: 'fastapi' as const };
19
20 // Create virtual environment and install dependencies if requirements.txt exists
21 const requirementsPath = path.join(workPath, 'requirements.txt');
22 if (await fs.pathExists(requirementsPath)) {
23 try {
24 // Create virtual environment
25 await execa('python3', ['-m', 'venv', '.venv'], {
26 cwd: workPath,
27 stdio: 'inherit',
28 });
29
30 // Install dependencies in venv
31 const venvPython =
32 process.platform === 'win32'
33 ? path.join(workPath, '.venv', 'Scripts', 'python.exe')
34 : path.join(workPath, '.venv', 'bin', 'python');
35
36 await execa(
37 venvPython,
38 ['-m', 'pip', 'install', '-r', 'requirements.txt'],
39 {
40 cwd: workPath,
41 stdio: 'inherit',
42 }
43 );
44 } catch (err) {
45 console.warn('Failed to create venv or install dependencies:', err);
46 // Continue anyway - maybe dependencies are already installed
47 }
48 }
49
50 const result = await startDevServer({
51 entrypoint,
52 workPath,
53 config,
54 meta: { isDev: true },
55 files: {},
56 repoRootPath: workPath,
57 });
58
59 if (!result) {
60 throw new Error('Failed to start dev server');
61 }
62
63 const { port, shutdown } = result;
64 const url = `http://127.0.0.1:${port}`;
65
66 // Wait a bit for server to be ready
67 await new Promise(resolve => setTimeout(resolve, 2000));
68
69 try {
70 await fn(url);

Callers 1

middleware.test.tsFile · 0.70

Calls 4

startDevServerFunction · 0.90
execaFunction · 0.85
shutdownFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected