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
40 changes: 40 additions & 0 deletions .github/workflows/js-unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: JS Unit

on:
push:
branches: [ master, develop ]
paths:
- 'src/**/*.js'
- 'jest.config.js'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/js-unit.yml'
pull_request:
branches: [ master, develop ]
paths:
- 'src/**/*.js'
- 'jest.config.js'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/js-unit.yml'

# One run per PR or branch. A new push cancels the previous run.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
unit:
name: Jest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: npm
cache-dependency-path: package-lock.json
- name: Install npm dependencies
run: npm ci --legacy-peer-deps
- name: Run unit tests
run: npm run test:unit
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ Do not apply GitHub changes (close, comment, relabel) during issue triage withou

### Testing

- Unit / Jest: `npm run test:scripts` / `npm run test-old` (and related coverage scripts).
- Unit / Jest: `npm run test:unit` (wp-scripts / `@wordpress/jest-preset-default`). Watch: `npm run test:unit:watch`.
Premium: `cd pro__premium_only && npm run test:unit` when `pro__premium_only/` is present.
- PHP compatibility: `composer phpcompat` (PHPCompatibilityWP; floor from `readme.txt` `Requires PHP`).
Premium PHP: `composer phpcompat:premium` when `pro__premium_only/` is present.
- Playwright e2e (WordPress Playground, no Docker): see [`e2e/readme.md`](./e2e/readme.md)
Expand Down
64 changes: 22 additions & 42 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
const path = require( 'path' )

module.exports = {
rootDir: path.resolve( __dirname ),

// Override the setup with some of our own stuff.
setupFilesAfterEnv: [
'<rootDir>/src/test/setup-test-framework.js',
],
preset: '@wordpress/jest-preset-default',
rootDir: __dirname,

modulePathIgnorePatterns: [
'<rootDir>/freemius',
'<rootDir>/build',
],
setupFilesAfterEnv: [ '<rootDir>/src/test/setup-test-framework.js' ],

// Custom mappers.
// Overlay replaces the preset mapper, so keep the CSS stub plus Stackable aliases.
moduleNameMapper: {
'\\.(scss|css)$': require.resolve(
'@wordpress/jest-preset-default/scripts/style-mock.js'
),
'^~stackable(.*)$': '<rootDir>/src$1',
'.*\\.s?css$': '<rootDir>/src/test/scss-stub.js',
'.*\\.(png|jpg|gif)$': '<rootDir>/src/test/image-stub.js',
'.*\\.svg$': '<rootDir>/src/test/svgr-mock.js',
stackable: '<rootDir>/src/test/stackable-mock.js',
'@wordpress/ajax': '<rootDir>/src/test/ajax-stub.js',
'@wordpress/codeEditor': '<rootDir>/src/test/ajax-stub.js',
'@wordpress/api': '<rootDir>/src/test/wp-api-stub.js',
'@wordpress/plugins': '<rootDir>/src/test/wp-plugins.js',
'\\.(mp4|webm|png|jpg|jpeg|gif)$': '<rootDir>/src/test/file-stub.js',
'^stackable$': '<rootDir>/src/test/stackable-mock.js',
'@wordpress/api$': '<rootDir>/src/test/wp-api-stub.js',
'@wordpress/ajax$': '<rootDir>/src/test/wp-admin-stub.js',
'@wordpress/codeEditor$': '<rootDir>/src/test/wp-admin-stub.js',
'@wordpress/plugins$': '<rootDir>/src/test/wp-admin-stub.js',
'@wordpress/dom-ready$': '<rootDir>/src/test/dom-ready-stub.js',
},

transform: {
'^.+\\.[jt]sx?$': '<rootDir>/node_modules/babel-jest',
'^.+\\.mp4$': '<rootDir>/src/test/file-transformer.js',
},

// Ignore Unexpected identifiers in node_modules/simple-html-tokenizer/dist/es6/tokenizer.js
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!simple-html-tokenizer)',
],

// All relevant code should be included in coverage.
collectCoverageFrom: [
'src/(block|components|icons|welcome|help|format-types|higher-order)/**/*.js',
'!src/block/ghost-button/**/*', // Deprecated block, don't test anymore.
'!src/block/pullquote/**/*', // Deprecated block, don't test anymore.
'!**/__test__/**/*',
],

testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)' ],

testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/pro__premium_only/',
'<rootDir>/build/',
'<rootDir>/dist/',
'<rootDir>/e2e/',
'/src/block',
'<rootDir>/freemius/',
'<rootDir>/pro__premium_only/',
'<rootDir>/src/block/',
'<rootDir>/src/deprecated/',
'<rootDir>/src/test/',
'<rootDir>/tools/',
],
}
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@
"test:e2e:premium": "npx playwright test -c playwright.premium.config.js",
"test:debug": "npx playwright test --ui",
"test:debug:premium": "npx playwright test -c playwright.premium.config.js --ui",
"test-old": "jest --no-cache --watchAll",
"test:coverage": "jest --no-cache --coverage",
"test:fast": "npm run clean:build && jest",
"test:scripts": "wp-scripts test-unit-js",
"test:unit": "wp-scripts test-unit-js",
"test:unit:watch": "wp-scripts test-unit-js --watch",
"lint": "concurrently \"npm run lint-js\" \"npm run lint-css\"",
"lint:fix": "concurrently \"npm run lint-js:fix\" \"npm run lint-css:fix\"",
"lint-js": "wp-scripts lint-js",
Expand Down
127 changes: 0 additions & 127 deletions src/__test__/util.test.js

This file was deleted.

Loading
Loading