Skip to content

Commit

Permalink
Merge pull request #125 from woocommerce/24-01/api-e2e-test-type
Browse files Browse the repository at this point in the history
Rename "api" to "woo-api" and "e2e" to "woo-e2e"
  • Loading branch information
Luc45 authored Feb 11, 2024
2 parents 12cacf6 + 3bd4584 commit 7fb1938
Show file tree
Hide file tree
Showing 48 changed files with 61 additions and 62 deletions.
26 changes: 1 addition & 25 deletions _tests/ParallelOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct() {
$this->processStatus = [];
$this->startTimes = [];
$this->nonJsonOutput = [];
register_shutdown_function( [ $this, 'onShutdown' ] );
register_shutdown_function( [ $this, 'displayBufferedOutputs' ] );
}

public function addRawOutput( string $output ) {
Expand Down Expand Up @@ -96,28 +96,4 @@ protected function displayBufferedOutputs() {
echo "$status\n";
}
}

public function onShutdown() {
if ( getenv( "CI" ) ) {
echo $this->rawOutput . "\n";

// Print the accumulated output for each task in CI environment
foreach ( $this->outputBuffer as $taskId => $output ) {
echo "\033[1;33m" . $this->headers[ $taskId ] . "\033[0m\n"; // Yellow for headers
echo $output . "\n"; // Print the accumulated output

if ( ! empty( $this->nonJsonOutput[ $taskId ] ) && file_exists( $this->nonJsonOutput[ $taskId ] ) ) {
echo file_get_contents( $this->nonJsonOutput[ $taskId ] ) . "\n";
} else {
echo "No non-json output file found for task $taskId\n";
}
}

// Print the summary section
echo "\n\033[1;32mSummary Section:\033[0m\n"; // Green for summary section header
foreach ( $this->processStatus as $status ) {
echo "$status\n";
}
}
}
}
17 changes: 11 additions & 6 deletions _tests/QITSelfTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Context {

Context::$action = $params[1] ?? 'run';

# Comma-separated list of test-types to run, eg: e2e,api
# Comma-separated list of test-types to run, eg: woo-e2e,woo-api
if ( isset( $params[2] ) ) {
Context::$test_types = array_map( 'trim', explode( ',', $params[2] ) );
} else {
Expand Down Expand Up @@ -105,7 +105,7 @@ class Context {

if ( getenv( 'QIT_SKIP_E2E' ) === 'yes' ) {
$test_types = array_filter( $test_types, function ( $test_type_path ) {
return basename( $test_type_path ) !== 'e2e';
return basename( $test_type_path ) !== 'woo-e2e';
} );
}

Expand Down Expand Up @@ -345,14 +345,15 @@ function run_test_runs( array $test_runs ) {

$normalized_t = $t;
unset( $normalized_t['path'] );
$normalized_t['type'] = str_replace( '-', '_', $normalized_t['type'] );

/*
* Here we need a unique name that is human-readable, so that we can easily identify the test in the output.
* We use the md5 of the test data to make sure it's unique.
*/
$t['test_function_name'] = sprintf(
'test_%s_%s_woo%s_php%s_wp%s_%s',
$t['type'],
$normalized_t['type'],
$t['slug'],
str_replace( '.', '', $t['woo'] ),
str_replace( '.', '', $t['php'] ),
Expand Down Expand Up @@ -473,6 +474,10 @@ function make_test_result_json_filepath( Process $process ): string {
return sprintf( '%s/%s', $process->getEnv()['QIT_TEST_PATH'], make_test_result_json_filename( $process ) );
}

function generate_test_file_name( string $test_type ) {
return ucfirst( str_replace( '-', '', $test_type ) ) . 'Test.php';
}

function handle_qit_response( Process $qit_process, string $out, array &$failed_tests ): void {
$result = json_decode( $out, true );

Expand Down Expand Up @@ -502,7 +507,7 @@ function handle_qit_response( Process $qit_process, string $out, array &$failed_
//php ./vendor/bin/phpunit tests/ActivationTest.php --filter=test_php81_activation -d --update-snapshots
$args = [
__DIR__ . '/vendor/bin/phpunit',
__DIR__ . '/tests/' . ucfirst( $qit_process->getEnv()['QIT_TEST_TYPE'] ) . 'Test.php',
__DIR__ . '/tests/' . generate_test_file_name( $qit_process->getEnv()['QIT_TEST_TYPE'] ),
/*
* Match a single test method by regex.
* Example test method: TestNamespace\TestCaseClass::testMethod
Expand Down Expand Up @@ -538,8 +543,8 @@ function handle_qit_response( Process $qit_process, string $out, array &$failed_
}

function generate_phpunit_files( string $test_type, array &$test_runs ): void {
$name = ucfirst( $test_type ) . 'Test';
$filepath = __DIR__ . '/tests/' . $name . '.php';
$name = str_replace( '.php', '', generate_test_file_name( $test_type ) );
$filepath = __DIR__ . '/tests/' . generate_test_file_name( $test_type );
$tests = '';

foreach ( $test_runs as &$test_run ) {
Expand Down
10 changes: 5 additions & 5 deletions _tests/tests/QITE2ETestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public function validate_and_normalize( string $file_path, ?callable $callback =
return $value;
}

if ( stripos( $file_path, 'e2e/delete_products' ) !== false ) {
if ( stripos( $file_path, 'woo-e2e/delete_products' ) !== false ) {
return [
[
'count' => '0',
'message' => 'Debug log is ignored for e2e/delete_products tests.',
'message' => 'Debug log is ignored for woo-e2e/delete_products tests.',
],
];
}
Expand All @@ -141,7 +141,7 @@ public function validate_and_normalize( string $file_path, ?callable $callback =

$debug_log['message'] = str_replace( 'compatibility-dashboard', 'qit-runner', $debug_log['message'] );

if ( stripos( $file_path, 'api/delete_products' ) !== false ) {
if ( stripos( $file_path, 'woo-api/delete_products' ) !== false ) {
$pos = stripos( $debug_log['message'], 'Stack Trace:' );

if ( $pos !== false ) {
Expand Down Expand Up @@ -209,8 +209,8 @@ public function validate_and_normalize( string $file_path, ?callable $callback =
}
}

// Handle E2E Delete Products tests with more wiggle room.
if ( stripos( $file_path, 'e2e/delete_products' ) !== false ) {
// Handle Woo E2E Delete Products tests with more wiggle room.
if ( stripos( $file_path, 'woo-e2e/delete_products' ) !== false ) {
if ( $debug_log['count'] <= 10 ) {
$debug_log['count'] = 'Less than 10';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "api",
"test_type": "woo-api",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "e2e",
"test_type": "woo-e2e",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down Expand Up @@ -1919,7 +1919,7 @@
"debug_log": [
{
"count": "0",
"message": "Debug log is ignored for e2e\\/delete_products tests."
"message": "Debug log is ignored for woo-e2e\\/delete_products tests."
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "e2e",
"test_type": "woo-e2e",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down Expand Up @@ -1723,7 +1723,7 @@
"debug_log": [
{
"count": "0",
"message": "Debug log is ignored for e2e\\/delete_products tests."
"message": "Debug log is ignored for woo-e2e\\/delete_products tests."
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "e2e",
"test_type": "woo-e2e",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "e2e",
"test_type": "woo-e2e",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "e2e",
"test_type": "woo-e2e",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"test_run_id": 123456,
"run_id": 123456,
"test_type": "e2e",
"test_type": "woo-e2e",
"wordpress_version": "6.0.0-normalized",
"woocommerce_version": "6.0.0-normalized",
"php_version": "7.4",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified qit
Binary file not shown.
18 changes: 18 additions & 0 deletions src/src/Commands/CreateRunCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,24 @@ public function execute( InputInterface $input, OutputInterface $output ) {

$command->add_option_to_send( 'zip' );

if ( $test_type === 'api' ) {
$command->setHidden( true );
}

// This will be hidden while custom test type is in development, but kept as an alias to "woo-e2e".
if ( $test_type === 'e2e' ) {
try {
$hide_e2e = $this->environment->get_cache()->get_manager_sync_data( 'hide_e2e' );
} catch ( \Exception $e ) {
// If it throws it's because it's not set, so we hide it.
$hide_e2e = true;
}

if ( $hide_e2e ) {
$command->setHidden( true );
}
}

$application->add( $command );
}
}

0 comments on commit 7fb1938

Please sign in to comment.