Skip to content

Migrate native tests to workspace#77425

Open
USERSATOSHI wants to merge 7 commits intoWordPress:trunkfrom
USERSATOSHI:try/migrate-test-native-to-workspace
Open

Migrate native tests to workspace#77425
USERSATOSHI wants to merge 7 commits intoWordPress:trunkfrom
USERSATOSHI:try/migrate-test-native-to-workspace

Conversation

@USERSATOSHI
Copy link
Copy Markdown
Contributor

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-tests while still relating the functionality.

Testing Instructions

run npm run test:native:*

@USERSATOSHI USERSATOSHI marked this pull request as ready for review April 17, 2026 08:30
@github-actions
Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: USERSATOSHI <tusharbharti@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@USERSATOSHI
Copy link
Copy Markdown
Contributor Author

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.js
the 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 ""

@USERSATOSHI
Copy link
Copy Markdown
Contributor Author

Since the integration migration PR has been merged, we can review this one (in free time) and then close Phase 1.

cc: @manzoorwanijk

@manzoorwanijk manzoorwanijk self-requested a review April 30, 2026 14:54
@manzoorwanijk manzoorwanijk self-assigned this Apr 30, 2026
@manzoorwanijk manzoorwanijk requested a review from Copilot April 30, 2026 14:54
@manzoorwanijk manzoorwanijk added the [Type] Code Quality Issues or PRs that relate to code quality label Apr 30, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json to define the new @wordpress/native-tests workspace and its test scripts/dependencies.
  • Updated test/native/jest.config.js to resolve globs relative to the repo root and include tsx in the package index glob.
  • Updated root package.json / package-lock.json to register the new workspace and route test:native:* scripts through it (and remove root-level reassure).

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.

Comment thread test/native/package.json
Comment on lines +22 to +30
"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"
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread test/native/package.json Outdated
"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",
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"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",

Copilot uses AI. Check for mistakes.
Comment thread test/native/package.json
"@testing-library/react-native": "^12.0.0",
"babel-jest": "^29.7.0",
"cross-env": "^7.0.3",
"glob": "^10.3.10",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants