-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 WP_ENV_TESTS_MYSQL_PORT
/ .wp-env.json
.env.tests.mysqlPort
option etc
#61057
Add WP_ENV_TESTS_MYSQL_PORT
/ .wp-env.json
.env.tests.mysqlPort
option etc
#61057
Conversation
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @shashwatahalder01. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @BrianHenryIE! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a reasonable addition to wp-env
, thanks!
I've left some comments 😄
@@ -85,6 +87,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = { | |||
themes: [], | |||
port: 8888, | |||
testsPort: 8889, | |||
testsMysqlPort: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I view the top-level port
and testsPort
properties are more of a legacy thing. It's more intuitive to set configuration like this only at the environment level. How would you feel about dropping the root testsMysqlPort
in favor of just having development.mysqlPort
and tests.mysqlPort
?
@@ -167,6 +167,7 @@ module.exports = function buildDockerComposeConfig( config ) { | |||
// Set the default ports based on the config values. | |||
const developmentPorts = `\${WP_ENV_PORT:-${ config.env.development.port }}:80`; | |||
const testsPorts = `\${WP_ENV_TESTS_PORT:-${ config.env.tests.port }}:80`; | |||
const testsMysqlPorts = `\${WP_ENV_TESTS_MYSQL_PORT:-${ config.env.tests.mysqlPort ?? '' }}:3306`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to support customizing the port like this let's go ahead and also support the development environment's MySQL port too.
To test, checkout this PR and create a project with its {
"name": "gutenberg-61057-test",
"devDependencies": {
"@wordpress/env": "file:/path/to/checked/out/gutenberg/packages/env"
}
} npm install;
npx wp-env start; Observe default behaviour with randomly assigned MySQL ports:
Add {
"env": {
"development": {
"mysqlPort": 13306
},
"tests": {
"mysqlPort": 13307
}
}
} npx wp-env start; Observe specified ports used:
Test Bash env variables: WP_ENV_MYSQL_PORT=13304 npx wp-env start
WP_ENV_TESTS_MYSQL_PORT=13305 npx wp-env start
|
WP_ENV_TESTS_MYSQL_PORT
/ .wp-env.json
testsMysqlPort
optionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems sensible to me. Thanks for adding tests! @ObliviousHarmony has this been updated to your liking?
Actually on second look I mistook these changes as new tests. It would be great to add a few if you could. |
It seems like all of the feedback has been reasonably addressed. Since this is only being blocked by the review points to be confirmed as addressed, I'm going to merge this to give it a try. |
… option etc (WordPress#61057) * Add `WP_ENV_TESTS_MYSQL_PORT` * Remove base `testsMysqlPort` in favour of `.env.x.mysqlPort` * Remove old root config code * Update config-integration.js.snap * Add `mysqlPort` to `DEFAULT_CONFIG` * Update README.md * Add test expectations for mysqlPort changes Unlinked contributors: shashwatahalder01. Co-authored-by: BrianHenryIE <brianhenryie@git.wordpress.org> Co-authored-by: ObliviousHarmony <obliviousharmony@git.wordpress.org> Co-authored-by: desrosj <desrosj@git.wordpress.org> Co-authored-by: alanef <fullworks@git.wordpress.org>
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
Fix: #50677
What?
Currently, the tests container's database port is assigned randomly each time wp-env is started. This PR adds the ability to set the MySQL port number in the
.wp-env.json
file or via aWP_ENV_TESTS_MYSQL_PORT
environmental variable.Why?
I'd like to be able to use the database in unit tests.
How?
By adding a config option to keep the port number static.
Testing Instructions
Set
testsMysqlPort
in.wp-env.json
Screenshots or screencast
Note
I tried to also add it as a setting
env.tests.mysqlPort
but I got a parsing error:✖ Invalid /Users/brian.henry/Sites/wpcs-autoload/.wp-env.json: "tests.mysqlPort" is not a configuration option.