From f98114cdd634882a8b15cbe63a5d4a8894977a36 Mon Sep 17 00:00:00 2001 From: priethor <27339341+priethor@users.noreply.github.com> Date: Thu, 20 Nov 2025 19:25:18 +0100 Subject: [PATCH 1/4] Add CI workflow for JS unit tests --- .github/workflows/unit-tests.yml | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/unit-tests.yml diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 00000000..739882b4 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,64 @@ +name: JavaScript Unit Tests + +on: + pull_request: + branches: [trunk] + push: + branches: [trunk] + # Allow manually triggering the workflow + workflow_dispatch: + +# Cancels all previous workflow runs for pull requests that have not completed +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + cancel-in-progress: true + +# Disable permissions for all available scopes by default +permissions: {} + +jobs: + unit-js: + name: JavaScript Unit Tests (Node.js ${{ matrix.node }}) + runs-on: ubuntu-latest + permissions: + contents: read + + strategy: + fail-fast: false + matrix: + event: ['${{ github.event_name }}'] + node: ['22'] + include: + # On push to trunk: also test minimum supported version + - event: 'push' + node: '20' + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + show-progress: false + persist-credentials: false + + - name: Setup Node.js and install dependencies + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run unit tests + run: npm run test:unit -- --ci --coverage + + - name: Upload coverage to Codecov + if: always() + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage/unit/lcov.info + flags: javascript + slug: WordPress/secure-custom-fields + name: javascript-coverage + fail_ci_if_error: false From 4110484da8601d29fc8b94e1c2bee0a77c6c88d3 Mon Sep 17 00:00:00 2001 From: priethor <27339341+priethor@users.noreply.github.com> Date: Thu, 20 Nov 2025 19:25:47 +0100 Subject: [PATCH 2/4] Create subfolders for the coverage reports to avoid overwriting them --- .github/workflows/e2e.yml | 2 +- .github/workflows/phpunit.yml | 4 ++-- .nycrc | 2 +- jest.config.js | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ee24fe65..d0109065 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -48,7 +48,7 @@ jobs: uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage/lcov.info + files: ./coverage/e2e/lcov.info flags: e2e slug: WordPress/secure-custom-fields name: e2e-coverage diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index ef433694..be6a64e2 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -40,13 +40,13 @@ jobs: composer install --no-progress --prefer-dist --no-interaction - name: Run PHPUnit with coverage - run: vendor/bin/phpunit --coverage-clover=coverage.xml + run: mkdir -p coverage/phpunit && vendor/bin/phpunit --coverage-clover=coverage/phpunit/coverage.xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} slug: WordPress/secure-custom-fields - files: ./coverage.xml + files: ./coverage/phpunit/coverage.xml flags: phpunit name: phpunit-php-${{ matrix.php }} diff --git a/.nycrc b/.nycrc index 0de7d85d..5830c700 100644 --- a/.nycrc +++ b/.nycrc @@ -1,6 +1,6 @@ { "tempDir": ".nyc_output", - "reportDir": "./coverage", + "reportDir": "./coverage/e2e", "reporter": [ "html", "lcov", "text" ], "include": [ "assets/src/**/*.js", "assets/src/**/*.jsx" ], "exclude": [ diff --git a/jest.config.js b/jest.config.js index b8dfd14c..9bd076cc 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,5 +15,7 @@ module.exports = { '!**/node_modules/**', '!**/vendor/**', ], + coverageDirectory: 'coverage/unit', + coverageReporters: [ 'lcov', 'text', 'html' ], transformIgnorePatterns: [ 'node_modules/(?!(react-jsx-parser)/)' ], }; From 47eedd511388db59ee0b7c35cd9430ca0e2635b6 Mon Sep 17 00:00:00 2001 From: priethor <27339341+priethor@users.noreply.github.com> Date: Thu, 20 Nov 2025 19:41:07 +0100 Subject: [PATCH 3/4] Run only node 20 in PRs, 22 and 24 in trunk, better coverage report naming --- .github/workflows/unit-tests.yml | 97 ++++++++++++++++---------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 739882b4..81da65d8 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -1,64 +1,65 @@ name: JavaScript Unit Tests on: - pull_request: - branches: [trunk] - push: - branches: [trunk] - # Allow manually triggering the workflow - workflow_dispatch: + pull_request: + branches: [trunk] + push: + branches: [trunk] + # Allow manually triggering the workflow + workflow_dispatch: # Cancels all previous workflow runs for pull requests that have not completed concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + cancel-in-progress: true # Disable permissions for all available scopes by default permissions: {} jobs: - unit-js: - name: JavaScript Unit Tests (Node.js ${{ matrix.node }}) - runs-on: ubuntu-latest - permissions: - contents: read + unit-js: + name: JavaScript Unit Tests (Node.js ${{ matrix.node }}) + runs-on: ubuntu-latest + permissions: + contents: read + strategy: + fail-fast: false + matrix: + event: ['${{ github.event_name }}'] + node: ['20', '22', '24'] + exclude: + # On PRs: only test minimum supported version + - event: 'pull_request' + node: '22' + - event: 'pull_request' + node: '24' - strategy: - fail-fast: false - matrix: - event: ['${{ github.event_name }}'] - node: ['22'] - include: - # On push to trunk: also test minimum supported version - - event: 'push' - node: '20' + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + show-progress: false + persist-credentials: false - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - show-progress: false - persist-credentials: false + - name: Setup Node.js and install dependencies + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'npm' - - name: Setup Node.js and install dependencies - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node }} - cache: 'npm' + - name: Install dependencies + run: npm ci - - name: Install dependencies - run: npm ci + - name: Run unit tests + run: npm run test:unit -- --ci --coverage - - name: Run unit tests - run: npm run test:unit -- --ci --coverage - - - name: Upload coverage to Codecov - if: always() - uses: codecov/codecov-action@v5 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage/unit/lcov.info - flags: javascript - slug: WordPress/secure-custom-fields - name: javascript-coverage - fail_ci_if_error: false + - name: Upload coverage to Codecov + if: always() + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage/unit/lcov.info + flags: javascript + slug: WordPress/secure-custom-fields + name: unit-js-node-${{ matrix.node }} + fail_ci_if_error: false From 217dcae257aa87b0cca1899eee245f4baac9f601 Mon Sep 17 00:00:00 2001 From: priethor <27339341+priethor@users.noreply.github.com> Date: Thu, 20 Nov 2025 19:55:14 +0100 Subject: [PATCH 4/4] Simplify job name to improve readability --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 81da65d8..8b29e4f0 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -18,7 +18,7 @@ permissions: {} jobs: unit-js: - name: JavaScript Unit Tests (Node.js ${{ matrix.node }}) + name: Node.js ${{ matrix.node }} runs-on: ubuntu-latest permissions: contents: read