(framework: string)
| 45 | console.table(getTable(results)); |
| 46 | |
| 47 | async function measure(framework: string) { |
| 48 | const { process: runningProcess, port } = await preview(framework); |
| 49 | // Give the server a sec to start up |
| 50 | await sleep(2000); |
| 51 | |
| 52 | const measureUrl = `http://localhost:${port}${path}`; |
| 53 | console.info( |
| 54 | `Getting lighthouse report for ${chalk.green(framework)} on ${measureUrl}` |
| 55 | ); |
| 56 | |
| 57 | const { report } = await getLighthouseReport(measureUrl, RUNS); |
| 58 | results[framework] = getSimpleReport(report); |
| 59 | |
| 60 | const outputDir = 'apps/components/src/reports'; |
| 61 | const pathFragment = path === '/' ? '/' : path + '/'; |
| 62 | const jsonPath = `${outputDir}${pathFragment}${framework}.json`; |
| 63 | const jsPath = `${outputDir}${pathFragment}${framework}.ts`; |
| 64 | |
| 65 | if (process.env.NO_WRITE !== 'true') { |
| 66 | await Promise.all([ |
| 67 | // Output results to a JSON file |
| 68 | fs.outputFile(jsonPath, JSON.stringify(report, null, 2)), |
| 69 | // Output results to a TS file for importing |
| 70 | fs.outputFile( |
| 71 | jsPath, |
| 72 | `export default ${JSON.stringify(report, null, 2)} as LH.Result` |
| 73 | ), |
| 74 | ]); |
| 75 | } |
| 76 | |
| 77 | // Don't throw an error when we kill the process below |
| 78 | runningProcess.catch(() => null); |
| 79 | await runningProcess.kill(); |
| 80 | } |
no test coverage detected