Skip to content

Commit

Permalink
Improve terminal reporter format
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc45 committed Nov 21, 2024
1 parent 5c88b26 commit 0ff3272
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 220 deletions.
Binary file modified qit
Binary file not shown.
2 changes: 2 additions & 0 deletions src/src/Commands/CustomTests/RunE2ECommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ protected function execute( InputInterface $input, OutputInterface $output ): in
$test_mode = E2ETestManager::$test_modes['headless'];
}

App::setVar( 'TEST_MODE', $test_mode );

$wait = $input->getOption( 'up_only' ) || $test_mode === E2ETestManager::$test_modes['codegen'];
$woo_extension = $input->getArgument( 'woo_extension' );
$test = $input->getArgument( 'test' );
Expand Down
67 changes: 45 additions & 22 deletions src/src/LocalTests/E2E/Runner/PlaywrightOrchestration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace QIT_CLI\LocalTests\E2E\Runner;

use QIT_CLI\App;
use QIT_CLI\LocalTests\E2E\E2ETestManager;

class PlaywrightOrchestration {
/**
* // phpcs:disable Squiz.Commenting.FunctionComment.MissingParamName
Expand All @@ -25,15 +28,34 @@ public function make_projects( array $test_infos ): array {
$project_counter = 1;
$multiple_plugins = count( $test_infos ) > 1;

// Helper function to get readable plugin name.
$get_plugin_name = function ( string $slug ): string {
return ucwords( str_replace( [ 'woocommerce-', '-' ], [ '', ' ' ], $slug ) );
};

// Helper function to format project name with counter.
$format_name = function ( string $name ) use ( &$project_counter ): string {
/*
* In UI mode, prefixes the project name with a counter (e.g., "01 - [test] Plugin (Run)").
* This provides visual ordering of test order since dependencies aren't visible when running in UI mode.
*/
if ( in_array( App::getVar( 'TEST_MODE' ), [ E2ETestManager::$test_modes['codegen'], E2ETestManager::$test_modes['ui'] ], true ) ) {
return sprintf( '%02d - %s', $project_counter ++, $name );
} else {
return $name;
}
};

// Shared setups first.
foreach ( $test_infos as $t ) {
$plugin_slug = $t['slug'];
$base_dir = $t['path_in_php_container'];
$host_path = $t['path_in_host'];
$plugin_name = $get_plugin_name( $plugin_slug );

// Shared setups (sh, php, js).
if ( file_exists( "{$host_path}/bootstrap/shared-setup.sh" ) ) {
$name = sprintf( '%02d-%s-shared-setup-sh', $project_counter++, $plugin_slug );
$name = $format_name( "[setup:shared] $plugin_name (Shell)" );
$projects[] = [
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
Expand All @@ -49,7 +71,7 @@ public function make_projects( array $test_infos ): array {
}

if ( file_exists( "{$host_path}/bootstrap/shared-setup.php" ) ) {
$name = sprintf( '%02d-%s-shared-setup-php', $project_counter++, $plugin_slug );
$name = $format_name( "[setup:shared] $plugin_name (PHP)" );
$projects[] = [
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
Expand All @@ -65,7 +87,7 @@ public function make_projects( array $test_infos ): array {
}

if ( file_exists( "{$host_path}/bootstrap/shared-setup.js" ) ) {
$name = sprintf( '%02d-%s-shared-setup-js', $project_counter++, $plugin_slug );
$name = $format_name( "[setup:shared] $plugin_name (JS)" );
$projects[] = [
'name' => $name,
'testDir' => "{$base_dir}/bootstrap",
Expand All @@ -85,7 +107,7 @@ public function make_projects( array $test_infos ): array {

// DB Export only for multiple plugins.
if ( $multiple_plugins ) {
$name = sprintf( '%02d-db-export', $project_counter++ );
$name = $format_name( '[db export' );
$projects[] = [
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
Expand All @@ -103,24 +125,25 @@ public function make_projects( array $test_infos ): array {
$plugin_slug = $t['slug'];
$base_dir = $t['path_in_php_container'];
$host_path = $t['path_in_host'];
$plugin_name = $get_plugin_name( $plugin_slug );
$current_setup = $last_operation ?: null;

if ( ! $first_test && $multiple_plugins ) {
// Add DB import before subsequent tests - depends on previous plugin's complete chain.
$import_name = sprintf( '%02d-db-import-before-%s', $project_counter++, $plugin_slug );
// Add DB import before subsequent tests
$name = $format_name( "[db import" );
$projects[] = [
'name' => $import_name,
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
'testMatch' => 'db-import.js',
'dependencies' => [ $last_operation ],
'use' => [ 'browserName' => 'chromium' ],
];
$current_setup = $import_name;
$current_setup = $name;
}

// Isolated setups (sh, php, js).
if ( file_exists( "{$host_path}/bootstrap/setup.sh" ) ) {
$name = sprintf( '%02d-%s-isolated-setup-sh', $project_counter++, $plugin_slug );
$name = $format_name( "[setup] $plugin_name (Shell)" );
$projects[] = [
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
Expand All @@ -136,7 +159,7 @@ public function make_projects( array $test_infos ): array {
}

if ( file_exists( "{$host_path}/bootstrap/setup.php" ) ) {
$name = sprintf( '%02d-%s-isolated-setup-php', $project_counter++, $plugin_slug );
$name = $format_name( "[setup] $plugin_name (PHP)" );
$projects[] = [
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
Expand All @@ -152,7 +175,7 @@ public function make_projects( array $test_infos ): array {
}

if ( file_exists( "{$host_path}/bootstrap/setup.js" ) ) {
$name = sprintf( '%02d-%s-isolated-setup-js', $project_counter++, $plugin_slug );
$name = $format_name( "[setup] $plugin_name (JS)" );
$projects[] = [
'name' => $name,
'testDir' => "{$base_dir}/bootstrap",
Expand All @@ -167,9 +190,9 @@ public function make_projects( array $test_infos ): array {
}

// Add the actual test phase.
$test_name = sprintf( '%02d-%s-test', $project_counter++, $plugin_slug );
$name = $format_name( "[test] $plugin_name (Run)" );
$projects[] = [
'name' => $test_name,
'name' => $name,
'testDir' => $base_dir,
'testMatch' => '**/*.spec.js',
'dependencies' => $current_setup ? [ $current_setup ] : [],
Expand All @@ -178,11 +201,11 @@ public function make_projects( array $test_infos ): array {
'qitTestSlug' => $plugin_slug,
],
];
$current_setup = $test_name;
$current_setup = $name;

// Add isolated teardowns.
if ( file_exists( "{$host_path}/bootstrap/teardown.sh" ) ) {
$name = sprintf( '%02d-%s-isolated-teardown-sh', $project_counter++, $plugin_slug );
$name = $format_name( "[teardown] $plugin_name (Shell)" );
$projects[] = [
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
Expand All @@ -198,7 +221,7 @@ public function make_projects( array $test_infos ): array {
}

if ( file_exists( "{$host_path}/bootstrap/teardown.php" ) ) {
$name = sprintf( '%02d-%s-isolated-teardown-php', $project_counter++, $plugin_slug );
$name = $format_name( "[teardown] $plugin_name (PHP)" );
$projects[] = [
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
Expand All @@ -214,7 +237,7 @@ public function make_projects( array $test_infos ): array {
}

if ( file_exists( "{$host_path}/bootstrap/teardown.js" ) ) {
$name = sprintf( '%02d-%s-isolated-teardown-js', $project_counter++, $plugin_slug );
$name = $format_name( "[teardown] $plugin_name (JS)" );
$projects[] = [
'name' => $name,
'testDir' => "{$base_dir}/bootstrap",
Expand All @@ -228,7 +251,6 @@ public function make_projects( array $test_infos ): array {
$current_setup = $name;
}

// Update last_operation after all plugin operations (setup, test, teardown) are complete.
$last_operation = $current_setup;
$first_test = false;
}
Expand All @@ -238,9 +260,10 @@ public function make_projects( array $test_infos ): array {
$plugin_slug = $t['slug'];
$base_dir = $t['path_in_php_container'];
$host_path = $t['path_in_host'];
$plugin_name = $get_plugin_name( $plugin_slug );

if ( file_exists( "{$host_path}/bootstrap/shared-teardown.sh" ) ) {
$name = sprintf( '%02d-%s-shared-teardown-sh', $project_counter++, $plugin_slug );
$name = $format_name( "[teardown:shared] $plugin_name (Shell)" );
$projects[] = [
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
Expand All @@ -256,7 +279,7 @@ public function make_projects( array $test_infos ): array {
}

if ( file_exists( "{$host_path}/bootstrap/shared-teardown.php" ) ) {
$name = sprintf( '%02d-%s-shared-teardown-php', $project_counter++, $plugin_slug );
$name = $format_name( "[teardown:shared] $plugin_name (PHP)" );
$projects[] = [
'name' => $name,
'testDir' => '/qit/tests/e2e/scripts',
Expand All @@ -272,7 +295,7 @@ public function make_projects( array $test_infos ): array {
}

if ( file_exists( "{$host_path}/bootstrap/shared-teardown.js" ) ) {
$name = sprintf( '%02d-%s-shared-teardown-js', $project_counter++, $plugin_slug );
$name = $format_name( "[teardown:shared] $plugin_name (JS)" );
$projects[] = [
'name' => $name,
'testDir' => "{$base_dir}/bootstrap",
Expand All @@ -289,4 +312,4 @@ public function make_projects( array $test_infos ): array {

return $projects;
}
}
}
16 changes: 16 additions & 0 deletions src/src/LocalTests/E2E/Runner/PlaywrightRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,22 @@ public function run_test( E2EEnvInfo $env_info, array $test_infos, TestResult $t
// Remove same-line cursor movement and clear line.
$out = preg_replace( '/\e\[\d*[ABCD]/', '', $out ); // Remove cursor movements.
$out = preg_replace( '/\e\[2K/', '', $out ); // Remove clear line codes.
/*
* [[setup:
* [[db]
* [[test]
* [[teardown:
* Remove double brackets (keep everything else)
*/
$out = preg_replace( '/\[\[(setup|db|test|teardown)/', '[$1', $out );
/*
* (Shell)]
* (JS)]
* (PHP)]
* Remove unnecessary brackets.
*/
$out = preg_replace( '/\((Shell|JS|PHP)\)]/', '($1)', $out );

$out = trim( $out );

if ( empty( $out ) ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"name": "01-test-slug-test",
"name": "[test] Test Slug (Run)",
"testDir": "test-path-in-php-container",
"testMatch": "**\/*.spec.js",
"dependencies": [],
Expand Down
Loading

0 comments on commit 0ff3272

Please sign in to comment.