Migrate native tests to workspace#77425
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
the argument forwarding has been resolved in this. The logs ( generated a bash script to test arg forwarding )--------------------------------------
1. test:native -- --testPathPattern
Expected: jest receives --testPathPattern=<pattern>
--------------------------------------
> gutenberg@23.0.0-rc.1 test:native
> npm run --workspace @wordpress/native-tests test:native -- --testPathPattern=packages/react-native-editor --passWithNoTests
> @wordpress/native-tests@0.0.0 test:native
> cross-env NODE_ENV=test jest --config jest.config.js --testPathPattern=packages/react-native-editor --passWithNoTests
--------------------------------------
2. test:native -- --testNamePattern
Expected: jest receives --testNamePattern=<pattern>
--------------------------------------
> gutenberg@23.0.0-rc.1 test:native
> npm run --workspace @wordpress/native-tests test:native -- --testNamePattern=should render --passWithNoTests
> @wordpress/native-tests@0.0.0 test:native
> cross-env NODE_ENV=test jest --config jest.config.js --testNamePattern=should render --passWithNoTests
--------------------------------------
3. test:native -- --verbose
Expected: jest receives --verbose
--------------------------------------
> gutenberg@23.0.0-rc.1 test:native
> npm run --workspace @wordpress/native-tests test:native -- --verbose --passWithNoTests
> @wordpress/native-tests@0.0.0 test:native
> cross-env NODE_ENV=test jest --config jest.config.js --verbose --passWithNoTests
--------------------------------------
4. test:native -- --runInBand
Expected: jest receives --runInBand
--------------------------------------
> gutenberg@23.0.0-rc.1 test:native
> npm run --workspace @wordpress/native-tests test:native -- --runInBand --passWithNoTests
> @wordpress/native-tests@0.0.0 test:native
> cross-env NODE_ENV=test jest --config jest.config.js --runInBand --passWithNoTests
--------------------------------------
5. test:native:update -- --testPathPattern (critical: hardcoded + forwarded args)
Expected: jest receives --updateSnapshot AND --testPathPattern
--------------------------------------
> gutenberg@23.0.0-rc.1 test:native:update
> npm run --workspace @wordpress/native-tests test:native:update -- --testPathPattern=packages/react-native-editor --passWithNoTests
> @wordpress/native-tests@0.0.0 test:native:update
> npm run test:native -- --updateSnapshot --testPathPattern=packages/react-native-editor --passWithNoTests
> @wordpress/native-tests@0.0.0 test:native
> cross-env NODE_ENV=test jest --config jest.config.js --updateSnapshot --testPathPattern=packages/react-native-editor --passWithNoTests
--------------------------------------
6. test:native:watch (skipped - interactive)
Expected: jest receives --watch
--------------------------------------
--------------------------------------
7. test:native:clean
Expected: jest --clearCache runs
--------------------------------------
> gutenberg@23.0.0-rc.1 test:native:clean
> npm run --workspace @wordpress/native-tests test:native:clean && rm -rf $TMPDIR/jest_*
> @wordpress/native-tests@0.0.0 test:native:clean
> jest --clearCache --config jest.config.jsthe script#!/usr/bin/env bash
# Test native arg forwarding cases.
# Only shows the expanded command npm resolves — suppresses actual test output.
BOLD="\033[1m"
RESET="\033[0m"
run_case() {
local num="$1"
local desc="$2"
local expected="$3"
shift 3
echo ""
echo "--------------------------------------"
echo -e "${BOLD}${num}. ${desc}${RESET}"
echo " Expected: ${expected}"
echo "--------------------------------------"
# Run the command, only show lines npm prints before handing off to jest
# (the "> script" and "> command" lines), suppress everything after
"$@" 2>&1 | grep -E "^>" || true
echo ""
}
echo ""
echo "======================================"
echo " Native Test Arg Forwarding Test Cases"
echo "======================================"
run_case 1 \
"test:native -- --testPathPattern" \
"jest receives --testPathPattern=<pattern>" \
npm run test:native -- --testPathPattern='packages/react-native-editor' --passWithNoTests
run_case 2 \
"test:native -- --testNamePattern" \
"jest receives --testNamePattern=<pattern>" \
npm run test:native -- --testNamePattern='should render' --passWithNoTests
run_case 3 \
"test:native -- --verbose" \
"jest receives --verbose" \
npm run test:native -- --verbose --passWithNoTests
run_case 4 \
"test:native -- --runInBand" \
"jest receives --runInBand" \
npm run test:native -- --runInBand --passWithNoTests
run_case 5 \
"test:native:update -- --testPathPattern (critical: hardcoded + forwarded args)" \
"jest receives --updateSnapshot AND --testPathPattern" \
npm run test:native:update -- --testPathPattern='packages/react-native-editor' --passWithNoTests
run_case 6 \
"test:native:watch (skipped - interactive)" \
"jest receives --watch" \
echo " Skipped (interactive mode)"
run_case 7 \
"test:native:clean" \
"jest --clearCache runs" \
npm run test:native:clean
echo "======================================"
echo " Done. Review expanded commands above."
echo "======================================"
echo "" |
|
Since the integration migration PR has been merged, we can review this one (in free time) and then close Phase 1. cc: @manzoorwanijk |
There was a problem hiding this comment.
Pull request overview
Migrates the native (React Native) Jest test suite into its own workspace package (@wordpress/native-tests) to reduce reliance on the monorepo root dependencies and align with the broader “tests/tools as workspaces” initiative.
Changes:
- Added
test/native/package.jsonto define the new@wordpress/native-testsworkspace and its test scripts/dependencies. - Updated
test/native/jest.config.jsto resolve globs relative to the repo root and includetsxin the package index glob. - Updated root
package.json/package-lock.jsonto register the new workspace and routetest:native:*scripts through it (and remove root-levelreassure).
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/native/package.json | Introduces the @wordpress/native-tests workspace package with native test scripts and dependencies. |
| test/native/jest.config.js | Adjusts path/glob resolution to behave correctly when run from a workspace context. |
| package.json | Adds test/native to workspaces and updates test:native:* scripts to use --workspace @wordpress/native-tests. |
| package-lock.json | Reflects the new workspace and dependency moves (including removing root reassure). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "devDependencies": { | ||
| "@emotion/jest": "^11.14.2", | ||
| "@testing-library/react-native": "^12.0.0", | ||
| "babel-jest": "^29.7.0", | ||
| "cross-env": "^7.0.3", | ||
| "jest": "^29.6.2", | ||
| "jest-junit": "^13.0.0", | ||
| "jest-watch-typeahead": "^2.2.2", | ||
| "reassure": "^0.7.1" |
There was a problem hiding this comment.
jest.config.js requires the glob package, but test/native/package.json doesn’t declare it. This workspace will still work only as long as glob remains available from the root (phantom dependency), which defeats the purpose of the migration. Add glob to this workspace’s devDependencies (aligning with test/unit/package.json, which already declares it).
| "test:native": "cross-env NODE_ENV=test jest --config jest.config.js", | ||
| "test:native:watch": "npm run test:native -- --watch", | ||
| "test:native:clean": "jest --clearCache --config jest.config.js", | ||
| "test:native:debug": "cross-env NODE_ENV=test node --inspect-brk node_modules/.bin/jest --runInBand --verbose --config jest.config.js", |
There was a problem hiding this comment.
test:native:debug invokes node_modules/.bin/jest relative to test/native/, but in a workspaces install Jest’s binary is typically exposed via PATH (or located under the repo root), and test/native/node_modules/.bin/jest may not exist. This will likely break npm run test:native:debug after the migration. Prefer invoking jest directly (letting npm set PATH), or point to the correct Jest entrypoint/binary in a way that works in the workspace context.
| "test:native:debug": "cross-env NODE_ENV=test node --inspect-brk node_modules/.bin/jest --runInBand --verbose --config jest.config.js", | |
| "test:native:debug": "cross-env NODE_ENV=test jest --runInBand --verbose --config jest.config.js", |
| "@testing-library/react-native": "^12.0.0", | ||
| "babel-jest": "^29.7.0", | ||
| "cross-env": "^7.0.3", | ||
| "glob": "^10.3.10", |
There was a problem hiding this comment.
You forgot to update the lockfile. I would suggest doing this after updating the branch from trunk.
git checkout trunk package-lock.json && npm install
What?
Part of #75041
Why?
The issue provides more context, but in short, this PR ensures the workspace package does not rely on root dependencies once dependency isolation is enforced.
How?
This PR converts tests/native into a new workspace
@wordpress/native-testswhile still relating the functionality.Testing Instructions
run
npm run test:native:*