Clean up e2e-environment changes from monorepo reorg (#31233)
* add flag to distinguish between the development repo and npm package * introduce local E2E file resolver function * update package changelog and readme
This commit is contained in:
parent
23f4f1c744
commit
e449511ff0
|
@ -5,6 +5,8 @@
|
||||||
- Added quotes around `WORDPRESS_TITLE` value in .env file to address issue with docker compose 2 "key cannot contain a space" error.
|
- Added quotes around `WORDPRESS_TITLE` value in .env file to address issue with docker compose 2 "key cannot contain a space" error.
|
||||||
- Added `LATEST_WP_VERSION_MINUS` that allows setting a number to subtract from the current WordPress version for the WordPress Docker image.
|
- Added `LATEST_WP_VERSION_MINUS` that allows setting a number to subtract from the current WordPress version for the WordPress Docker image.
|
||||||
- Support for PHP_VERSION, MARIADB_VERSION environment variables for built in container initialization
|
- Support for PHP_VERSION, MARIADB_VERSION environment variables for built in container initialization
|
||||||
|
- `resolveLocalE2ePath` to resolve path to local E2E file
|
||||||
|
- `WC_E2E_FOLDER` for mapping plugin root to path within repo
|
||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ const {
|
||||||
getAppRoot,
|
getAppRoot,
|
||||||
getAppName,
|
getAppName,
|
||||||
getTestConfig,
|
getTestConfig,
|
||||||
|
resolveLocalE2ePath,
|
||||||
} = require( '../utils' );
|
} = require( '../utils' );
|
||||||
|
|
||||||
const dockerArgs = [];
|
const dockerArgs = [];
|
||||||
|
@ -56,10 +57,7 @@ if ( appPath ) {
|
||||||
|
|
||||||
const appInitFile = customInitFile
|
const appInitFile = customInitFile
|
||||||
? customInitFile
|
? customInitFile
|
||||||
: path.resolve(
|
: resolveLocalE2ePath( 'docker/initialize.sh' );
|
||||||
appPath,
|
|
||||||
'plugins/woocommerce/tests/e2e/docker/initialize.sh'
|
|
||||||
);
|
|
||||||
// If found, copy it into the wp-cli Docker context so
|
// If found, copy it into the wp-cli Docker context so
|
||||||
// it gets picked up by the entrypoint script.
|
// it gets picked up by the entrypoint script.
|
||||||
if ( fs.existsSync( appInitFile ) ) {
|
if ( fs.existsSync( appInitFile ) ) {
|
||||||
|
@ -84,11 +82,6 @@ if ( ! process.env.WC_E2E_FOLDER_MAPPING ) {
|
||||||
'/var/www/html/wp-content/plugins/' + getAppBase();
|
'/var/www/html/wp-content/plugins/' + getAppBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set some environment variables
|
|
||||||
if ( ! process.env.WC_CORE_PATH ) {
|
|
||||||
envVars.WC_CORE_PATH = 'plugins/woocommerce';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! process.env.WORDPRESS_PORT ) {
|
if ( ! process.env.WORDPRESS_PORT ) {
|
||||||
process.env.WORDPRESS_PORT = testConfig.port;
|
process.env.WORDPRESS_PORT = testConfig.port;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ const { spawnSync } = require( 'child_process' );
|
||||||
const program = require( 'commander' );
|
const program = require( 'commander' );
|
||||||
const path = require( 'path' );
|
const path = require( 'path' );
|
||||||
const fs = require( 'fs' );
|
const fs = require( 'fs' );
|
||||||
const { getAppRoot } = require( '../utils' );
|
const { getAppRoot, resolveLocalE2ePath } = require( '../utils' );
|
||||||
const {
|
const {
|
||||||
WC_E2E_SCREENSHOTS,
|
WC_E2E_SCREENSHOTS,
|
||||||
JEST_PUPPETEER_CONFIG,
|
JEST_PUPPETEER_CONFIG,
|
||||||
|
@ -21,10 +21,7 @@ const appPath = getAppRoot();
|
||||||
|
|
||||||
// clear the screenshots folder before running tests.
|
// clear the screenshots folder before running tests.
|
||||||
if ( WC_E2E_SCREENSHOTS ) {
|
if ( WC_E2E_SCREENSHOTS ) {
|
||||||
const screenshotPath = path.resolve(
|
const screenshotPath = resolveLocalE2ePath( 'screenshots' );
|
||||||
appPath,
|
|
||||||
'plugins/woocommerce/tests/e2e/screenshots'
|
|
||||||
);
|
|
||||||
if ( fs.existsSync( screenshotPath ) ) {
|
if ( fs.existsSync( screenshotPath ) ) {
|
||||||
fs.readdirSync( screenshotPath ).forEach( ( file, index ) => {
|
fs.readdirSync( screenshotPath ).forEach( ( file, index ) => {
|
||||||
const filename = path.join( screenshotPath, file );
|
const filename = path.join( screenshotPath, file );
|
||||||
|
@ -36,9 +33,7 @@ if ( WC_E2E_SCREENSHOTS ) {
|
||||||
const nodeConfigDirs = [ path.resolve( __dirname, '../config' ) ];
|
const nodeConfigDirs = [ path.resolve( __dirname, '../config' ) ];
|
||||||
|
|
||||||
if ( appPath ) {
|
if ( appPath ) {
|
||||||
nodeConfigDirs.unshift(
|
nodeConfigDirs.unshift( resolveLocalE2ePath( 'config' ) );
|
||||||
path.resolve( appPath, 'plugins/woocommerce/tests/e2e/config' )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const testEnvVars = {
|
const testEnvVars = {
|
||||||
|
@ -55,10 +50,7 @@ if ( DEFAULT_TIMEOUT_OVERRIDE ) {
|
||||||
if ( ! JEST_PUPPETEER_CONFIG ) {
|
if ( ! JEST_PUPPETEER_CONFIG ) {
|
||||||
// Use local Puppeteer config if there is one.
|
// Use local Puppeteer config if there is one.
|
||||||
// Load test configuration file into an object.
|
// Load test configuration file into an object.
|
||||||
const localJestConfigFile = path.resolve(
|
const localJestConfigFile = resolveLocalE2ePath( 'config/jest-puppeteer.config.js' );
|
||||||
appPath,
|
|
||||||
'tests/e2e/config/jest-puppeteer.config.js'
|
|
||||||
);
|
|
||||||
const jestConfigFile = path.resolve(
|
const jestConfigFile = path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
'../config/jest-puppeteer.config.js'
|
'../config/jest-puppeteer.config.js'
|
||||||
|
@ -100,10 +92,7 @@ let configPath = path.resolve( __dirname, '../config/jest.config.js' );
|
||||||
|
|
||||||
// Look for a Jest config in the dependent app's path.
|
// Look for a Jest config in the dependent app's path.
|
||||||
if ( appPath ) {
|
if ( appPath ) {
|
||||||
const appConfig = path.resolve(
|
const appConfig = resolveLocalE2ePath( 'config/jest.config.js' );
|
||||||
appPath,
|
|
||||||
'plugins/woocommerce/tests/e2e/config/jest.config.js'
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( fs.existsSync( appConfig ) ) {
|
if ( fs.existsSync( appConfig ) ) {
|
||||||
configPath = appConfig;
|
configPath = appConfig;
|
||||||
|
|
|
@ -33,6 +33,18 @@ SCRIPTPATH=$(dirname "$0")
|
||||||
REALPATH=$(readlink "$0")
|
REALPATH=$(readlink "$0")
|
||||||
cd "$SCRIPTPATH/$(dirname "$REALPATH")/.."
|
cd "$SCRIPTPATH/$(dirname "$REALPATH")/.."
|
||||||
|
|
||||||
|
# Set a flag to distinguish between the development repo and npm package
|
||||||
|
DEV_PATH=$(echo $0 | rev | cut -f4 -d/ | rev)
|
||||||
|
if [ "$DEV_PATH" != "node_modules" ]; then
|
||||||
|
export WC_E2E_WOOCOMMERCE_DEV='true'
|
||||||
|
export WC_E2E_FOLDER='plugins/woocommerce'
|
||||||
|
else
|
||||||
|
export WC_E2E_WOOCOMMERCE_DEV=''
|
||||||
|
if [ -z $WC_E2E_FOLDER ]; then
|
||||||
|
export WC_E2E_FOLDER=''
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Run scripts
|
# Run scripts
|
||||||
case $1 in
|
case $1 in
|
||||||
'docker:up')
|
'docker:up')
|
||||||
|
|
|
@ -119,7 +119,12 @@ You can override these in `/tests/e2e/config/default.json`.
|
||||||
|
|
||||||
### Folder Mapping
|
### Folder Mapping
|
||||||
|
|
||||||
The built in container defaults to mapping the root folder of the repository to a folder in the `plugins` folder. For example `woocommerce` is mapped to `/var/www/html/wp-content/plugins/woocommerce`. Use the `WC_E2E_FOLDER_MAPPING` environment variable to override this mapping.
|
The built in container defaults to mapping the root folder of the repository to a folder in the `plugins` folder. Use the environment variables `WC_E2E_FOLDER` and `WC_E2E_FOLDER_MAPPING` to override this mapping. The `WC_E2E_FOLDER` is a path relative to the root of the project. For example, in the `woocommerce` repository this mapping is:
|
||||||
|
|
||||||
|
- `WC_E2E_FOLDER=plugins/woocommerce`
|
||||||
|
- `WC_E2E_FOLDER_MAPPING=/var/www/html/wp-content/plugins/woocommerce`
|
||||||
|
|
||||||
|
Other repository examples:
|
||||||
|
|
||||||
- Storefront Theme - ```WC_E2E_FOLDER_MAPPING=/var/www/html/wp-content/themes/storefront npx wc-e2e docker:up```
|
- Storefront Theme - ```WC_E2E_FOLDER_MAPPING=/var/www/html/wp-content/themes/storefront npx wc-e2e docker:up```
|
||||||
- Site Project - ```WC_E2E_FOLDER_MAPPING=/var/www/html/wp-content npx wc-e2e docker:up```
|
- Site Project - ```WC_E2E_FOLDER_MAPPING=/var/www/html/wp-content npx wc-e2e docker:up```
|
||||||
|
|
|
@ -9,7 +9,7 @@ const fs = require( 'fs' );
|
||||||
/**
|
/**
|
||||||
* Internal Dependencies
|
* Internal Dependencies
|
||||||
*/
|
*/
|
||||||
const { getAppRoot } = require( '../utils' );
|
const { resolveLocalE2ePath } = require( '../utils' );
|
||||||
|
|
||||||
const failureSetup = [];
|
const failureSetup = [];
|
||||||
if ( WC_E2E_SCREENSHOTS ) {
|
if ( WC_E2E_SCREENSHOTS ) {
|
||||||
|
@ -23,11 +23,10 @@ const setupFilesAfterEnv = [
|
||||||
'expect-puppeteer',
|
'expect-puppeteer',
|
||||||
];
|
];
|
||||||
|
|
||||||
const appPath = getAppRoot();
|
const localJestSetupFile = resolveLocalE2ePath( 'config/jest.setup.js' );
|
||||||
const localJestSetupFile = path.resolve(
|
const moduleNameMap = resolveLocalE2ePath( '$1' );
|
||||||
appPath,
|
const testSpecs = resolveLocalE2ePath( 'specs' );
|
||||||
'plugins/woocommerce/tests/e2e/config/jest.setup.js'
|
|
||||||
);
|
|
||||||
if ( fs.existsSync( localJestSetupFile ) ) {
|
if ( fs.existsSync( localJestSetupFile ) ) {
|
||||||
setupFilesAfterEnv.push( localJestSetupFile );
|
setupFilesAfterEnv.push( localJestSetupFile );
|
||||||
}
|
}
|
||||||
|
@ -35,7 +34,7 @@ if ( fs.existsSync( localJestSetupFile ) ) {
|
||||||
const combinedConfig = {
|
const combinedConfig = {
|
||||||
...jestConfig,
|
...jestConfig,
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'@woocommerce/e2e/tests/(.*)': appPath + 'tests/e2e/$1',
|
'@woocommerce/e2e/tests/(.*)': moduleNameMap,
|
||||||
},
|
},
|
||||||
|
|
||||||
setupFiles: [ '<rootDir>/config/env.setup.js' ],
|
setupFiles: [ '<rootDir>/config/env.setup.js' ],
|
||||||
|
@ -52,7 +51,7 @@ const combinedConfig = {
|
||||||
...jestConfig.transformIgnorePatterns,
|
...jestConfig.transformIgnorePatterns,
|
||||||
'node_modules/(?!(woocommerce)/)',
|
'node_modules/(?!(woocommerce)/)',
|
||||||
],
|
],
|
||||||
roots: [ appPath + 'tests/e2e/specs' ],
|
roots: [ testSpecs ],
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( process.env.jest_test_spec ) {
|
if ( process.env.jest_test_spec ) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ services:
|
||||||
WORDPRESS_DEBUG: 1
|
WORDPRESS_DEBUG: 1
|
||||||
volumes:
|
volumes:
|
||||||
- wordpress:/var/www/html
|
- wordpress:/var/www/html
|
||||||
- "../../../${WC_CORE_PATH}:${WC_E2E_FOLDER_MAPPING}"
|
- "../../../${WC_E2E_FOLDER}:${WC_E2E_FOLDER_MAPPING}"
|
||||||
|
|
||||||
wordpress-cli:
|
wordpress-cli:
|
||||||
container_name: "${APP_NAME}_wordpress-cli"
|
container_name: "${APP_NAME}_wordpress-cli"
|
||||||
|
@ -60,7 +60,7 @@ services:
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- wordpress:/var/www/html
|
- wordpress:/var/www/html
|
||||||
- "../../../plugins/woocommerce:${WC_E2E_FOLDER_MAPPING}"
|
- "../../../${WC_E2E_FOLDER}:${WC_E2E_FOLDER_MAPPING}"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db:
|
db:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const getAppRoot = require( './app-root' );
|
const getAppRoot = require( './app-root' );
|
||||||
const { getAppName, getAppBase } = require( './app-name' );
|
const { getAppName, getAppBase } = require( './app-name' );
|
||||||
const { getTestConfig, getAdminConfig } = require( './test-config' );
|
const { getTestConfig, getAdminConfig, resolveLocalE2ePath } = require( './test-config' );
|
||||||
const { getRemotePluginZip, getLatestReleaseZipUrl } = require('./get-plugin-zip');
|
const { getRemotePluginZip, getLatestReleaseZipUrl } = require('./get-plugin-zip');
|
||||||
const takeScreenshotFor = require( './take-screenshot' );
|
const takeScreenshotFor = require( './take-screenshot' );
|
||||||
const updateReadyPageStatus = require('./update-ready-page');
|
const updateReadyPageStatus = require('./update-ready-page');
|
||||||
|
@ -12,6 +12,7 @@ module.exports = {
|
||||||
getAppName,
|
getAppName,
|
||||||
getTestConfig,
|
getTestConfig,
|
||||||
getAdminConfig,
|
getAdminConfig,
|
||||||
|
resolveLocalE2ePath,
|
||||||
getRemotePluginZip,
|
getRemotePluginZip,
|
||||||
getLatestReleaseZipUrl,
|
getLatestReleaseZipUrl,
|
||||||
takeScreenshotFor,
|
takeScreenshotFor,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const path = require( 'path' );
|
const path = require( 'path' );
|
||||||
const mkdirp = require( 'mkdirp' );
|
const mkdirp = require( 'mkdirp' );
|
||||||
const getAppRoot = require( './app-root' );
|
const { resolveLocalE2ePath } = require( './test-config' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take a screenshot if browser context exists.
|
* Take a screenshot if browser context exists.
|
||||||
|
@ -10,11 +10,7 @@ const getAppRoot = require( './app-root' );
|
||||||
*/
|
*/
|
||||||
const takeScreenshotFor = async ( message ) => {
|
const takeScreenshotFor = async ( message ) => {
|
||||||
const title = message.replace( /\.$/, '' );
|
const title = message.replace( /\.$/, '' );
|
||||||
const appPath = getAppRoot();
|
const savePath = resolveLocalE2ePath( 'screenshots' );
|
||||||
const savePath = path.resolve(
|
|
||||||
appPath,
|
|
||||||
'plugins/woocommerce/tests/e2e/screenshots'
|
|
||||||
);
|
|
||||||
const filePath = path.join(
|
const filePath = path.join(
|
||||||
savePath,
|
savePath,
|
||||||
`${ title }.png`.replace( /[^a-z0-9.-]+/gi, '-' )
|
`${ title }.png`.replace( /[^a-z0-9.-]+/gi, '-' )
|
||||||
|
|
|
@ -2,12 +2,27 @@ const path = require( 'path' );
|
||||||
const fs = require( 'fs' );
|
const fs = require( 'fs' );
|
||||||
const getAppRoot = require( './app-root' );
|
const getAppRoot = require( './app-root' );
|
||||||
|
|
||||||
// Copy local test configuration file if it exists.
|
|
||||||
const appPath = getAppRoot();
|
const appPath = getAppRoot();
|
||||||
const localTestConfigFile = path.resolve(
|
|
||||||
appPath,
|
/**
|
||||||
'plugins/woocommerce/tests/e2e/config/default.json'
|
* Resolve a local E2E file.
|
||||||
);
|
*
|
||||||
|
* @param {string} filename Filename to append to the path.
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
const resolveLocalE2ePath = ( filename = '' ) => {
|
||||||
|
const { WC_E2E_FOLDER } = process.env;
|
||||||
|
const localPath = `${WC_E2E_FOLDER}/tests/e2e/${filename}`;
|
||||||
|
const resolvedPath = path.resolve(
|
||||||
|
appPath,
|
||||||
|
localPath.indexOf( '/' ) == 0 ? localPath.slice( 1 ) : localPath
|
||||||
|
);
|
||||||
|
|
||||||
|
return resolvedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy local test configuration file if it exists.
|
||||||
|
const localTestConfigFile = resolveLocalE2ePath( 'config/default.json' );
|
||||||
const defaultConfigFile = path.resolve(
|
const defaultConfigFile = path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
'../config/default/default.json'
|
'../config/default/default.json'
|
||||||
|
@ -78,4 +93,5 @@ const getAdminConfig = () => {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getTestConfig,
|
getTestConfig,
|
||||||
getAdminConfig,
|
getAdminConfig,
|
||||||
|
resolveLocalE2ePath,
|
||||||
};
|
};
|
||||||
|
|
|
@ -6007,7 +6007,7 @@ packages:
|
||||||
/@wordpress/deprecated/2.12.3:
|
/@wordpress/deprecated/2.12.3:
|
||||||
resolution: {integrity: sha512-qr+yDfTQfI3M4h6oY6IeHWwoHr4jxbILjSlV+Ht6Jjto9Owap6OuzSqR13Ev4xqIoG4C7b5B3gZXVfwVDae1zg==}
|
resolution: {integrity: sha512-qr+yDfTQfI3M4h6oY6IeHWwoHr4jxbILjSlV+Ht6Jjto9Owap6OuzSqR13Ev4xqIoG4C7b5B3gZXVfwVDae1zg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.15.4
|
'@babel/runtime': 7.16.3
|
||||||
'@wordpress/hooks': 2.12.3
|
'@wordpress/hooks': 2.12.3
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue