Added removePathDuplicates method

This method ensures that we can execute tests using a relative path with or without `plugins/woocommerce` and/or `tests/e2e` prepended on the test file path.
This commit is contained in:
jamelreid 2022-01-12 14:00:00 -05:00
parent 6e08e1802f
commit 059346a725
1 changed files with 22 additions and 0 deletions

View File

@ -93,6 +93,27 @@ const resolvePackagePath = ( filename, packageName = '' ) => {
return resolvedPath;
};
/**
* Removes duplicates from a file path in order to allow backwards support for executing tests commands
* that prepend `plugins/woocommerce` and/or `tests/e2e.
*
* @param {string} filePath Path to a specific test file
* @param {Array} exclude An array of strings that won't be removed in the event that duplicates exist
* @return {string}
*/
const removePathDuplicates = ( filePath, exclude = [] ) => {
const pathArray = resolveLocalE2ePath( filePath ).split( '/' );
return pathArray
.filter( ( element, index, arr ) => {
return (
arr.indexOf( element ) === index ||
exclude.indexOf( element ) !== -1
);
} )
.join( '/' );
};
// Copy local test configuration file if it exists.
const localTestConfigFile = resolveLocalE2ePath( 'config/default.json' );
const defaultConfigFile = resolvePackagePath( 'config/default/default.json' );
@ -165,4 +186,5 @@ module.exports = {
resolveLocalE2ePath,
resolvePackage,
resolvePackagePath,
removePathDuplicates,
};