Warm package-runner-based Lighthouse commands before the benchmark. Args: command: The Lighthouse command prefix. Returns: The original command prefix.
(command: tuple[str, ...])
| 729 | |
| 730 | @cache |
| 731 | def _prepare_lighthouse_command(command: tuple[str, ...]) -> tuple[str, ...]: |
| 732 | """Warm package-runner-based Lighthouse commands before the benchmark. |
| 733 | |
| 734 | Args: |
| 735 | command: The Lighthouse command prefix. |
| 736 | |
| 737 | Returns: |
| 738 | The original command prefix. |
| 739 | """ |
| 740 | if not command or command[0] not in {"npx", "pnpx"}: |
| 741 | return command |
| 742 | |
| 743 | prepare_command = [*command, "--version"] |
| 744 | try: |
| 745 | subprocess.run( |
| 746 | prepare_command, |
| 747 | check=True, |
| 748 | capture_output=True, |
| 749 | text=True, |
| 750 | timeout=LIGHTHOUSE_COMMAND_PREP_TIMEOUT_SECONDS, |
| 751 | ) |
| 752 | except subprocess.CalledProcessError as err: |
| 753 | pytest.fail( |
| 754 | "Lighthouse CLI preparation failed. " |
| 755 | "If Lighthouse is not already installed, make sure the npm registry " |
| 756 | f"is reachable or set {LIGHTHOUSE_COMMAND_ENV_VAR} to an installed CLI.\n" |
| 757 | f"Command: {' '.join(prepare_command)}\n" |
| 758 | f"stdout:\n{_format_subprocess_output(err.stdout)}\n" |
| 759 | f"stderr:\n{_format_subprocess_output(err.stderr)}" |
| 760 | ) |
| 761 | except subprocess.TimeoutExpired as err: |
| 762 | pytest.fail( |
| 763 | f"Lighthouse CLI preparation timed out after {err.timeout}s. " |
| 764 | "If Lighthouse is not already installed, make sure the npm registry " |
| 765 | f"is reachable or set {LIGHTHOUSE_COMMAND_ENV_VAR} to an installed CLI.\n" |
| 766 | f"Command: {' '.join(prepare_command)}\n" |
| 767 | f"stdout:\n{_format_subprocess_output(err.stdout)}\n" |
| 768 | f"stderr:\n{_format_subprocess_output(err.stderr)}" |
| 769 | ) |
| 770 | |
| 771 | return command |
| 772 | |
| 773 | |
| 774 | def _get_lighthouse_target_url(url: str) -> str: |
no test coverage detected