[CI] Add test for @php-wasm/node direct usage in Jest #3099
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚧 WIP
Motivation for the change, related issues
After upgrading from
@php-wasm/nodev3.0.22 to v3.0.39, Jest tests that useloadNodeRuntime()directly fail with ESM-related errors.The per-version packages introduced in #3062 contain JavaScript files that use ESM syntax (
import.meta.url), which breaks when loaded in Jest's CommonJS sandbox.Error:
Or alternatively:
This affects downstream projects (like WordPress Studio) that use
@php-wasm/nodedirectly in their Jest test suites.Implementation details
This PR adds a test that verifies
@php-wasm/nodecan be used directly in Jest without:--experimental-vm-modulesrunCLI()The test currently fails - it demonstrates the issue and will pass once a fix is implemented.
Root Cause
The per-version packages (
@php-wasm/node-8-3, etc.) contain ESM files:When
@php-wasm/node/index.cjsdynamically imports these packages, Jest cannot handle the ESM dynamic imports in its CommonJS sandbox.Related PRs
Testing Instructions (or ideally a Blueprint)
Run the test suite for
commonjs-and-jest:The new test
php-wasm-node.spec.tswill fail with the error above, demonstrating the issue.