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
4 changes: 4 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/.github
/node_modules
/src
/tests
/artifacts

# Configuration files
.distignore
Expand All @@ -11,8 +13,10 @@
.gitignore
.plugin-data
.wp-env.json
.wp-env.test.json
grumphp.yml
phpcs.xml.dist
phpunit.xml.dist
psalm.xml.dist

# Dependency management
Expand Down
14 changes: 12 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
{
"extends": [ "plugin:@wordpress/eslint-plugin/recommended" ]
}
"extends": [ "plugin:@wordpress/eslint-plugin/recommended" ],
"overrides": [
{
"files": [ "tests/js/**/*.js" ],
"extends": [ "plugin:@wordpress/eslint-plugin/test-unit" ]
},
{
"files": [ "tests/playwright/**/*.js" ],
"extends": [ "plugin:@wordpress/eslint-plugin/test-playwright" ]
}
]
}
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/.github export-ignore
/node_modules export-ignore
/src export-ignore
/tests export-ignore
/artifacts export-ignore

# Configuration files
/.distignore export-ignore
Expand All @@ -11,8 +13,10 @@
/.gitignore export-ignore
/.plugin-data export-ignore
/.wp-env.json export-ignore
/.wp-env.test.json export-ignore
/grumphp.yml export-ignore
/phpcs.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml.dist export-ignore

# Dependency management
Expand Down
154 changes: 154 additions & 0 deletions .github/workflows/tests-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# 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/**'
- 'composer.json'
- '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@v5

- name: Set up Node.js
uses: actions/setup-node@v5
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@v5
with:
name: dist-assets
path: build

- name: Cache Chromium
id: playwright-cache
uses: actions/cache@v5
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

# Artifacts lose executable permissions on individual files.
- name: Pack Chromium with executable permissions
run: tar -C "$HOME/.cache" -czf playwright-chromium.tar.gz ms-playwright

- name: Archive Chromium
uses: actions/upload-artifact@v5
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: 20
strategy:
fail-fast: false
matrix:
php: ['8.1']
core: ['WordPress/WordPress#6.7', null]
steps:
- name: Checkout
uses: actions/checkout@v5

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

- name: Install npm dependencies
run: npm ci

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

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

- name: Unpack Chromium with executable permissions
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

# The block renderer is loaded through the Composer autoloader.
- name: Install Composer dependencies
run: composer install --no-dev --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@v5
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
41 changes: 41 additions & 0 deletions .github/workflows/tests-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow

name: JavaScript 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'

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

permissions:
contents: read

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

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

- name: Install npm dependencies
run: npm ci

- name: Run Jest
run: npm run test:unit:js
131 changes: 131 additions & 0 deletions .github/workflows/tests-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# 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'
- 'src/**'
- 'tests/php/**'
- 'tests/bootstrap.php'
- 'tests/wp-tests-config.php'
- 'composer.json'
- 'package.json'
- 'package-lock.json'
- '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']
core: ['WordPress/WordPress#6.7', null]
steps:
- name: Checkout
uses: actions/checkout@v5

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

- name: Install npm dependencies
run: npm ci

# The block is registered from build/, which is not versioned.
- 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

# Production requirements only: dev tools are resolved for the simulated
# platform (config.platform.php) and some need a newer PHP than the plugin.
- name: Check production platform requirements
run: composer check-platform-reqs --no-dev

- 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@v5

- name: Set up Node.js
uses: actions/setup-node@v5
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-html=coverage/ --coverage-text

- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v5
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ yarn-error.log*
# Coverage directory used by tools like istanbul
coverage

# Test outputs (Playwright traces, PHPUnit cache)
/artifacts/
.phpunit.result.cache

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