Skip to content

Commit 20a7ffa

Browse files
josephfuscoahuseyn
andauthored
ci: jest ts jest compatibility (#2247)
* fix(faustwp-core): update ts-jest to ^29.1.1 ts-jest 27.x only supports Jest 27.x, but we're using Jest 29.x. This version mismatch caused test failures with the error: "process() or/and processAsync() method of code transformer..." Updated to ts-jest ^29.1.1 to match @faustwp/cli. * fix: update deprecated ts-jest globals config to transform syntax ts-jest deprecated the globals config in favor of transform options. Updated all jest.config.js files to use the new syntax: Before: globals: { 'ts-jest': { useESM: true } } After: transform: { '^.+\\.tsx?$': ['ts-jest', { useESM: true }] } * fix: disable default coverage collection in jest configs Coverage collection via babel-plugin-istanbul has compatibility issues with Node.js 22 due to deprecated util.promisify usage in test-exclude. Disabling collectCoverage by default allows tests to run successfully. Coverage is still collected when explicitly requested via test:coverage:ci scripts. * fix: add coverage to .eslintignore files Add coverage directory to .eslintignore to prevent prettier format checks from failing on generated coverage report files. - Create packages/faustwp-cli/.eslintignore with dist, node_modules, coverage - Update packages/faustwp-core/.eslintignore to include coverage * fix(faustwp-core): replace inline snapshots with toEqual in Toolbar tests toMatchInlineSnapshot() with expected content is not supported in newer Jest/Babel versions. Replace with toEqual() using explicit array comparisons for toolbar node content validation. * test(faustwp-core): update snapshots for fast-xml-parser 5.x fast-xml-parser 5.x changed XML quote escaping behavior, outputting unescaped quotes instead of escaped entities. Update test snapshots to match the new output format. * chore: regenerate package-lock.json Regenerate lockfile after updating ts-jest dependency to ensure correct versions are locked. * fix: regenerate package-lock.json to fix npm ci sync error The previous lockfile was missing dependencies that npm ci requires: - glob@11.1.0, glob@10.5.0 - jackspeak@4.1.1, jackspeak@3.4.3 - minimatch@10.1.1, minimatch@9.0.5 - path-scurry@2.0.1, path-scurry@1.11.1 - @isaacs/brace-expansion@5.0.0, brace-expansion@2.0.2 - @isaacs/balanced-match@4.0.1 - lru-cache@11.2.5, lru-cache@10.4.3 This caused CI to fail with: "npm ci can only install packages when your package.json and package-lock.json are in sync" * fix: remove glob overrides to resolve npm ci sync error The glob overrides in root and faustwp-core package.json were forcing glob to v10.5.0, but faustwp-cli explicitly requires glob v11.1.0. This created an unresolvable conflict causing npm ci to fail with: "Missing: glob@11.1.0 from lock file" Remove the glob overrides and regenerate package-lock.json to allow npm to resolve glob versions naturally for each package. * test(blocks): suppress expected console.error in hook error test The test for useBlocksTheme throwing when used outside provider was logging expected React errors to console.error, which caused CI to exit with code 1 even though all tests passed. * test(faustwp-cli): fix validateNextWordPressUrl test expectations The test expected console.log to be called with the full error message as a single argument, but errorLog() passes the message prefix and details as separate arguments. * fix(ci): use docker exec for MySQL health check The Wait for db step used $MYSQL_ROOT_PASSWORD which was never defined, causing intermittent test failures. Use docker compose exec to connect directly to the container instead of from the host. Bug introduced in 6e5ef28 (May 2024). * fix(ci): pin MySQL 8.0 and enable native auth for SSL compatibility MySQL 8.4+ has stricter SSL requirements causing "self-signed certificate" errors in CI. Pin to MySQL 8.0 and use mysql_native_password authentication to ensure compatibility with the WordPress test containers. Also removes deprecated docker-compose version attribute. * fix(ci): disable SSL for MySQL connections in test setup Add --ssl-mode=DISABLED to mysql/mysqladmin commands in install-wp-tests.sh to prevent SSL certificate verification errors in CI environment. * fix(ci): disable SSL for MySQL connections in test setup Add --skip-ssl to mysql/mysqladmin commands in install-wp-tests.sh to prevent SSL certificate verification errors in CI environment. Note: Using --skip-ssl instead of --ssl-mode=DISABLED for compatibility with MariaDB client (default-mysql-client) in WordPress containers. * fix: add test-exclude override for Node.js 22 coverage compatibility The test-exclude@6.0.0 package uses util.promisify in a way that's incompatible with Node.js 22, causing coverage collection to fail with "TypeError: The 'original' argument must be of type function". This adds an npm override to force test-exclude@^7.0.1 which fixes the Node.js 22 compatibility issue. * fix coverage test * Update FaustWP CLI Jest setup Add Jest as a dev dependency for the faustwp-cli package and simplify the ts-jest transform config: replace the previous useESM object with an explicit tsconfig option (tsconfig.json). This ensures ts-jest uses the project TypeScript config and keeps the Jest setup concise. * Enable ESM support for ts-jest in CLI tests Add useESM: true to the ts-jest transformer in packages/faustwp-cli/jest.config.js so TypeScript tests run in ESM mode. This ensures ts-jest handles native ESM imports/exports properly while continuing to use the existing tsconfig.json. * Update ts-jest for Node 22 compat * Add TypeScript typings and suppress InnerBlocks error Add a // @ts-expect-error before InnerBlocks.Content to silence incompatible React types across versions, and tighten TypeScript annotations in errorLoggingLink: specify the Observable observer shape and explicit types for next and error handlers (FetchResult / unknown). These changes address TS type errors and improve type safety without altering runtime behavior. * Update errorLoggingLink.ts * fix: add transformIgnorePatterns to Jest configs for ESM compatibility - Add transformIgnorePatterns to faustwp-core and blocks Jest configs to transform @apollo/client, ts-invariant, tslib, and zen-observable-ts - Add ts-invariant as explicit devDependency in faustwp-core to fix missing transitive dependency issue This resolves Jest test failures on Node.js 22 where ESM modules from @apollo/client were not being transformed correctly during test runs. * fix: add @apollo/client transitive dependencies for Jest compatibility Add explicit devDependencies for @apollo/client's transitive dependencies in faustwp-core. Due to npm workspace hoisting, the local @apollo/client (v3.14.0) cannot resolve its dependencies when they're hoisted to the root node_modules with different versions. Added dependencies: - @graphql-typed-document-node/core - @wry/caches, @wry/equality, @wry/trie - graphql-tag, hoist-non-react-statics - optimism, prop-types, rehackt - symbol-observable, tslib, zen-observable-ts This fixes "Cannot find module 'zen-observable-ts'" and similar errors that caused 10 faustwp-core and 3 blocks test suites to fail in CI. * Update action.yml * fix: run coverage tests manually to avoid test-exclude/glob incompatibility The jest-coverage-report-action's skip-step: install parameter was not working, causing npm install to run and override the locked dependencies. This resulted in test-exclude@6.0.0 being used with glob v11, which fails on Node 22 due to promisify incompatibility. This change: - Runs coverage tests manually using npm scripts (respects npm ci deps) - Uses coverage-file parameter to provide pre-generated reports - Upgrades action to v2.3.1 and uses skip-step: all * fix: run coverage tests manually to avoid test-exclude/glob incompatibility The jest-coverage-report-action's skip-step: install parameter was not working, causing npm install to run and override the locked dependencies. This resulted in test-exclude@6.0.0 being used with glob v11, which fails on Node 22 due to promisify incompatibility. This change: - Runs coverage tests manually using npm scripts (respects npm ci deps) - Uses coverage-file parameter to provide pre-generated reports - Upgrades action to v2.3.1 and uses skip-step: all --------- Co-authored-by: ahuseyn <huseyn.aghayev@wpengine.com>
1 parent 765a266 commit 20a7ffa

21 files changed

Lines changed: 17083 additions & 15324 deletions

File tree

.github/actions/run-coverage/action.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ inputs:
99
runs:
1010
using: 'composite'
1111
steps:
12-
# We are currently fixed at 2.1.2 since 2.2 was throwing errors
13-
# Remove this when the issue has been resolved.
14-
- uses: ArtiomTr/jest-coverage-report-action@v2.1.2
12+
# Run coverage tests manually to use correct dependencies from npm ci.
13+
# This ensures the lockfile and package.json overrides are respected,
14+
# avoiding test-exclude/glob version incompatibility issues on Node 22.
15+
- name: Run coverage tests
16+
shell: bash
17+
working-directory: ${{ inputs.working-directory }}
18+
run: npm run test:coverage:ci
19+
20+
# Use the action only for report generation, not for running tests
21+
- uses: ArtiomTr/jest-coverage-report-action@v2.3.1
1522
with:
16-
# tell to the action to not attach comment.
1723
output: report-markdown
18-
test-script: npm run test:coverage:ci
24+
coverage-file: report.json
25+
base-coverage-file: report.json
1926
working-directory: ${{ inputs.working-directory }}
2027
annotations: none
21-
continue-on-error: FALSE
28+
skip-step: all
29+
continue-on-error: false
2230

.github/workflows/unit-test-plugin.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ jobs:
2828
docker compose up -d
2929
3030
- name: Wait for db
31+
working-directory: ./plugins/faustwp
3132
run: |
32-
while ! mysqladmin ping --host=127.0.0.1 --port=33066 --password=$MYSQL_ROOT_PASSWORD --silent; do
33+
until docker compose exec -T db mysqladmin ping -pwordpress --silent; do
3334
sleep 1
3435
done
3536

0 commit comments

Comments
 (0)