Skip to content

Commit

Permalink
Env: Bind "core" files to tests environment (#21195)
Browse files Browse the repository at this point in the history
* Env: Bind "core" files to tests environment

When using a local source for "core" we want to ensure two things:

1. That changes the user makes within the "core" directory are served in
   both the development and tests environments.
2. That the development and tests environment use separate databases and
   `wp-content/uploads`.

Only (2) was working because the tests environment served everything
from a totally separate copy of WordPress.

The fix is to bind every file except wp-config.php and wp-content from
the local "core" directory to the tests environment.

* Env: Only bind core files to tests environment when using local source
  • Loading branch information
noisysocks authored Mar 30, 2020
1 parent 6e3b72a commit 4fba3b0
Showing 1 changed file with 50 additions and 7 deletions.
57 changes: 50 additions & 7 deletions packages/env/lib/build-docker-compose-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,56 @@ module.exports = function buildDockerComposeConfig( config ) {
...themeMounts,
];

const testsMounts = [
`${
config.coreSource ? config.coreSource.testsPath : 'tests-wordpress'
}:/var/www/html`,
...pluginMounts,
...themeMounts,
];
let testsMounts;
if ( config.coreSource ) {
testsMounts = [
`${ config.coreSource.testsPath }:/var/www/html`,

// When using a local source for "core" we want to ensure two things:
//
// 1. That changes the user makes within the "core" directory are
// served in both the development and tests environments.
// 2. That the development and tests environment use separate
// databases and `wp-content/uploads`.
//
// To do this we copy the local "core" files ($wordpress) to a tests
// directory ($tests-wordpress) and instruct the tests environment
// to source its files like so:
//
// - wp-config.php <- $tests-wordpress/wp-config.php
// - wp-config-sample.php <- $tests-wordpress/wp-config.php
// - wp-content <- $tests-wordpress/wp-content
// - * <- $wordpress/*
//
// https://github.com/WordPress/gutenberg/issues/21164
...( config.coreSource.type === 'local'
? fs
.readdirSync( config.coreSource.path )
.filter(
( filename ) =>
filename !== 'wp-config.php' &&
filename !== 'wp-config-sample.php' &&
filename !== 'wp-content'
)
.map(
( filename ) =>
`${ path.join(
config.coreSource.path,
filename
) }:/var/www/html/${ filename }`
)
: [] ),

...pluginMounts,
...themeMounts,
];
} else {
testsMounts = [
'tests-wordpress:/var/www/html',
...pluginMounts,
...themeMounts,
];
}

// Set the default ports based on the config values.
const developmentPorts = `\${WP_ENV_PORT:-${ config.port }}:80`;
Expand Down

0 comments on commit 4fba3b0

Please sign in to comment.