Skip to content

Commit e77626d

Browse files
authored
[E2E][QIT] Add QIT foundation with basic connectivity tests (#11047)
1 parent 95546f6 commit e77626d

File tree

11 files changed

+243
-12
lines changed

11 files changed

+243
-12
lines changed

changelog/dev-qit-e2e-foundation

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: dev
3+
Comment: Add foundation to run E2E tests with QIT and basic tests.
4+
5+

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"cweagans/composer-patches": "1.7.1",
4343
"automattic/jetpack-changelogger": "3.3.2",
4444
"spatie/phpunit-watcher": "1.23.6",
45-
"woocommerce/qit-cli": "0.4.0",
45+
"woocommerce/qit-cli": "0.10.0",
4646
"slevomat/coding-standard": "8.15.0",
4747
"dg/bypass-finals": "1.5.1",
4848
"sirbrillig/phpcs-variable-analysis": "^2.11",

composer.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"test:qit-phpstan": "npm run build:release && ./tests/qit/phpstan.sh",
4949
"test:qit-phpstan-local": "npm run build:release && ./tests/qit/phpstan.sh --local",
5050
"test:qit-malware": "npm run build:release && ./tests/qit/malware.sh --local",
51+
"test:qit-e2e": "./tests/qit/e2e-runner.sh",
5152
"watch": "webpack --watch",
5253
"hmr": "webpack server",
5354
"start": "npm run watch",

tests/js/jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module.exports = {
4646
'<rootDir>/.*/build-module/',
4747
'<rootDir>/docker/',
4848
'<rootDir>/tests/e2e',
49+
'<rootDir>/tests/qit/e2e',
4950
],
5051
watchPathIgnorePatterns: [
5152
'/node_modules/',
@@ -54,6 +55,7 @@ module.exports = {
5455
'<rootDir>/.*/build-module/',
5556
'<rootDir>/docker/',
5657
'<rootDir>/tests/e2e',
58+
'<rootDir>/tests/qit/e2e',
5759
],
5860
transform: {
5961
...tsjPreset.transform,

tests/qit/config/default.env

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
# Create `local.env` and supply actual values.
2-
QIT_USER=""
3-
QIT_PASSWORD=""
1+
# QIT Configuration for WooCommerce Payments
2+
# Copy this file to local.env and update with your values
3+
4+
# ===========================================
5+
# QIT CLI CREDENTIALS (for security, phpstan, malware, custom e2e tests)
6+
# ===========================================
7+
QIT_USER=your_qit_username
8+
QIT_PASSWORD=your_qit_application_password
9+

tests/qit/e2e-runner.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
# Enable strict error handling and safe field splitting for reliability
4+
set -euo pipefail
5+
IFS=$'\n\t'
6+
7+
# E2E test runner for WooPayments using QIT
8+
cwd=$(pwd)
9+
WCP_ROOT="$cwd"
10+
QIT_ROOT="$cwd/tests/qit"
11+
12+
# Load local env variables if present
13+
if [[ -f "$QIT_ROOT/config/local.env" ]]; then
14+
. "$QIT_ROOT/config/local.env"
15+
fi
16+
17+
# If QIT_BINARY is not set, default to ./vendor/bin/qit
18+
QIT_BINARY=${QIT_BINARY:-./vendor/bin/qit}
19+
20+
echo "Running E2E tests..."
21+
22+
# Change to project root directory to build plugin
23+
cd "$WCP_ROOT"
24+
25+
# Foundation version: Simplified build process for easier testing
26+
# For this foundation PR, we'll always build to avoid complex signature computation issues
27+
28+
BUILD_HASH_FILE="$WCP_ROOT/woocommerce-payments.zip.hash"
29+
30+
# For this foundation PR, always build if zip doesn't exist or if forced
31+
if [[ -n "${WCP_FORCE_BUILD:-}" ]] || [[ ! -f "woocommerce-payments.zip" ]]; then
32+
echo "Building WooPayments plugin..."
33+
npm run build:release
34+
echo "foundation-build-$(date +%s)" > "$BUILD_HASH_FILE"
35+
else
36+
echo "Using existing woocommerce-payments.zip"
37+
fi
38+
39+
# Change to QIT directory so qit.yml is automatically found
40+
cd "$QIT_ROOT"
41+
42+
# Convert relative QIT_BINARY path to absolute for directory change compatibility
43+
if [[ "$QIT_BINARY" = ./* ]]; then
44+
QIT_CMD="$WCP_ROOT/$QIT_BINARY"
45+
else
46+
QIT_CMD="$QIT_BINARY"
47+
fi
48+
49+
echo "Running QIT E2E foundation tests (no Jetpack credentials)..."
50+
51+
# Run our QIT E2E tests (qit.yml automatically loaded from current directory)
52+
"$QIT_CMD" run:e2e woocommerce-payments ./e2e \
53+
--source "$WCP_ROOT/woocommerce-payments.zip"
54+
55+
echo "QIT E2E foundation tests completed!"

tests/qit/e2e/.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
},
5+
globals: {
6+
page: 'readonly',
7+
browser: 'readonly',
8+
context: 'readonly',
9+
},
10+
rules: {
11+
// Disable Jest-specific rules that conflict with Playwright
12+
'jest/no-done-callback': 'off',
13+
'jest/expect-expect': 'off',
14+
// Allow QIT-specific imports that ESLint can't resolve
15+
'import/no-unresolved': [ 'error', { ignore: [ '/qitHelpers' ] } ],
16+
},
17+
overrides: [
18+
{
19+
files: [ '*.spec.js', '*.test.js' ],
20+
rules: {
21+
// Playwright test specific overrides
22+
'jest/no-done-callback': 'off',
23+
},
24+
},
25+
],
26+
};

tests/qit/e2e/basic.spec.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { test, expect } from '@playwright/test';
5+
import qit from '/qitHelpers';
6+
7+
/**
8+
* Simple QIT E2E test - bare minimum to verify QIT works
9+
*/
10+
test( 'Load home page', async ( { page } ) => {
11+
await page.goto( '/' );
12+
13+
// Just check that we can load the page and title exists
14+
await expect( page ).toHaveTitle( /.*/ );
15+
} );
16+
17+
/**
18+
* Test WooCommerce Payments onboarding flow access
19+
* Since we're running in development mode without Jetpack connection,
20+
* we expect to always land on the onboarding flow.
21+
*/
22+
test( 'Access WooCommerce Payments onboarding as admin', async ( { page } ) => {
23+
// Use QIT helper to login as admin
24+
await qit.loginAsAdmin( page );
25+
26+
// Navigate to WooCommerce Payments settings
27+
await page.goto(
28+
'/wp-admin/admin.php?page=wc-admin&path=%2Fpayments%2Foverview'
29+
);
30+
31+
// We should see the Payments admin route load
32+
await expect(
33+
page.locator( 'h1:not(.screen-reader-text)' ).first()
34+
).toContainText( /Settings|Payments|Overview/, { timeout: 15000 } );
35+
36+
// In development mode without Jetpack connection, we should be on onboarding
37+
expect( page.url() ).toContain( 'onboarding' );
38+
39+
// The onboarding page should load without errors
40+
await expect( page.locator( 'body' ) ).not.toHaveText(
41+
/500|404|Fatal error/
42+
);
43+
} );
44+
45+
/**
46+
* Test plugin activation and basic WooCommerce functionality
47+
*/
48+
test( 'Verify WooCommerce Payments plugin activation', async ( { page } ) => {
49+
await qit.loginAsAdmin( page );
50+
51+
// Check plugins page to verify WooCommerce Payments is active
52+
await page.goto( '/wp-admin/plugins.php' );
53+
54+
// Look for the WooCommerce Payments plugin row (exclude update row)
55+
const pluginRow = page.locator(
56+
'tr[data-plugin*="woocommerce-payments"]:not(.plugin-update-tr)'
57+
);
58+
await expect( pluginRow ).toBeVisible();
59+
60+
// Verify it shows as activated
61+
await expect( pluginRow.locator( '.deactivate' ) ).toBeVisible();
62+
} );

tests/qit/e2e/bootstrap/setup.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
# QIT Bootstrap Setup for WooCommerce Payments E2E Tests
7+
# This script runs before tests to configure the plugin environment
8+
9+
echo "Setting up WooCommerce Payments for E2E testing..."
10+
11+
# Ensure environment is marked as local so dev-only CLI commands are available
12+
wp config set WP_ENVIRONMENT_TYPE local --quiet 2>/dev/null || true
13+
14+
# Create a test product for payment testing
15+
PRODUCT_ID=$(wp post create \
16+
--post_title="Test Product for Payments" \
17+
--post_content="A simple test product for QIT payment testing" \
18+
--post_status=publish \
19+
--post_type=product \
20+
--porcelain)
21+
22+
# Set product meta data properly
23+
wp post meta update $PRODUCT_ID _price "10.00"
24+
wp post meta update $PRODUCT_ID _regular_price "10.00"
25+
wp post meta update $PRODUCT_ID _virtual "yes"
26+
wp post meta update $PRODUCT_ID _manage_stock "no"
27+
28+
# Ensure WooCommerce checkout page exists and is properly configured
29+
wp option update woocommerce_checkout_page_id $(wp post list --post_type=page --post_name=checkout --field=ID --format=ids)
30+
31+
# Configure WooCommerce for testing
32+
wp option update woocommerce_currency "USD"
33+
wp option update woocommerce_enable_guest_checkout "yes"
34+
wp option update woocommerce_force_ssl_checkout "no"
35+
36+
# Create a test customer
37+
wp user create testcustomer [email protected] \
38+
--role=customer \
39+
--user_pass=testpass123 \
40+
--first_name="Test" \
41+
--last_name="Customer" \
42+
--quiet
43+
44+
echo "Setting up WooCommerce Payments configuration..."
45+
46+
# NOTE: Jetpack connection setup will be added in future PRs
47+
# For now, WooPayments will run in development mode
48+
echo "Running WooPayments without a Jetpack connection (Jetpack connection setup in upcoming PRs)"
49+
50+
# Enable development/test mode for better testing experience
51+
wp option set wcpay_dev_mode 1 --quiet 2>/dev/null || true
52+
53+
# Disable proxy mode (we want direct production API access)
54+
wp option set wcpaydev_proxy 0 --quiet 2>/dev/null || true
55+
56+
# Disable onboarding redirect for E2E testing
57+
wp option set wcpay_should_redirect_to_onboarding 0 --quiet 2>/dev/null || true
58+
59+
echo "WooPayments configuration completed"

0 commit comments

Comments
 (0)