Skip to content

feat(test): fail Playwright runs on PHP errors in debug.log - #35

Open
Hug0-Drelon wants to merge 1 commit into
masterfrom
feat-php-debug-log
Open

Hug0-Drelon wants to merge 1 commit into
masterfrom
feat-php-debug-log

Conversation

@Hug0-Drelon

@Hug0-Drelon Hug0-Drelon commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What?

Fail Playwright tests when WordPress writes a PHP Notice, Warning, Deprecated, Parse error, or Fatal error to wp-content/debug.log, without printing those errors into REST or HTML bodies.

src/
├── debug-log/          # resolve debug.log via wp-env status --json, parse PHP lines, wrap rest()
├── test/               # export extended test + expect with auto fixtures
└── setup/global.setup.js  # truncate/skip leftover log, then fail if setup REST appends PHP errors

Why?

Consumers (polylang-wc, Polylang Pro) use requestUtils.rest() from @wordpress/e2e-test-utils-playwright, which JSON.parse()s the body. With WP_DEBUG_DISPLAY true, a notice becomes SyntaxError: Unexpected token 'N' and hides the real PHP message.

@wordpress/e2e-test-utils-playwright does not inspect PHP notices or debug.log (only browser console warnings). This package is the right place to fail on log lines while keeping REST parseable.

How?

  • Resolve debug.log from npx wp-env [--config=…] status --json using the consumer wpCliCommand / WP_ENV_CLI_COMMAND (tests-cli → tests-WordPress, otherwise WordPress).
  • Packaged globalSetup truncates or skips existing log output, wraps requestUtils.rest(), then fails if matching PHP lines were appended during setup REST work.
  • Exported test auto fixtures: worker ignores leftover lines; each test fails on new matching lines before and after (covers beforeAll); worker teardown covers afterAll.
  • Match only [date] PHP Notice|Warning|Deprecated|Parse error|Fatal error:. Ignore other error_log() noise.
  • On REST JSON SyntaxError, throw: REST <path> returned non-JSON; a PHP notice was likely printed into the response; see debug.log. Then the original message.

Consumers should set WP_DEBUG / WP_DEBUG_LOG / WP_DEBUG_DISPLAY: false in the committed wp-env config CI actually starts, import test/expect from this package, and bump the package (polylang-wc first).

Test plan

  • npm run lint:js and npm run build pass
  • Package exports test and expect (node -e smoke in CI)
  • With WP_DEBUG_DISPLAY false, requestUtils.rest() still returns parseable JSON
  • A dummy plugin that calls __() too early during a sample test fails with the PHP message from debug.log
  • Leftover wp-env boot lines are not attributed to tests
  • A REST body that starts with Notice: gets the wrapped non-JSON error message

Keep REST JSON valid with WP_DEBUG_DISPLAY off, and surface Notice/Warning/Deprecated/Fatal lines from wp-content/debug.log on the exported test fixtures.
@Hug0-Drelon Hug0-Drelon added the enhancement New feature or request label Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant