Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing plugin dir + using multiple plugins + mocking API calls #29

Open
BrianHenryIE opened this issue Nov 28, 2021 · 6 comments
Open
Labels
documentation Improvements or additions to documentation

Comments

@BrianHenryIE
Copy link

I'm looking for the best way to symlink multiple plugins from my project folder into the test environment.

docker-compose.yaml symlinks the plugin being tested with:

    volumes:
      - wordpress:/var/www/html
      - "../../../:${WC_E2E_FOLDER_MAPPING}"

In my project dir, I keep my plugin in a subdir (src) rather than the project root.

Additionally, I generally am writing a plugin around existing paid plugins that I need active. So I need to to symlink that plugin.

Then I want to mock the API data I need in tests, which I'm doing in PHP with WP_HTTP::request()'s pre_http_request filter. Again, this plugin needs to be symlinked.

I'm successfully doing this with a package.json postinstall script:

"postinstall": "find ./node_modules/@woocommerce/e2e-environment/docker-compose.yaml -exec sed -i '' 's|../../../:${WC_E2E_FOLDER_MAPPING}|'$(pwd)'/src/:\\${WC_E2E_FOLDER_MAPPING}\"\\\n      - \"'$(pwd)'/wp-content/plugins/woocommerce-shipment-tracking:\\${WC_E2E_FOLDER_MAPPING}/../woocommerce-shipment-tracking\"\\\n      - \"'$(pwd)'/tests/e2e/mocking-plugin/:\\${WC_E2E_FOLDER_MAPPING}/../mocking-plugin|g' {} +"  },

Is there a better way?

@rrennick
Copy link
Contributor

In my project dir, I keep my plugin in a subdir (src) rather than the project root.

The next release of e2e-environment will have WC_E2E_FOLDER which you would set to src. In the interim you could create a package.json with all of your E2E packages in the src folder and run all your E2E in that folder.

I'm going to leave this issue open for a reminder that we will need to update the instructions here when we release the e2e-environment package.

@rrennick rrennick added the documentation Improvements or additions to documentation label Nov 30, 2021
@rrennick
Copy link
Contributor

Additionally, I generally am writing a plugin around existing paid plugins that I need active. So I need to to symlink that plugin.

@BrianHenryIE I forgot to ask if there was a reason you can't install these with WP CLI in your initialization script?

@BrianHenryIE
Copy link
Author

From what I see, the only mapping into the host is WC_E2E_FOLDER_MAPPING, so there's no way for me to point wp plugin install to the plugin files. The key point being these are usually paid plugins, so are not available in the .org repo. So I don't know how!

@rrennick
Copy link
Contributor

rrennick commented Dec 3, 2021

The key point being these are usually paid plugins, so are not available in the .org repo. So I don't know how!

You can install and activate a plugin zip with wp plugin install /path/to/plugin.zip --activate in your container initialization script.

@zhongruige
Copy link
Contributor

Hi @BrianHenryIE,

Wanted to just follow up on this as it's been open a while. Did the option to try above work for you?

@BrianHenryIE
Copy link
Author

BrianHenryIE commented Jun 1, 2022

I had hoped the following would work but it fails at installing the WP CLI package.

wp package install wp-cli/dist-archive-command:dev-main

# List all folders in the plugin's (project) wp-content/plugins subfolder which are not symlinks or WooCommerce. Then create plugin archives for them.
find wp-content/plugins/bh-wc-disable-free-gifts-per-product/wp-content/plugins -depth 1 -type d ! -name 'woocommerce' ! -type l | xargs -n 1 -- bash -c 'wp dist-archive $0'

# List all .zip files in the plugin's (project) wp-content/plugins subfolder and install those plugins.
find wp-content/plugins/bh-wc-disable-free-gifts-per-product/wp-content/plugins -depth 1 -name '*.zip' | xargs -n 1 -- bash -c 'wp plugin install $0 --activate'
Error: Composer directory '/etc/X11/fs/.wp-cli/packages' for packages couldn't be created: mkdir(): Permission denied

I also seem to have to add || true to the end of the wp user create customer ... command in initialize.sh or it causes a loop when the username already exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants