woocommerce/plugins/woocommerce-blocks/.github/workflows/unit-tests.yml

164 lines
5.6 KiB
YAML

name: Unit tests
on:
push:
branches: [trunk]
pull_request:
jobs:
Setup:
runs-on: ubuntu-latest
name: Setup
steps:
- uses: actions/checkout@v3
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install Node Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --no-optional
- name: Build Assets
run: FORCE_REDUCED_MOTION=true npm run build:e2e-test
- name: Store Build Assets
uses: actions/upload-artifact@v3
with:
name: build-assets
path: build/
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.0" # This is not the PHP version used to run the tests, that is set by wp-env
coverage: none
tools: composer
- name: Composer install
run: composer install
PHPUnitTests:
name: PHP ${{ matrix.php }}
needs: Setup
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0' ]
steps:
- uses: actions/checkout@v3
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Download Build Assets
uses: actions/download-artifact@v3
with:
name: build-assets
- name: blocks.ini setup
run: echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = test' > blocks.ini
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Set up Composer caching
uses: actions/cache@v3
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install PHP deps
run: composer install
- name: Setup Permissions
run: |
mkdir -p ./wp-content/uploads/wc-logs
echo 'deny from all' > ./wp-content/uploads/wc-logs/.htaccess
chmod -R 777 ./
- name: Run PHPUnit tests
run: |
JSON='{"phpVersion": "${{ matrix.php }}"}'
echo $JSON > .wp-env.override.json
npm run wp-env start --update
npm run test:php
- name: Run PHPUnit tests (WooCommerce Development Version)
run: |
JSON='{"plugins": [".","https://downloads.wordpress.org/plugin/woocommerce.zip"], "phpVersion": "${{ matrix.php }}"}'
echo $JSON > .wp-env.override.json
npm run wp-env stop
rm -rf /home/runner/wp-env/*
npm run wp-env start --update
npm run test:php
JSUnitTests:
name: JS Unit Tests
needs: Setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Download Build Assets
uses: actions/download-artifact@v3
with:
name: build-assets
- name: blocks.ini setup
run: echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = test' > blocks.ini
- name: Run JavaScript Unit tests
run: npm run test