-
Notifications
You must be signed in to change notification settings - Fork 138
Add error for incorrect test command usage #1314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add error for incorrect test command usage #1314
Conversation
|
Please add relevant [Type] label and milestone to this PR. |
92fb6ac to
87d8d96
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
I suggest we handle the exit code from PHPUnit to detect if it exits due to the absence of the WP tests setup. This way, we can wrap the test command in a bash or PHP script, avoiding the need to check global variables that might be initialized at multiple points during the WP test suite lifecycle. |
Makes sense but I just have one doubt. Currently this is the error we are getting on running the composer test commands directly: ➜ composer test:plugins
> phpunit '--verbose' '--testsuite' 'auto-sizes'
Error: The following required constants are not defined: WP_TESTS_DOMAIN, WP_TESTS_EMAIL, WP_TESTS_TITLE, WP_PHP_BINARY.
Please check out `wp-tests-config-sample.php` for an example.
Script phpunit handling the test event returned with error code 1
Script @test --verbose --testsuite auto-sizes was called via test:auto-sizes
Script @test:auto-sizes was called via test:pluginsThis error |
|
Humm yes, this is what I was concerned about. A better exit code between 0 to 255 can be used apart from the reserved ones to communicate the error type. But I am not sure if it can be added to the core tests bootstrap file. Also, I think adding an exit with the proper message above this line should work in most of cases. performance/tests/bootstrap.php Line 35 in d300b2c
It can check if |
|
@westonruter Any thoughts on if we can propose to add a meaningful error code if the test process is exiting prematurely in case dependencies not met? |
|
I guess any error code other than what |
The putenv( sprintf( 'WP_PHPUNIT__DIR=%s', dirname( __FILE__ ) ) );elseif ( false !== getenv( 'WP_PHPUNIT__DIR' ) ) {
$_test_root = getenv( 'WP_PHPUNIT__DIR' );
}So, I don't think we can use that to determine if we should show error. Also, the original issue was that if the user runs Please feel free correct me if I have misunderstood something here. |
Well, that's another case, I am not aware of. Also, I am not sure if we use
That doesn't mean we can't add a bash script to run the tests inside this command... right? But it's not doable right now because of the existing return code. |
|
The issue with modifying the bootstrap file is that it can be loaded by PHPUnit in various environments, whereas this change only considers Without this change, my tests run as expected in the Lando environment. The correct behavior should be: We need to detect when tests are failing due to a missing WP test suite setup and suggest using wp-env to run their tests. |
We can still achieve this. If echo 'Error: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.' . PHP_EOL;
echo 'Info: Alternatively, you can run `npm run wp-env start && npm run test-php` to execute tests in the wp-env environment.' . PHP_EOL;
exit(1);In the rest of the cases, WP tests bootstrap will handle on its own: It will only jump to other cases if the user is using |
|
Given what @westonruter noted in #1314 (comment), I doubt if these lines are relevant anymore: performance/tests/bootstrap.php Lines 29 to 33 in 49beab8
because |
Summary
Fixes #1256
This PR addresses an issue where running Composer test commands directly shows error related to missing constants but doesn't show that the user should run the npm command to run tests.
Relevant technical choices
Added missing environment variables check and file exists check for php unit test
functions.phpin the testbootstrap.php.Now, running
composer test:pluginscommand directly: