-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Env: Run tests using the same version used for development. #18703
Env: Run tests using the same version used for development. #18703
Conversation
@@ -33,6 +33,7 @@ | |||
}, | |||
"dependencies": { | |||
"chalk": "^2.4.2", | |||
"copy-dir": "^1.2.0", |
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.
We could potentially avoid pulling in a new dependency by reusing fs-extra
(already a devDependencies
in the root package.json
), which is also promises-based (avoids need to promisify).
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 started that way, but opted to optimize for a leaner @wordpress/env
. fs-extra
is 10x bigger.
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 started that way, but opted to optimize for a leaner
@wordpress/env
.fs-extra
is 10x bigger.
That's fair. It's not as optimal for our project to have multiple dependencies capable of achieving the same goal, but good to be thinking about the consumer here. Might be a good reason to look to whether we should try to replace or remove our existing usage of fs-extra
, which I know to be quite limited.
In fact, I think the only thing we really "need" it for is this directory removal:
Lines 246 to 247 in 598211e
await fs.remove( gitWorkingDirectoryPath ); | |
await fs.remove( svnWorkingDirectoryPath ); |
Historically I might have used rimraf
for this.
Apparently recursive
is available as an experimental option now in the latest Node LTS, so we could consider that option as well: https://nodejs.org/dist/latest-v12.x/docs/api/fs.html#fs_fs_rmdir_path_options_callback
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.
Historically I might have used rimraf for this.
And we already have rimraf
. I'll make a note to replace it.
Apparently recursive is available as an experimental option now in the latest Node LTS, so we could consider that option as well
When it becomes stable right?
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.
Apparently recursive is available as an experimental option now in the latest Node LTS, so we could consider that option as well
When it becomes stable right?
Ehh, it doesn't bother me much. Well.. assuming that it's experimental in the sense of "The API signature may change in the future" and not "Your entire filesystem might be destroyed".
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.
Stability: 1 - Experimental. The feature is not subject to Semantic Versioning rules. Non-backward compatible changes or removal may occur in any future release. Use of the feature is not recommended in production environments.
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.
* Promisified dependencies | ||
*/ | ||
const copyDir = util.promisify( require( 'copy-dir' ) ); | ||
const wait = util.promisify( setTimeout ); |
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.
TIL setTimeout[ require( 'util' ).promisify.custom ]
is a thing.
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.
Yeah, I think it used to be that you had to use setTimeout[ require( 'util' ).promisify.custom ]
directly.
const commonVolumes = ` | ||
${ dependencyMappings } | ||
- ${ cwd }${ cwdTestsPath }/e2e-tests/mu-plugins/:/var/www/html/wp-content/mu-plugins/ | ||
- ${ cwd }${ cwdTestsPath }/e2e-tests/plugins/:/var/www/html/wp-content/plugins/${ cwdName }-test-plugins/`; | ||
const volumes = ` | ||
- ${ cwd }/../${ cwdName }-wordpress/:/var/www/html/${ commonVolumes }`; | ||
const testsVolumes = ` | ||
- tests-wordpress:/var/www/html/${ commonVolumes }`; | ||
- ${ cwd }/../${ cwdName }-tests-wordpress/:/var/www/html/${ commonVolumes }`; |
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 know it exists already for gutenberg-wordpress
, but this directory creation one level up from the project root was very unexpected for me the first time I encountered it. Was there a reason to not include it as a directory within the project, like already exists with wordpress
? For one thing, it makes future clean-up easier, since it's kept self-contained.
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.
It would make the plugin volume recursive and sometimes Docker tripped up on that for some reason.
@@ -97,6 +103,31 @@ module.exports = { | |||
// Some commit refs need to be set as detached. | |||
await repo.setHeadDetached( ref ); | |||
} | |||
|
|||
// Duplicate repo for the tests container. | |||
let stashed = true; // Stash to avoid copying config changes. |
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 wonder if, rather than this stash + filesystem copy, we could just create a clone from the repoPath
.
In some brief testing in the Terminal, when I'm in gutenberg-wordpress
, then run:
git clone . ../gutenberg-tests-wordpress/
... it creates a checkout of WordPress, at the same commit as in gutenberg-wordpress
, excluding modifications in the working directory. Isn't this the same as what you're trying to achieve with the logic here?
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 don't think it copies over things like a detached head ref from await repo.setHeadDetached( ref );
.
411e3e8
to
e8a2b5e
Compare
Description
@wordpress/env
'swp-env start
command takes a[ref]
positional argument, which defaults tomaster
, to specify a version of https:/WordPress/WordPress to run. This was being respected for the development environment, but not for the tests environment, which resulted in E2E tests being ran on the default version shipped with the WordPress Docker container, i.e. notmaster
with TwentyTwenty which our tests expect.This PR addresses the issue by mounting an isolated copy of the checked out WordPress used for development, in the tests container, so that it can use the same version.
How has this been tested?
It was verified that after running
wp-env start
, both the development and tests containers are now running the same version of WordPress and all E2E tests pass as expected.Types of Changes
Bug Fix:
@wordpress/env
now respects the specified WordPress version for both development and tests environments.Checklist: