Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions .github/workflows/tests-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow

name: E2E Tests

on: # yamllint disable-line rule:truthy
workflow_dispatch:
pull_request:
paths:
- '**/*.php'
- 'src/**'
- 'tests/playwright/**'
- 'tests/bin/initialize.sh'
- 'composer.json'
- 'composer.lock'
- 'package.json'
- 'package-lock.json'
- '.wp-env.test.json'
- '.github/workflows/tests-e2e.yml'
push:
branches:
- main
paths:
- '**/*.php'
- 'src/**'
- 'tests/playwright/**'
- 'tests/bin/initialize.sh'
- 'composer.json'
- 'composer.lock'
- 'package.json'
- 'package-lock.json'
- '.wp-env.test.json'
- '.github/workflows/tests-e2e.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
prepare:
name: Build assets and prepare Chromium
runs-on: ubuntu-22.04
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version-file: 'package.json'
cache: 'npm'

- name: Install npm dependencies
run: npm ci

- name: Build plugin assets
run: npm run build

- name: Archive build assets
uses: actions/upload-artifact@v4
with:
name: dist-assets
path: build

- name: Cache Chromium
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('package-lock.json') }}

- name: Install Chromium
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright install chromium

# Zip artifacts strip Unix execute bits; tar preserves them for Playwright binaries.
- name: Pack Chromium cache
run: tar -C "$HOME/.cache" -czf playwright-chromium.tar.gz ms-playwright

- name: Archive Chromium
uses: actions/upload-artifact@v4
with:
name: playwright-chromium
path: playwright-chromium.tar.gz

test-e2e:
name: E2E - WP ${{ matrix.core || 'latest' }} / PHP ${{ matrix.php }}
needs: prepare
runs-on: ubuntu-22.04
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
include:
- php: '8.1'
core: 'WordPress/WordPress#7.0'
# null = latest official WordPress release (wp-env default).
- php: '8.3'
core: null
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version-file: 'package.json'
cache: 'npm'

- name: Install npm dependencies
run: npm ci

- name: Restore build assets
uses: actions/download-artifact@v4
with:
name: dist-assets
path: build

- name: Restore Chromium
uses: actions/download-artifact@v4
with:
name: playwright-chromium
path: .

- name: Unpack Chromium cache
run: |
mkdir -p "$HOME/.cache"
tar -C "$HOME/.cache" -xzf playwright-chromium.tar.gz

- name: Install Chromium operating-system dependencies
run: npx playwright install-deps chromium

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install Composer dependencies
run: composer install --no-interaction --prefer-dist --optimize-autoloader

- name: Launch test environment
env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.core }}
run: npm run env:start-ci

- name: Run E2E tests
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
run: npm run test:e2e

- name: Sanitize Core version for artifact name
id: core-label
if: failure()
run: |
echo "core=${{ matrix.core || 'latest' }}" | tr '/\\#:*?"<>|' '-' >> "$GITHUB_OUTPUT"

- name: Archive failure artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: e2e-${{ steps.core-label.outputs.core }}-php-${{ matrix.php }}
path: artifacts/test-results
if-no-files-found: ignore

- name: Stop test environment
if: always()
continue-on-error: true
run: npm run env:stop-tests
50 changes: 50 additions & 0 deletions .github/workflows/tests-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow

name: JS Unit Tests

on: # yamllint disable-line rule:truthy
workflow_dispatch:
pull_request:
paths:
- 'src/**'
- 'tests/js/**'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/tests-js.yml'
push:
branches:
- main
paths:
- 'src/**'
- 'tests/js/**'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/tests-js.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test-js:
name: Jest unit tests
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version-file: 'package.json'
cache: 'npm'

- name: Install npm dependencies
run: npm ci

- name: Run JS unit tests
run: npm run test:unit:js
155 changes: 155 additions & 0 deletions .github/workflows/tests-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow

name: PHP Tests

on: # yamllint disable-line rule:truthy
workflow_dispatch:
pull_request:
paths:
- '**/*.php'
- 'tests/php/**'
- 'tests/bootstrap.php'
- 'tests/wp-tests-config.php'
- 'tests/bin/initialize.sh'
- 'build/**'
- 'src/**'
- 'composer.json'
- 'composer.lock'
- 'package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- '.wp-env.test.json'
- '.github/workflows/tests-php.yml'
push:
branches:
- main
paths:
- '**/*.php'
- 'tests/php/**'
- 'tests/bootstrap.php'
- 'tests/wp-tests-config.php'
- 'tests/bin/initialize.sh'
- 'src/**'
- 'composer.json'
- 'composer.lock'
- 'package.json'
- 'package-lock.json'
- 'build/**'
- 'phpunit.xml.dist'
- '.wp-env.test.json'
- '.github/workflows/tests-php.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test-php:
name: PHPUnit - WP ${{ matrix.core || 'latest' }} / PHP ${{ matrix.php }}
runs-on: ubuntu-22.04
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.3']
# null = latest official WordPress release (wp-env default).
core: [null]
include:
- php: '8.1'
core: 'WordPress/WordPress#7.0'
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version-file: 'package.json'
cache: 'npm'

- name: Install npm dependencies
run: npm ci

- name: Build plugin assets
run: npm run build

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install Composer dependencies
run: composer install --no-interaction --prefer-dist --optimize-autoloader

- name: Check platform requirements
run: |
composer check-platform-reqs --lock --no-dev
composer check-platform-reqs --lock

- name: Launch test environment
env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.core }}
run: npm run env:start-ci

- name: Run PHPUnit
run: npm run test:php

- name: Stop test environment
if: always()
continue-on-error: true
run: npm run env:stop-tests

coverage:
name: PHPUnit coverage
runs-on: ubuntu-22.04
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version-file: 'package.json'
cache: 'npm'

- name: Install npm dependencies
run: npm ci

- name: Build plugin assets
run: npm run build

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none

- name: Install Composer dependencies
run: composer install --no-interaction --prefer-dist --optimize-autoloader

- name: Launch coverage environment
env:
WP_ENV_PHP_VERSION: '8.1'
run: npm run env:start-tests

- name: Run PHPUnit with coverage
run: npm run test:php:coverage

- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: phpunit-coverage
path: coverage
if-no-files-found: warn

- name: Stop coverage environment
if: always()
continue-on-error: true
run: npm run env:stop-tests
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ yarn-error.log*

# Coverage directory used by tools like istanbul
coverage
/coverage/
.phpunit.result.cache

# Playwright / E2E artifacts
/artifacts/

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/
Expand Down
Loading
Loading