Tests: Fix argument forwarding for test:unit workspace scripts#77541
Tests: Fix argument forwarding for test:unit workspace scripts#77541manzoorwanijk wants to merge 1 commit intotrunkfrom
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. |
|
Size Change: 0 B Total Size: 7.76 MB ℹ️ View Unchanged
|
|
Flaky tests detected in b13c1a4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24767999723
|
|
Hi @manzoorwanijk, Thanks for creating the PR. I checked, and the I also explored whether there’s another way to solve this. Currently, we are copying the scripts from I tried the following approach: "test:unit": "npm run --workspace @wordpress/unit-tests test:unit --"This seems to work for the case that was failing:
I’m also checking if there’s anything missing with this approach in the meantime, but it should preserve the advantages of decoupling unit tests into a workspace. |
|
I was testing for the 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 "" |
|
@USERSATOSHI that is a good idea. It should work. Thanks. |
Follow-up to #77063. After the test/unit workspace conversion, flags passed via `npm run test:unit -- ...` were swallowed by the nested `npm run --workspace` call. For example: npm run test:unit -- --testPathPattern='test/crdt.ts' …ran the entire suite instead of filtering. Append a trailing `--` to each workspace-delegating script so npm forwards all subsequent user args (both flags and positionals) to the workspace command untouched. Also drop the `-- --` workaround in `fixtures:generate` since a single `--` now works end-to-end.
c72ab3b to
b13c1a4
Compare

What?
Follow-up fix to #77063 — fixes argument forwarding for
npm run test:unit -- ...after thetest/unitworkspace conversion.Why?
After #77063 converted
test/unitto an npm workspace, the roottest:unitscript becamenpm run --workspace @wordpress/unit-tests test:unit. The nestednpm rundrops recognized npm flags (e.g.--help) and positionals passed through--, so:npm run test:unit -- --testPathPattern='test/crdt.ts'…ran the entire suite instead of filtering.
This was noted in the workspace-conversion PR itself and worked around in
fixtures:generatewith a double-- --, and reported again in #77063 (comment).Same family of issue as #77083 (which hit
test:e2efor the same reason).How?
Append a trailing
--to each workspace-delegating script. The trailing separator explicitly marks where user args begin, so npm forwards both flags and positionals unchanged:This approach (suggested by @t-hamano in #77541 (comment)) keeps the workspace as the source of truth for the actual command and is a minimal, one-character fix per script.
Also revert the
-- --workaround infixtures:generateback to a single--since arg forwarding now works end-to-end.Testing Instructions
Verify flag forwarding:
Should list only the ~12 stylelint-config test files, not the full suite.
Verify positional forwarding (the
fixtures:generatepath):Should match only the
full-contenttests.Verify the update variant forwards flags:
Verify
fixtures:regeneratestill runs end-to-end.Use of AI Tools
Authored with assistance from Claude Code.