Skip to content

Commit c9a2baf

Browse files
Tsvetan StoychevTsvetan Stoychev
authored andcommitted
Make WooCommerce E2E storefront inspectable
1 parent 74160fc commit c9a2baf

10 files changed

Lines changed: 129 additions & 5 deletions

‎AGENTS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ namespace, PSR-4 Composer autoloading, PHP 7.4+, and WordPress 6.0+.
3434
`assets/js/loaders/`.
3535
- WooCommerce browser E2E tests are root-level test tooling. Keep the pinned
3636
WooCommerce version and checksum synchronized in `tools/setup-woocommerce-e2e.sh`.
37+
The setup disables WooCommerce Coming soon mode so anonymous storefront tests
38+
can see the seeded product.
3739
Review and update each Docker image tag and digest together in
3840
`docker/woocommerce-e2e.yml`.
3941
- Pin third-party GitHub Actions to full 40-character commit SHAs. Keep the
@@ -55,6 +57,8 @@ make conventions
5557
make unit
5658
make js-test
5759
make woocommerce-e2e
60+
make woocommerce-e2e-up
61+
make woocommerce-e2e-down
5862
make integration-setup
5963
make integration
6064
make translations

‎Makefile‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ TEST_DB_PASS = root
1313
TEST_DB_HOST = db
1414
WP_TEST_VERSION ?= latest
1515

16-
.PHONY: help build up down restart logs shell composer-install wp-install lint lint-fix lint-php analyse composer-validate composer-audit conventions translations js-install js-test woocommerce-e2e integration-setup integration test package package-verify package-smoke clean
16+
.PHONY: help build up down restart logs shell composer-install wp-install lint lint-fix lint-php analyse composer-validate composer-audit conventions translations js-install js-test woocommerce-e2e woocommerce-e2e-up woocommerce-e2e-down integration-setup integration test package package-verify package-smoke clean
1717

1818
help:
1919
@echo "Targets:"
@@ -36,6 +36,8 @@ help:
3636
@echo " js-install Install locked JavaScript test dependencies"
3737
@echo " js-test Run loader behavior tests in Chromium"
3838
@echo " woocommerce-e2e Run WooCommerce page-type browser tests"
39+
@echo " woocommerce-e2e-up Start the inspectable WooCommerce test stack on port 9081"
40+
@echo " woocommerce-e2e-down Stop and reset the inspectable WooCommerce test stack"
3941
@echo " unit Run unit tests"
4042
@echo " integration-setup Install WordPress test suite inside containers"
4143
@echo " integration Run integration tests"
@@ -103,6 +105,12 @@ js-test: js-install
103105
woocommerce-e2e:
104106
sh tools/run-woocommerce-e2e.sh
105107

108+
woocommerce-e2e-up:
109+
sh tools/up-woocommerce-e2e.sh
110+
111+
woocommerce-e2e-down:
112+
sh tools/down-woocommerce-e2e.sh
113+
106114
unit:
107115
$(COMPOSE) run --rm -w $(PLUGIN_WORKDIR) $(PHP_SERVICE) composer unit
108116

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ make conventions
2929
make translations
3030
make js-test
3131
make woocommerce-e2e
32+
make woocommerce-e2e-up
3233
make package
3334
make package-smoke
3435
```
@@ -126,11 +127,21 @@ behavior on HTTP, HTTPS, localhost, and subdomains.
126127
stack, seeds a product and completed order, then uses Playwright to visit the
127128
shop, product, cart, checkout, and order-received pages. It intercepts the
128129
synthetic collector and verifies the actual Basicrum beacon `p_type` values.
130+
WooCommerce Coming soon mode is disabled in this isolated stack, so the shop
131+
also proves that the seeded product is visible to anonymous visitors.
129132
The WooCommerce download is pinned and checksum-verified in
130133
`tools/setup-woocommerce-e2e.sh`; update its version and checksum together.
131134
The stack's Docker image tags and immutable digests are reviewed together in
132135
`docker/woocommerce-e2e.yml`.
133136

137+
To inspect the same seeded WooCommerce storefront manually, run
138+
`make woocommerce-e2e-up`. It exposes an isolated stack at
139+
`http://localhost:9081/` with `admin` / `basicrum-e2e-password`; use
140+
`make woocommerce-e2e-down` to stop and reset it. Set
141+
`WOOCOMMERCE_E2E_PORT` to use a different host port. The inspectable stack
142+
keeps its own data and plugin copy, so run `make woocommerce-e2e-down` and then
143+
`make woocommerce-e2e-up` after changing plugin source.
144+
134145
The JavaScript package, Playwright configuration, and browser tests live at the
135146
repository root. The release builder copies only `plugins/basicrum/`, and the
136147
release verifier also rejects Node or Playwright development files if they ever

‎docker/woocommerce-e2e.dev.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
wordpress:
3+
ports:
4+
- "${WOOCOMMERCE_E2E_PORT:-9081}:80"
5+
6+
wpcli:
7+
environment:
8+
WP_URL: http://localhost:${WOOCOMMERCE_E2E_PORT:-9081}
9+
WP_TITLE: Basicrum WooCommerce Local
10+
HTTP_HOST: localhost:${WOOCOMMERCE_E2E_PORT:-9081}

‎tests/e2e/woocommerce-page-types.spec.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ async function visitAndCaptureBeacon( page, route, expectedPageType, prepare ) {
4747
expect( response.ok() ).toBeTruthy();
4848
await expect( page.locator( '#basicrum-loader-js' ) ).toHaveCount( 1 );
4949

50+
if ( 'shop' === expectedPageType ) {
51+
const productLink = page.getByRole( 'link', {
52+
name: 'Basicrum E2E Product',
53+
exact: true,
54+
} );
55+
56+
await expect( productLink ).toHaveCount( 1 );
57+
await expect( productLink ).toBeVisible();
58+
}
59+
5060
const inlineConfig = await page.locator( 'script' ).evaluateAll( ( scripts ) => {
5161
return scripts
5262
.map( ( script ) => script.textContent || '' )
@@ -79,6 +89,7 @@ test.beforeAll( async ( { request } ) => {
7989

8090
expect( response.ok() ).toBeTruthy();
8191
fixture = await response.json();
92+
expect( new URL( fixture.routes.product ).pathname ).toBe( '/product/basicrum-e2e-product/' );
8293
} );
8394

8495
for ( const [ routeName, expectedPageType ] of expectedPageTypes ) {

‎tools/down-woocommerce-e2e.sh‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
SCRIPT_DIR=$( CDPATH= cd -- "$(dirname -- "$0")" && pwd )
6+
REPOSITORY_ROOT=$( CDPATH= cd -- "$SCRIPT_DIR/.." && pwd )
7+
COMPOSE_FILE="$REPOSITORY_ROOT/docker/woocommerce-e2e.yml"
8+
COMPOSE_DEV_FILE="$REPOSITORY_ROOT/docker/woocommerce-e2e.dev.yml"
9+
10+
if ! command -v docker >/dev/null 2>&1; then
11+
printf '%s\n' 'Docker is required to stop the WooCommerce development stack.' >&2
12+
exit 1
13+
fi
14+
15+
COMPOSE_PROJECT_NAME=basicrum_woocommerce_dev
16+
export COMPOSE_PROJECT_NAME
17+
18+
docker compose -f "$COMPOSE_FILE" -f "$COMPOSE_DEV_FILE" down --volumes --remove-orphans

‎tools/run-woocommerce-e2e.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ while ! compose exec -T wordpress test -f /var/www/html/wp-includes/version.php;
5151
sleep 2
5252
done
5353

54-
compose run --rm --no-deps --user "$(id -u):$(id -g)" -e COMPOSER_HOME=/tmp/composer composer \
54+
compose run --rm --no-deps -e COMPOSER_HOME=/tmp/composer composer \
5555
install --no-dev --no-interaction --prefer-dist
5656

5757
compose run --rm wpcli sh /tools/setup-woocommerce-e2e.sh

‎tools/seed-woocommerce-e2e.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
exit( 1 );
1111
}
1212

13-
update_option( 'permalink_structure', '/%postname%/' );
14-
flush_rewrite_rules();
15-
1613
$product = new WC_Product_Simple();
1714
$product->set_name( 'Basicrum E2E Product' );
1815
$product->set_regular_price( '10.00' );

‎tools/setup-woocommerce-e2e.sh‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ if [ "$(wp plugin get woocommerce --field=version --path="${WP_PATH}")" != "$WOO
5858
fi
5959

6060
wp wc tool run install_pages --user=1 --path="${WP_PATH}"
61+
62+
# Fresh WooCommerce installs enable Coming soon mode for anonymous visitors.
63+
wp option update woocommerce_coming_soon no --path="${WP_PATH}"
64+
wp option update woocommerce_store_pages_only no --path="${WP_PATH}"
65+
6166
wp plugin activate basicrum --path="${WP_PATH}"
67+
wp rewrite structure '/%postname%/' --hard --path="${WP_PATH}"
6268

6369
wp option update basicrum_settings \
6470
'{"enabled":"1","development_mode":"0","beacon_url":"https://collector.basicrum.test/beacon","brum_site_id":"550e8400-e29b-41d4-a716-446655440000","track_admins":"0","consent_enabled":"0","wait_after_onload":"0","delay_ms":0,"script_position":"footer","use_unminified_loaders":"0"}' \

‎tools/up-woocommerce-e2e.sh‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
SCRIPT_DIR=$( CDPATH= cd -- "$(dirname -- "$0")" && pwd )
6+
REPOSITORY_ROOT=$( CDPATH= cd -- "$SCRIPT_DIR/.." && pwd )
7+
COMPOSE_FILE="$REPOSITORY_ROOT/docker/woocommerce-e2e.yml"
8+
COMPOSE_DEV_FILE="$REPOSITORY_ROOT/docker/woocommerce-e2e.dev.yml"
9+
PORT=${WOOCOMMERCE_E2E_PORT:-9081}
10+
11+
if ! command -v docker >/dev/null 2>&1; then
12+
printf '%s\n' 'Docker is required to run the WooCommerce development stack.' >&2
13+
exit 1
14+
fi
15+
16+
COMPOSE_PROJECT_NAME=basicrum_woocommerce_dev
17+
export COMPOSE_PROJECT_NAME
18+
19+
compose() {
20+
docker compose -f "$COMPOSE_FILE" -f "$COMPOSE_DEV_FILE" "$@"
21+
}
22+
23+
print_access_details() {
24+
printf '%s\n' "WooCommerce test stack is ready at http://localhost:${PORT}/"
25+
printf '%s\n' "Admin: http://localhost:${PORT}/wp-admin/"
26+
printf '%s\n' 'Login: admin / basicrum-e2e-password'
27+
printf '%s\n' 'Run make woocommerce-e2e-down to stop and reset it.'
28+
}
29+
30+
if [ -n "$(compose ps -aq wordpress)" ]; then
31+
compose up -d db wordpress
32+
33+
if compose run --rm --no-deps wpcli core is-installed --path=/var/www/html >/dev/null 2>&1; then
34+
print_access_details
35+
exit 0
36+
fi
37+
fi
38+
39+
compose run --rm --no-deps plugin
40+
compose up -d db wordpress
41+
42+
attempt=0
43+
while ! compose exec -T wordpress test -f /var/www/html/wp-includes/version.php; do
44+
attempt=$((attempt + 1))
45+
46+
if [ "$attempt" -ge 30 ]; then
47+
printf '%s\n' 'WordPress files were not initialized in time.' >&2
48+
exit 1
49+
fi
50+
51+
sleep 2
52+
done
53+
54+
compose run --rm --no-deps -e COMPOSER_HOME=/tmp/composer composer \
55+
install --no-dev --no-interaction --prefer-dist
56+
57+
compose run --rm wpcli sh /tools/setup-woocommerce-e2e.sh
58+
59+
print_access_details

0 commit comments

Comments
 (0)