woocommerce / woocommerce-e2e-boilerplate

GNU General Public License v3.0
18 stars 3 forks source link

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

Open BrianHenryIE opened 3 years ago

BrianHenryIE commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.