MCPcopy
hub / github.com/resend/react-email / startWebServer

Function startWebServer

packages/render/e2e/integrations.spec.ts:94–135  ·  view source on GitHub ↗
(command: string, url: string, cwd: string)

Source from the content-addressed store, hash-verified

92};
93
94const startWebServer = async (command: string, url: string, cwd: string) => {
95 const output: string[] = [];
96 const appendOutput = (source: 'stdout' | 'stderr', chunk: Buffer) => {
97 output.push(`[${source}] ${chunk.toString()}`);
98 output.splice(0, Math.max(0, output.length - 40));
99 };
100 const formatOutput = () =>
101 output.length === 0
102 ? 'No server output was captured.'
103 : output.join('').trim();
104 const child = child_process.spawn(command, {
105 shell: true,
106 cwd,
107 detached: process.platform !== 'win32',
108 stdio: ['ignore', 'pipe', 'pipe'],
109 });
110 child.stdout?.on('data', (chunk) => appendOutput('stdout', chunk));
111 child.stderr?.on('data', (chunk) => appendOutput('stderr', chunk));
112
113 const childExit = new Promise<never>((_, reject) => {
114 child.once('error', reject);
115 child.once('exit', (code, signal) => {
116 reject(
117 new Error(
118 `Command "${command}" exited before ${url} became available. Exit code: ${code}; signal: ${signal}.\n\n${formatOutput()}`,
119 ),
120 );
121 });
122 });
123
124 try {
125 await Promise.race([waitForServer(url, 30_000), childExit]);
126 } catch (error) {
127 stopWebServer(child);
128 if (error instanceof Error) {
129 throw new Error(`${error.message}\n\n${formatOutput()}`);
130 }
131 throw error;
132 }
133
134 return child;
135};
136
137describe('integrations', () => {
138 let page!: playwright.Page;

Callers 1

Calls 5

appendOutputFunction · 0.85
formatOutputFunction · 0.85
waitForServerFunction · 0.85
stopWebServerFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…