From f39164c62c21c91018677653acb1f23aed055203 Mon Sep 17 00:00:00 2001 From: Wesley LeMahieu Date: Sun, 1 Jun 2025 11:34:49 -0700 Subject: [PATCH 1/7] add quotes around pwd path variable --- scripts/react-compiler/link-compiler.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/react-compiler/link-compiler.sh b/scripts/react-compiler/link-compiler.sh index 47bb84be94d9f..987209688783a 100755 --- a/scripts/react-compiler/link-compiler.sh +++ b/scripts/react-compiler/link-compiler.sh @@ -12,6 +12,6 @@ fi HERE=$(pwd) -cd compiler/packages/babel-plugin-react-compiler && yarn --silent link && cd $HERE +cd compiler/packages/babel-plugin-react-compiler && yarn --silent link && cd "$HERE" yarn --silent link babel-plugin-react-compiler From e1b5d33eaa0f38b12e27dda3e280c213dd83cf55 Mon Sep 17 00:00:00 2001 From: Wesley LeMahieu Date: Sun, 1 Jun 2025 12:04:28 -0700 Subject: [PATCH 2/7] fix playground link-compiler script --- compiler/apps/playground/scripts/link-compiler.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/apps/playground/scripts/link-compiler.sh b/compiler/apps/playground/scripts/link-compiler.sh index 1ee5f0b81bf09..96188f7b45137 100755 --- a/compiler/apps/playground/scripts/link-compiler.sh +++ b/compiler/apps/playground/scripts/link-compiler.sh @@ -8,8 +8,8 @@ set -eo pipefail HERE=$(pwd) -cd ../../packages/react-compiler-runtime && yarn --silent link && cd $HERE -cd ../../packages/babel-plugin-react-compiler && yarn --silent link && cd $HERE +cd ../../packages/react-compiler-runtime && yarn --silent link && cd "$HERE" +cd ../../packages/babel-plugin-react-compiler && yarn --silent link && cd "$HERE" yarn --silent link babel-plugin-react-compiler yarn --silent link react-compiler-runtime From 8e430920841189f5b552b6772db6bea0744db5ec Mon Sep 17 00:00:00 2001 From: Wesley LeMahieu Date: Mon, 2 Jun 2025 17:34:50 -0700 Subject: [PATCH 3/7] normalize stack trace, fixing broken tests when pwd has spaces --- packages/internal-test-utils/consoleMock.js | 29 +++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/internal-test-utils/consoleMock.js b/packages/internal-test-utils/consoleMock.js index 9bb797bac395b..0d38edeef68d5 100644 --- a/packages/internal-test-utils/consoleMock.js +++ b/packages/internal-test-utils/consoleMock.js @@ -156,7 +156,8 @@ function normalizeCodeLocInfo(str) { // at Component (/path/filename.js:123:45) // React format: // in Component (at filename.js:123) - return str.replace(/\n +(?:at|in) ([\S]+)[^\n]*/g, function (m, name) { + return str.replace(/\n +(?:at|in) ([^(\n]+)[^\n]*/g, function (m, name) { + name = name.trim(); if (name.endsWith('.render')) { // Class components will have the `render` method as part of their stack trace. // We strip that out in our normalization to make it look more like component stacks. @@ -167,6 +168,18 @@ function normalizeCodeLocInfo(str) { }); } +function normalizeStackTrace(str) { + if (typeof str !== 'string') { + return str; + } + // Replace only the file path and line/column numbers, keep the rest. + // Matches: " in ComponentName (at /path/to/file.js:123:45)" + return str.replace( + /^\s+in ([^(]+) \(at .*\/([^\/]+):\d+:\d+\)$/gm, + ' in $1 (at **/$2:**:**)', + ); +} + function normalizeComponentStack(entry) { if ( typeof entry[0] === 'string' && @@ -346,7 +359,9 @@ export function createLogAssertion( ); } - const normalizedMessage = normalizeCodeLocInfo(message); + const normalizedMessage = normalizeStackTrace( + normalizeCodeLocInfo(message), + ); receivedLogs.push(normalizedMessage); // Check the number of %s interpolations. @@ -380,9 +395,12 @@ export function createLogAssertion( } // Main logic to check if log is expected, with the component stack. + // Also normalize stack traces in expectedMessage for robust matching + const normalizedExpectedMessage = normalizeStackTrace(expectedMessage); + if ( - normalizedMessage === expectedMessage || - normalizedMessage.includes(expectedMessage) + normalizedMessage === normalizedExpectedMessage || + normalizedMessage.includes(normalizedExpectedMessage) ) { if (isLikelyAComponentStack(normalizedMessage)) { if (expectedWithoutStack === true) { @@ -409,7 +427,8 @@ export function createLogAssertion( const message = Array.isArray(messageOrTuple) ? messageOrTuple[0] : messageOrTuple; - return message.replace('\n', ' '); + // Normalize stack traces for diff output as well + return normalizeStackTrace(message.replace('\n', ' ')); }) .join('\n'), receivedLogs.map(message => message.replace('\n', ' ')).join('\n'), From c469ac91fa402eb4f6771aed3fac665d052a368b Mon Sep 17 00:00:00 2001 From: Wesley LeMahieu Date: Tue, 3 Jun 2025 12:18:20 -0700 Subject: [PATCH 4/7] update test to reflect more accurate stack trace --- packages/react/src/__tests__/ReactTypeScriptClass-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts index 254f686184a20..272d21cf2ccde 100644 --- a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts +++ b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts @@ -528,7 +528,7 @@ describe('ReactTypeScriptClass', function () { ' in ProvideChildContextTypes (at **)', 'StateBasedOnContext uses the legacy contextTypes API which will soon be removed. ' + 'Use React.createContext() with static contextType instead. (https://react.dev/link/legacy-context)\n' + - ' in ProvideChildContextTypes.createElement (at **)', + ' in ProvideChildContextTypes.createElement [as render] (at **)', ]); }); } @@ -721,7 +721,7 @@ describe('ReactTypeScriptClass', function () { ' in ProvideContext (at **)', 'ReadContext uses the legacy contextTypes API which will soon be removed. ' + 'Use React.createContext() with static contextType instead. (https://react.dev/link/legacy-context)\n' + - ' in ProvideContext.createElement (at **)', + ' in ProvideContext.createElement [as render] (at **)', ]); }); } From e85ac587f66db8f01b64a594f809c4007c51e98b Mon Sep 17 00:00:00 2001 From: Wesley LeMahieu Date: Tue, 3 Jun 2025 12:31:42 -0700 Subject: [PATCH 5/7] drop superfluos comments --- packages/internal-test-utils/consoleMock.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/internal-test-utils/consoleMock.js b/packages/internal-test-utils/consoleMock.js index 0d38edeef68d5..80b8b94019aca 100644 --- a/packages/internal-test-utils/consoleMock.js +++ b/packages/internal-test-utils/consoleMock.js @@ -395,7 +395,6 @@ export function createLogAssertion( } // Main logic to check if log is expected, with the component stack. - // Also normalize stack traces in expectedMessage for robust matching const normalizedExpectedMessage = normalizeStackTrace(expectedMessage); if ( @@ -427,7 +426,6 @@ export function createLogAssertion( const message = Array.isArray(messageOrTuple) ? messageOrTuple[0] : messageOrTuple; - // Normalize stack traces for diff output as well return normalizeStackTrace(message.replace('\n', ' ')); }) .join('\n'), From e891ef506d85d4fd3eb95530f2908221a4432c82 Mon Sep 17 00:00:00 2001 From: Wesley LeMahieu Date: Tue, 3 Jun 2025 12:50:24 -0700 Subject: [PATCH 6/7] remove unnecessary change --- packages/internal-test-utils/consoleMock.js | 24 ++++----------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/packages/internal-test-utils/consoleMock.js b/packages/internal-test-utils/consoleMock.js index 80b8b94019aca..f5a0173ee9d3e 100644 --- a/packages/internal-test-utils/consoleMock.js +++ b/packages/internal-test-utils/consoleMock.js @@ -168,18 +168,6 @@ function normalizeCodeLocInfo(str) { }); } -function normalizeStackTrace(str) { - if (typeof str !== 'string') { - return str; - } - // Replace only the file path and line/column numbers, keep the rest. - // Matches: " in ComponentName (at /path/to/file.js:123:45)" - return str.replace( - /^\s+in ([^(]+) \(at .*\/([^\/]+):\d+:\d+\)$/gm, - ' in $1 (at **/$2:**:**)', - ); -} - function normalizeComponentStack(entry) { if ( typeof entry[0] === 'string' && @@ -359,9 +347,7 @@ export function createLogAssertion( ); } - const normalizedMessage = normalizeStackTrace( - normalizeCodeLocInfo(message), - ); + const normalizedMessage = normalizeCodeLocInfo(message); receivedLogs.push(normalizedMessage); // Check the number of %s interpolations. @@ -395,11 +381,9 @@ export function createLogAssertion( } // Main logic to check if log is expected, with the component stack. - const normalizedExpectedMessage = normalizeStackTrace(expectedMessage); - if ( - normalizedMessage === normalizedExpectedMessage || - normalizedMessage.includes(normalizedExpectedMessage) + normalizedMessage === expectedMessage || + normalizedMessage.includes(expectedMessage) ) { if (isLikelyAComponentStack(normalizedMessage)) { if (expectedWithoutStack === true) { @@ -426,7 +410,7 @@ export function createLogAssertion( const message = Array.isArray(messageOrTuple) ? messageOrTuple[0] : messageOrTuple; - return normalizeStackTrace(message.replace('\n', ' ')); + return message.replace('\n', ' '); }) .join('\n'), receivedLogs.map(message => message.replace('\n', ' ')).join('\n'), From 21a6fb523e8d52f208e71ae90b9a2eef945f3c99 Mon Sep 17 00:00:00 2001 From: Wesley LeMahieu Date: Sat, 7 Jun 2025 13:31:38 -0700 Subject: [PATCH 7/7] revise regex and restore tests to original --- packages/internal-test-utils/consoleMock.js | 2 +- packages/react/src/__tests__/ReactTypeScriptClass-test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/internal-test-utils/consoleMock.js b/packages/internal-test-utils/consoleMock.js index f5a0173ee9d3e..ecb97b3a03059 100644 --- a/packages/internal-test-utils/consoleMock.js +++ b/packages/internal-test-utils/consoleMock.js @@ -156,7 +156,7 @@ function normalizeCodeLocInfo(str) { // at Component (/path/filename.js:123:45) // React format: // in Component (at filename.js:123) - return str.replace(/\n +(?:at|in) ([^(\n]+)[^\n]*/g, function (m, name) { + return str.replace(/\n +(?:at|in) ([^(\[\n]+)[^\n]*/g, function (m, name) { name = name.trim(); if (name.endsWith('.render')) { // Class components will have the `render` method as part of their stack trace. diff --git a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts index 272d21cf2ccde..254f686184a20 100644 --- a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts +++ b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts @@ -528,7 +528,7 @@ describe('ReactTypeScriptClass', function () { ' in ProvideChildContextTypes (at **)', 'StateBasedOnContext uses the legacy contextTypes API which will soon be removed. ' + 'Use React.createContext() with static contextType instead. (https://react.dev/link/legacy-context)\n' + - ' in ProvideChildContextTypes.createElement [as render] (at **)', + ' in ProvideChildContextTypes.createElement (at **)', ]); }); } @@ -721,7 +721,7 @@ describe('ReactTypeScriptClass', function () { ' in ProvideContext (at **)', 'ReadContext uses the legacy contextTypes API which will soon be removed. ' + 'Use React.createContext() with static contextType instead. (https://react.dev/link/legacy-context)\n' + - ' in ProvideContext.createElement [as render] (at **)', + ' in ProvideContext.createElement (at **)', ]); }); }