2020-07-24 13:12:07 +00:00
|
|
|
const path = require( 'path' );
|
|
|
|
const fs = require( 'fs' );
|
2020-10-21 17:25:13 +00:00
|
|
|
const getAppRoot = require( './app-root' );
|
2020-07-29 21:57:59 +00:00
|
|
|
|
|
|
|
// Copy local test configuration file if it exists.
|
|
|
|
const appPath = getAppRoot();
|
|
|
|
const localTestConfigFile = path.resolve( appPath, 'tests/e2e/config/default.json' );
|
|
|
|
const testConfigFile = path.resolve( __dirname, '../config/default.json' );
|
|
|
|
if ( fs.existsSync( localTestConfigFile ) ) {
|
|
|
|
fs.copyFileSync(
|
|
|
|
localTestConfigFile,
|
|
|
|
testConfigFile
|
|
|
|
);
|
|
|
|
}
|
2020-07-24 13:12:07 +00:00
|
|
|
|
|
|
|
const getTestConfig = () => {
|
|
|
|
const rawTestConfig = fs.readFileSync( testConfigFile );
|
|
|
|
|
2020-09-23 19:22:15 +00:00
|
|
|
let testConfig = JSON.parse( rawTestConfig );
|
|
|
|
let testPort = testConfig.url.match( /[0-9]+/ );
|
|
|
|
testConfig.baseUrl = testConfig.url.substr( 0, testConfig.url.length - 1 );
|
2020-08-21 16:25:30 +00:00
|
|
|
if ( Array.isArray( testPort ) ) {
|
2020-08-19 12:57:14 +00:00
|
|
|
testConfig.port = testPort[0] ? testPort[0] : '8084';
|
|
|
|
} else {
|
|
|
|
testConfig.port = '';
|
|
|
|
}
|
2020-07-24 13:12:07 +00:00
|
|
|
return testConfig;
|
|
|
|
};
|
|
|
|
|
2021-01-19 15:02:08 +00:00
|
|
|
/**
|
|
|
|
* Get user account settings for Docker configuration.
|
|
|
|
*/
|
|
|
|
const getAdminConfig = () => {
|
|
|
|
const testConfig = getTestConfig();
|
|
|
|
const adminConfig = {
|
|
|
|
'WORDPRESS_LOGIN': testConfig.users.admin.username ? testConfig.users.admin.username : 'admin',
|
|
|
|
'WORDPRESS_PASSWORD': testConfig.users.admin.password ? testConfig.users.admin.password : 'password',
|
|
|
|
'WORDPRESS_EMAIL': testConfig.users.admin.email ? testConfig.users.admin.email : 'admin@woocommercecoree2etestsuite.com',
|
|
|
|
};
|
|
|
|
|
|
|
|
return adminConfig;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getTestConfig,
|
|
|
|
getAdminConfig,
|
|
|
|
};
|