add port configuration support

This commit is contained in:
Ron Rennick 2020-07-24 10:12:07 -03:00
parent 4cffb9b95c
commit eaafc88d33
8 changed files with 50 additions and 5 deletions

1
.gitignore vendored
View File

@ -45,6 +45,7 @@ tests/cli/vendor
/tests/bin/tmp
/tests/e2e/config/local-*.json
/tests/e2e/config/local.json
/tests/e2e/config/default.json
/tests/e2e/docker
/tests/e2e/env/docker/wp-cli/initialize.sh
/tests/e2e/env/build/

1
tests/e2e/env/.env vendored
View File

@ -7,7 +7,6 @@ WORDPRESS_TABLE_PREFIX=wp_
WORDPRESS_DEBUG=1
# WordPress CLI environment
WORDPRESS_PORT=8084
WORDPRESS_HOST=wordpress-www:80
WORDPRESS_TITLE=WooCommerce Core E2E Test Suite
WORDPRESS_LOGIN=admin

View File

@ -5,6 +5,7 @@ const program = require( 'commander' );
const path = require( 'path' );
const fs = require( 'fs' );
const getAppPath = require( '../utils/app-root' );
const getTestConfig = require( '../utils/test-config' );
const dockerArgs = [];
let command = '';
@ -48,9 +49,28 @@ if ( appPath ) {
envVars.APP_NAME = path.basename( appPath );
}
// Load test configuration file into an object.
const localTestConfigFile = path.resolve( appPath, 'tests/e2e/config/default.json' );
const testConfigFile = path.resolve( __dirname, '../config/default.json' );
// Copy local test configuration file if it exists.
if ( fs.existsSync( localTestConfigFile ) ) {
fs.copyFileSync(
localTestConfigFile,
testConfigFile
);
}
const testConfig = getTestConfig();
// Set some environment variables
if ( ! process.env.WC_E2E_FOLDER_MAPPING ) {
envVars.WC_E2E_FOLDER_MAPPING = '/var/www/html/wp-content/plugins/' + envVars.APP_NAME;
}
if ( ! global.process.env.WORDPRESS_PORT ) {
global.process.env.WORDPRESS_PORT = testConfig.port;
}
if ( ! global.process.env.WORDPRESS_URL ) {
global.process.env.WORDPRESS_URL = testConfig.url;
}
// Ensure that the first Docker compose file loaded is from our local env.
dockerArgs.unshift( '-f', path.resolve( __dirname, '../docker-compose.yaml' ) );

View File

@ -8,8 +8,9 @@ DELAY_SEC=10
# Counter for the loop that checks if the Docker container had been built
count=0
while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8084/?pagename=ready)" != "200" ]]
WP_BASE_URL=$(node utils/get-base-url.js)
echo "Testing URL: $WP_BASE_URL"
while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' ${WP_BASE_URL}/?pagename=ready)" != "200" ]]
do
echo "$(date) - Docker container is still being built"

View File

@ -1,5 +1,8 @@
const getTestConfig = require( '../utils/test-config' );
const testConfig = getTestConfig();
global.process.env = {
...global.process.env,
// Gutenberg test util functions expect the test url to be at :8889, we change it to 8084.
WP_BASE_URL: 'http://localhost:8084',
// Remove the trailing slash from jest sequencer WORDPRESS_URL.
WP_BASE_URL: testConfig.baseUrl,
};

4
tests/e2e/env/utils/get-base-url.js vendored Normal file
View File

@ -0,0 +1,4 @@
const getTestConfig = require( './test-config' );
const testConfig = getTestConfig();
console.log(testConfig.baseUrl);

View File

@ -1,5 +1,7 @@
const getAppRoot = require( './app-root' );
const getTestConfig = require( './test-config' );
module.exports = {
getAppRoot,
getTestConfig,
};

15
tests/e2e/env/utils/test-config.js vendored Normal file
View File

@ -0,0 +1,15 @@
const path = require( 'path' );
const fs = require( 'fs' );
const getTestConfig = () => {
const testConfigFile = path.resolve( __dirname, '../config/default.json' );
const rawTestConfig = fs.readFileSync( testConfigFile );
let testConfig = JSON.parse(rawTestConfig);
testConfig.baseUrl = testConfig.url.substr(0, testConfig.url.length - 1);
let testPort = testConfig.url.match(/[0-9]+/);
testConfig.port = testPort[0] ? testPort[0] : '8084';
return testConfig;
};
module.exports = getTestConfig;