( {
env = {},
preferConfiguredBaseUrl = true
}: {
env?: Record<string, string>
preferConfiguredBaseUrl?: boolean
} = {} )
| 90 | } |
| 91 | |
| 92 | export async function startAstroDevServer ( { |
| 93 | env = {}, |
| 94 | preferConfiguredBaseUrl = true |
| 95 | }: { |
| 96 | env?: Record<string, string> |
| 97 | preferConfiguredBaseUrl?: boolean |
| 98 | } = {} ): Promise<AstroDevServer> { |
| 99 | const configuredBaseUrl = process.env.PLAYWRIGHT_BASE_URL || '' |
| 100 | |
| 101 | if ( preferConfiguredBaseUrl && configuredBaseUrl.length > 0 ) { |
| 102 | await waitForServer( configuredBaseUrl ) |
| 103 | |
| 104 | return { |
| 105 | baseUrl: configuredBaseUrl, |
| 106 | output: { text: '' }, |
| 107 | process: null |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | const port = await getAvailablePort() |
| 112 | const baseUrl = `http://${ host }:${ port }` |
| 113 | const output = { text: '' } |
| 114 | |
| 115 | const childProcess = spawn( command, [ |
| 116 | 'exec', |
| 117 | 'astro', |
| 118 | 'dev', |
| 119 | '--host', |
| 120 | host, |
| 121 | '--port', |
| 122 | String( port ) |
| 123 | ], { |
| 124 | cwd: process.cwd(), |
| 125 | env: { |
| 126 | ...process.env, |
| 127 | ...env |
| 128 | }, |
| 129 | stdio: [ 'ignore', 'pipe', 'pipe' ] |
| 130 | } ) |
| 131 | |
| 132 | childProcess.stdout.on( 'data', chunk => { |
| 133 | output.text += chunk.toString() |
| 134 | } ) |
| 135 | childProcess.stderr.on( 'data', chunk => { |
| 136 | output.text += chunk.toString() |
| 137 | } ) |
| 138 | |
| 139 | await waitForServer( baseUrl ) |
| 140 | |
| 141 | return { |
| 142 | baseUrl, |
| 143 | output, |
| 144 | process: childProcess |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | export function stopChildProcess ( childProcess: ChildProcessWithoutNullStreams | null ) { |
| 149 | return new Promise<void>( resolve => { |
no test coverage detected