Skip to content

Commit b51dbd2

Browse files
committed
Improve report command and error handling
- Updated option descriptions for clarity. - Enhanced error messages with formatting. - Simplified logic for determining report directories. - Added checks for local report directory existence. - Improved user prompts when starting the server.
1 parent e9d55f9 commit b51dbd2

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

qit

324 Bytes
Binary file not shown.

src/src/Commands/CustomTests/ShowReportCommand.php

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,47 @@ protected function configure() {
2727
$this
2828
->addArgument( 'report_dir', InputArgument::OPTIONAL, '(Optional) The report directory. If not set, will show the last report.' )
2929
->addOption( 'local', null, null, 'Force showing the local report instead of the remote one.' )
30-
->addOption( 'dir_only', null, null, 'Only show the report directory.' )
30+
->addOption( 'dir_only', null, null, 'Only output the local report directory path.' )
3131
->setDescription( 'Shows a test report.' );
3232
}
3333

3434
protected function execute( InputInterface $input, OutputInterface $output ): int {
35+
// Determine the report directories.
3536
if ( ! is_null( $input->getArgument( 'report_dir' ) ) ) {
3637
$local_report = $input->getArgument( 'report_dir' );
37-
$remote_report = null; // Assuming no remote report is provided when report_dir is specified.
38+
$remote_report = null; // Assuming no remote report when report_dir is specified.
3839
} else {
3940
$report_dir = json_decode( $this->cache->get( 'last_e2e_report' ) ?: '', true );
4041

4142
if ( empty( $report_dir ) ) {
42-
$output->writeln( 'No report found.' );
43+
$output->writeln( '<error>No report found.</error>' );
4344

4445
return Command::FAILURE;
4546
}
4647

4748
$local_report = $report_dir['local_playwright'];
48-
$remote_report = $report_dir['remote_qit'];
49+
$remote_report = $report_dir['remote_qit'] ?? null; // Use null coalescing in case 'remote_qit' is not set.
4950
}
5051

5152
// Handle --dir_only option early.
5253
if ( $input->getOption( 'dir_only' ) ) {
53-
if ( $input->getOption( 'local' ) || empty( $remote_report ) ) {
54-
// If --local is set or no remote report exists, show local directory.
55-
if ( ! file_exists( $local_report ) ) {
56-
throw new \RuntimeException( sprintf( 'Could not find the report directory: %s', $local_report ) );
57-
}
54+
// Check if the local report directory exists.
55+
if ( ! file_exists( $local_report ) ) {
56+
throw new \RuntimeException( sprintf( 'Could not find the report directory: %s', $local_report ) );
57+
}
5858

59-
$directory = dirname( $local_report );
60-
$output->writeln( $directory );
59+
// Output the local report directory path.
60+
$directory = realpath( $local_report );
61+
if ( $directory === false ) {
62+
throw new \RuntimeException( sprintf( 'Invalid report directory path: %s', $local_report ) );
63+
}
6164

62-
return Command::SUCCESS;
63-
} else {
64-
// Show remote directory if available and --local is not set.
65-
$directory = $remote_report;
66-
$output->writeln( $directory );
65+
$output->writeln( $directory );
6766

68-
return Command::SUCCESS;
69-
}
67+
return Command::SUCCESS;
7068
}
7169

72-
// If it has both local and remote, show the remote, unless "force-local" is true.
70+
// If remote_report exists and --local is not set, open the remote report.
7371
if ( ! $input->getOption( 'local' ) && ! empty( $remote_report ) ) {
7472
open_in_browser( $remote_report );
7573

@@ -87,16 +85,21 @@ protected function execute( InputInterface $input, OutputInterface $output ): in
8785

8886
try {
8987
$port = $this->start_server( $local_report );
90-
$output->writeln( "Server started on port: $port" );
88+
$output->writeln( "<info>Server started on port: $port</info>" );
9189
} catch ( \RuntimeException $e ) {
92-
$output->writeln( 'Error: ' . $e->getMessage() );
90+
$output->writeln( '<error>Error: ' . $e->getMessage() . '</error>' );
9391

9492
return Command::FAILURE;
9593
}
9694

9795
open_in_browser( "http://localhost:$port" );
9896

99-
( new QuestionHelper() )->ask( $input, $output, new Question( "Report available on http://localhost:$port. Press Ctrl+C to quit." ) );
97+
// Prompt the user to keep the server running.
98+
( new QuestionHelper() )->ask(
99+
$input,
100+
$output,
101+
new Question( "Report available on http://localhost:$port. Press Ctrl+C to quit." )
102+
);
100103

101104
return Command::SUCCESS;
102105
}

src/src/LocalTests/LocalTestRunNotifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function notify_test_finished( TestResult $test_result ): array {
161161
}
162162

163163
$test_result_json_original = $result_json;
164-
$result_json = $this->playwright_to_puppeteer_converter->convert_pw_to_puppeteer( json_decode( $result_json, true ) );
164+
$result_json = $this->playwright_to_puppeteer_converter->convert_pw_to_puppeteer( json_decode( $result_json, true ) );
165165
} else {
166166
$result_json = [];
167167
}

0 commit comments

Comments
 (0)