Skip to content

Commit e66ef64

Browse files
authored
[tests] remove withoutStack from assertConsole helpers (#35498)
Stacked on #35497 ----- Now that the assert helpers require a component stack, we don't need the `{withoutStack: true}` option.
1 parent 8c34556 commit e66ef64

43 files changed

Lines changed: 874 additions & 2055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js‎

Lines changed: 12 additions & 643 deletions
Large diffs are not rendered by default.

‎packages/internal-test-utils/consoleMock.js‎

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,11 @@ export function createLogAssertion(
290290
}
291291
}
292292

293-
constwithoutStack=options.withoutStack;
294-
295-
if(consoleMethod==='log'&&withoutStack!==undefined){
296-
throwFormattedError(
297-
`Do not pass withoutStack to assertConsoleLogDev, console.log does not have component stacks.`,
298-
);
299-
}elseif(withoutStack!==undefined&&withoutStack!==true){
300-
throwFormattedError(
301-
`The second argument must be {withoutStack: true}.`+
302-
`\n\nInstead received ${JSON.stringify(options)}.`,
303-
);
304-
}
305-
306293
constobservedLogs=clearObservedErrors();
307294
constreceivedLogs=[];
308295
constmissingExpectedLogs=Array.from(expectedMessages);
309296

310297
constunexpectedLogs=[];
311-
constunexpectedMissingComponentStack=[];
312-
constunexpectedIncludingComponentStack=[];
313298
constunexpectedMissingErrorStack=[];
314299
constunexpectedIncludingErrorStack=[];
315300
constlogsMismatchingFormat=[];
@@ -334,72 +319,12 @@ export function createLogAssertion(
334319
}
335320

336321
letexpectedMessage;
337-
letexpectedWithoutStack;
338322
constexpectedMessageOrArray=expectedMessages[index];
339-
if(
340-
expectedMessageOrArray!=null&&
341-
Array.isArray(expectedMessageOrArray)
342-
){
343-
// Should be in the local form assert([['log', {withoutStack: true}]])
344-
345-
// Some validations for common mistakes.
346-
if(expectedMessageOrArray.length===1){
347-
throwFormattedError(
348-
`Did you forget to remove the array around the log?`+
349-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2, but there's only one item in the array. If this is intentional, remove the extra array.`,
350-
);
351-
}elseif(expectedMessageOrArray.length!==2){
352-
throwFormattedError(
353-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
354-
`Instead received ${expectedMessageOrArray}.`,
355-
);
356-
}elseif(consoleMethod==='log'){
357-
// We don't expect any console.log calls to have a stack.
358-
throwFormattedError(
359-
`Do not pass withoutStack to assertConsoleLogDev logs, console.log does not have component stacks.`,
360-
);
361-
}
362-
363-
// Format is correct, check the values.
364-
constcurrentExpectedMessage=expectedMessageOrArray[0];
365-
constcurrentExpectedOptions=expectedMessageOrArray[1];
366-
if(
367-
typeofcurrentExpectedMessage!=='string'||
368-
typeofcurrentExpectedOptions!=='object'||
369-
currentExpectedOptions.withoutStack!==true
370-
){
371-
throwFormattedError(
372-
`Log entries that are arrays must be of the form [string, {withoutStack: true}]`+
373-
`\n\nInstead received [${typeofcurrentExpectedMessage}, ${JSON.stringify(
374-
currentExpectedOptions,
375-
)}].`,
376-
);
377-
}
378-
379-
expectedMessage=normalizeExpectedMessage(currentExpectedMessage);
380-
expectedWithoutStack=expectedMessageOrArray[1].withoutStack;
381-
}elseif(typeofexpectedMessageOrArray==='string'){
323+
if(typeofexpectedMessageOrArray==='string'){
382324
expectedMessage=normalizeExpectedMessage(expectedMessageOrArray);
383-
// withoutStack: inherit from global option - simplify when withoutStack is removed.
384-
if(consoleMethod==='log'){
385-
expectedWithoutStack=true;
386-
}else{
387-
expectedWithoutStack=withoutStack;
388-
}
389-
}elseif(
390-
typeofexpectedMessageOrArray==='object'&&
391-
expectedMessageOrArray!=null&&
392-
expectedMessageOrArray.withoutStack!=null
393-
){
394-
// Special case for common case of a wrong withoutStack value.
395-
throwFormattedError(
396-
`Did you forget to wrap a log with withoutStack in an array?`+
397-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2.`+
398-
`\n\nInstead received ${JSON.stringify(expectedMessageOrArray)}.`,
399-
);
400325
}elseif(expectedMessageOrArray!=null){
401326
throwFormattedError(
402-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
327+
`The expected message for ${matcherName}() must be a string. `+
403328
`Instead received ${JSON.stringify(expectedMessageOrArray)}.`,
404329
);
405330
}
@@ -499,18 +424,6 @@ export function createLogAssertion(
499424
}
500425

501426
if(matchesExpectedMessage){
502-
// withoutStack: Check for unexpected/missing component stacks.
503-
// These checks can be simplified when withoutStack is removed.
504-
if(isLikelyAComponentStack(normalizedMessage)){
505-
if(expectedWithoutStack===true&&!hasErrorStack){
506-
// Only report unexpected component stack if it's not an error stack
507-
// (error stacks look like component stacks after normalization)
508-
unexpectedIncludingComponentStack.push(normalizedMessage);
509-
}
510-
}elseif(expectedWithoutStack!==true&&!expectsErrorStack){
511-
unexpectedMissingComponentStack.push(normalizedMessage);
512-
}
513-
514427
// Check for unexpected/missing error stacks
515428
if(hasErrorStack&&!expectsErrorStack){
516429
// Error stack is present but \n in <stack> was not in the expected message
@@ -538,12 +451,7 @@ export function createLogAssertion(
538451
functionprintDiff(){
539452
return`${diff(
540453
expectedMessages
541-
.map(messageOrTuple=>{
542-
constmessage=Array.isArray(messageOrTuple)
543-
? messageOrTuple[0]
544-
: messageOrTuple;
545-
returnmessage.replace('\n',' ');
546-
})
454+
.map(message=>message.replace('\n',' '))
547455
.join('\n'),
548456
receivedLogs.map(message=>message.replace('\n',' ')).join('\n'),
549457
{
@@ -582,36 +490,6 @@ export function createLogAssertion(
582490
);
583491
}
584492

585-
// Any logs that include a component stack but shouldn't.
586-
if(unexpectedIncludingComponentStack.length>0){
587-
throwFormattedError(
588-
`${unexpectedIncludingComponentStack
589-
.map(
590-
stack=>
591-
`Unexpected component stack for:\n ${printReceived(stack)}`,
592-
)
593-
.join(
594-
'\n\n',
595-
)}\n\nIf this ${logName()} should include a component stack, remove {withoutStack: true} from this ${logName()}.`+
596-
`\nIf all ${logName()}s should include the component stack, you may need to remove {withoutStack: true} from the ${matcherName} call.`,
597-
);
598-
}
599-
600-
// Any logs that are missing a component stack without withoutStack.
601-
if(unexpectedMissingComponentStack.length>0){
602-
throwFormattedError(
603-
`${unexpectedMissingComponentStack
604-
.map(
605-
stack=>
606-
`Missing component stack for:\n ${printReceived(stack)}`,
607-
)
608-
.join(
609-
'\n\n',
610-
)}\n\nIf this ${logName()} should omit a component stack, pass [log, {withoutStack: true}].`+
611-
`\nIf all ${logName()}s should omit the component stack, add {withoutStack: true} to the ${matcherName} call.`,
612-
);
613-
}
614-
615493
// Any logs that include an error stack trace but \n in <stack> wasn't expected.
616494
if(unexpectedIncludingErrorStack.length>0){
617495
throwFormattedError(

‎packages/react-client/src/__tests__/ReactFlight-test.js‎

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,16 +1514,13 @@ describe('ReactFlight', () => {
15141514
},
15151515
};
15161516
consttransport=ReactNoopFlightServer.render(<inputvalue={obj}/>);
1517-
assertConsoleErrorDev(
1518-
[
1519-
'Only plain objects can be passed to Client Components from Server Components. '+
1520-
'Objects with toJSON methods are not supported. '+
1521-
'Convert it manually to a simple value before passing it to props.\n'+
1522-
' <input value={{toJSON: ...}}>\n'+
1523-
' ^^^^^^^^^^^^^^^',
1524-
],
1525-
{withoutStack: true},
1526-
);
1517+
assertConsoleErrorDev([
1518+
'Only plain objects can be passed to Client Components from Server Components. '+
1519+
'Objects with toJSON methods are not supported. '+
1520+
'Convert it manually to a simple value before passing it to props.\n'+
1521+
' <input value={{toJSON: ...}}>\n'+
1522+
' ^^^^^^^^^^^^^^^',
1523+
]);
15271524

15281525
ReactNoopFlightClient.read(transport);
15291526
assertConsoleErrorDev([
@@ -1545,14 +1542,11 @@ describe('ReactFlight', () => {
15451542
consttransport=ReactNoopFlightServer.render(
15461543
<div>Womp womp: {newMyError('spaghetti')}</div>,
15471544
);
1548-
assertConsoleErrorDev(
1549-
[
1550-
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1551-
' <div>Womp womp: {Error}</div>\n'+
1552-
' ^^^^^^^',
1553-
],
1554-
{withoutStack: true},
1555-
);
1545+
assertConsoleErrorDev([
1546+
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1547+
' <div>Womp womp: {Error}</div>\n'+
1548+
' ^^^^^^^',
1549+
]);
15561550

15571551
ReactNoopFlightClient.read(transport);
15581552
assertConsoleErrorDev([
@@ -1565,15 +1559,12 @@ describe('ReactFlight', () => {
15651559

15661560
it('should warn in DEV if a special object is passed to a host component',()=>{
15671561
consttransport=ReactNoopFlightServer.render(<inputvalue={Math}/>);
1568-
assertConsoleErrorDev(
1569-
[
1570-
'Only plain objects can be passed to Client Components from Server Components. '+
1571-
'Math objects are not supported.\n'+
1572-
' <input value={Math}>\n'+
1573-
' ^^^^^^',
1574-
],
1575-
{withoutStack: true},
1576-
);
1562+
assertConsoleErrorDev([
1563+
'Only plain objects can be passed to Client Components from Server Components. '+
1564+
'Math objects are not supported.\n'+
1565+
' <input value={Math}>\n'+
1566+
' ^^^^^^',
1567+
]);
15771568

15781569
ReactNoopFlightClient.read(transport);
15791570
assertConsoleErrorDev([
@@ -1589,15 +1580,12 @@ describe('ReactFlight', () => {
15891580
consttransport=ReactNoopFlightServer.render(
15901581
<inputvalue={{[Symbol.iterator]: {}}}/>,
15911582
);
1592-
assertConsoleErrorDev(
1593-
[
1594-
'Only plain objects can be passed to Client Components from Server Components. '+
1595-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1596-
' <input value={{}}>\n'+
1597-
' ^^^^',
1598-
],
1599-
{withoutStack: true},
1600-
);
1583+
assertConsoleErrorDev([
1584+
'Only plain objects can be passed to Client Components from Server Components. '+
1585+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1586+
' <input value={{}}>\n'+
1587+
' ^^^^',
1588+
]);
16011589

16021590
ReactNoopFlightClient.read(transport);
16031591
assertConsoleErrorDev([
@@ -1620,16 +1608,13 @@ describe('ReactFlight', () => {
16201608
}
16211609
constClient=clientReference(ClientImpl);
16221610
consttransport=ReactNoopFlightServer.render(<Clientvalue={obj}/>);
1623-
assertConsoleErrorDev(
1624-
[
1625-
'Only plain objects can be passed to Client Components from Server Components. '+
1626-
'Objects with toJSON methods are not supported. '+
1627-
'Convert it manually to a simple value before passing it to props.\n'+
1628-
' <... value={{toJSON: ...}}>\n'+
1629-
' ^^^^^^^^^^^^^^^',
1630-
],
1631-
{withoutStack: true},
1632-
);
1611+
assertConsoleErrorDev([
1612+
'Only plain objects can be passed to Client Components from Server Components. '+
1613+
'Objects with toJSON methods are not supported. '+
1614+
'Convert it manually to a simple value before passing it to props.\n'+
1615+
' <... value={{toJSON: ...}}>\n'+
1616+
' ^^^^^^^^^^^^^^^',
1617+
]);
16331618

16341619
ReactNoopFlightClient.read(transport);
16351620
assertConsoleErrorDev([
@@ -1655,16 +1640,13 @@ describe('ReactFlight', () => {
16551640
consttransport=ReactNoopFlightServer.render(
16561641
<Client>Current date: {obj}</Client>,
16571642
);
1658-
assertConsoleErrorDev(
1659-
[
1660-
'Only plain objects can be passed to Client Components from Server Components. '+
1661-
'Objects with toJSON methods are not supported. '+
1662-
'Convert it manually to a simple value before passing it to props.\n'+
1663-
' <>Current date: {{toJSON: ...}}</>\n'+
1664-
' ^^^^^^^^^^^^^^^',
1665-
],
1666-
{withoutStack: true},
1667-
);
1643+
assertConsoleErrorDev([
1644+
'Only plain objects can be passed to Client Components from Server Components. '+
1645+
'Objects with toJSON methods are not supported. '+
1646+
'Convert it manually to a simple value before passing it to props.\n'+
1647+
' <>Current date: {{toJSON: ...}}</>\n'+
1648+
' ^^^^^^^^^^^^^^^',
1649+
]);
16681650

16691651
ReactNoopFlightClient.read(transport);
16701652
assertConsoleErrorDev([
@@ -1683,15 +1665,12 @@ describe('ReactFlight', () => {
16831665
}
16841666
constClient=clientReference(ClientImpl);
16851667
consttransport=ReactNoopFlightServer.render(<Clientvalue={Math}/>);
1686-
assertConsoleErrorDev(
1687-
[
1688-
'Only plain objects can be passed to Client Components from Server Components. '+
1689-
'Math objects are not supported.\n'+
1690-
' <... value={Math}>\n'+
1691-
' ^^^^^^',
1692-
],
1693-
{withoutStack: true},
1694-
);
1668+
assertConsoleErrorDev([
1669+
'Only plain objects can be passed to Client Components from Server Components. '+
1670+
'Math objects are not supported.\n'+
1671+
' <... value={Math}>\n'+
1672+
' ^^^^^^',
1673+
]);
16951674

16961675
ReactNoopFlightClient.read(transport);
16971676
assertConsoleErrorDev([
@@ -1712,15 +1691,12 @@ describe('ReactFlight', () => {
17121691
consttransport=ReactNoopFlightServer.render(
17131692
<Clientvalue={{[Symbol.iterator]: {}}}/>,
17141693
);
1715-
assertConsoleErrorDev(
1716-
[
1717-
'Only plain objects can be passed to Client Components from Server Components. '+
1718-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1719-
' <... value={{}}>\n'+
1720-
' ^^^^',
1721-
],
1722-
{withoutStack: true},
1723-
);
1694+
assertConsoleErrorDev([
1695+
'Only plain objects can be passed to Client Components from Server Components. '+
1696+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1697+
' <... value={{}}>\n'+
1698+
' ^^^^',
1699+
]);
17241700

17251701
ReactNoopFlightClient.read(transport);
17261702

@@ -1744,13 +1720,10 @@ describe('ReactFlight', () => {
17441720
ReactNoopFlightClient.read(transport);
17451721

17461722
assertConsoleErrorDev([
1747-
[
1748-
'Only plain objects can be passed to Client Components from Server Components. '+
1749-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1750-
' <... value={{}}>\n'+
1751-
' ^^^^',
1752-
{withoutStack: true},
1753-
],
1723+
'Only plain objects can be passed to Client Components from Server Components. '+
1724+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1725+
' <... value={{}}>\n'+
1726+
' ^^^^',
17541727
'Only plain objects can be passed to Client Components from Server Components. '+
17551728
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
17561729
' <... value={{}}>\n'+
@@ -1769,13 +1742,10 @@ describe('ReactFlight', () => {
17691742
);
17701743
ReactNoopFlightClient.read(transport);
17711744
assertConsoleErrorDev([
1772-
[
1773-
'Only plain objects can be passed to Client Components from Server Components. '+
1774-
'Math objects are not supported.\n'+
1775-
' [..., Math, <h1/>]\n'+
1776-
' ^^^^',
1777-
{withoutStack: true},
1778-
],
1745+
'Only plain objects can be passed to Client Components from Server Components. '+
1746+
'Math objects are not supported.\n'+
1747+
' [..., Math, <h1/>]\n'+
1748+
' ^^^^',
17791749
'Only plain objects can be passed to Client Components from Server Components. '+
17801750
'Math objects are not supported.\n'+
17811751
' [..., Math, <h1/>]\n'+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
[tests] remove withoutStack from assertConsole helpers (#35498) · react/react@e66ef64 · GitHub
Skip to content

Commit e66ef64

Browse files
authored
[tests] remove withoutStack from assertConsole helpers (#35498)
Stacked on #35497 ----- Now that the assert helpers require a component stack, we don't need the `{withoutStack: true}` option.
1 parent 8c34556 commit e66ef64

43 files changed

Lines changed: 874 additions & 2055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js‎

Lines changed: 12 additions & 643 deletions
Large diffs are not rendered by default.

‎packages/internal-test-utils/consoleMock.js‎

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,11 @@ export function createLogAssertion(
290290
}
291291
}
292292

293-
constwithoutStack=options.withoutStack;
294-
295-
if(consoleMethod==='log'&&withoutStack!==undefined){
296-
throwFormattedError(
297-
`Do not pass withoutStack to assertConsoleLogDev, console.log does not have component stacks.`,
298-
);
299-
}elseif(withoutStack!==undefined&&withoutStack!==true){
300-
throwFormattedError(
301-
`The second argument must be {withoutStack: true}.`+
302-
`\n\nInstead received ${JSON.stringify(options)}.`,
303-
);
304-
}
305-
306293
constobservedLogs=clearObservedErrors();
307294
constreceivedLogs=[];
308295
constmissingExpectedLogs=Array.from(expectedMessages);
309296

310297
constunexpectedLogs=[];
311-
constunexpectedMissingComponentStack=[];
312-
constunexpectedIncludingComponentStack=[];
313298
constunexpectedMissingErrorStack=[];
314299
constunexpectedIncludingErrorStack=[];
315300
constlogsMismatchingFormat=[];
@@ -334,72 +319,12 @@ export function createLogAssertion(
334319
}
335320

336321
letexpectedMessage;
337-
letexpectedWithoutStack;
338322
constexpectedMessageOrArray=expectedMessages[index];
339-
if(
340-
expectedMessageOrArray!=null&&
341-
Array.isArray(expectedMessageOrArray)
342-
){
343-
// Should be in the local form assert([['log', {withoutStack: true}]])
344-
345-
// Some validations for common mistakes.
346-
if(expectedMessageOrArray.length===1){
347-
throwFormattedError(
348-
`Did you forget to remove the array around the log?`+
349-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2, but there's only one item in the array. If this is intentional, remove the extra array.`,
350-
);
351-
}elseif(expectedMessageOrArray.length!==2){
352-
throwFormattedError(
353-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
354-
`Instead received ${expectedMessageOrArray}.`,
355-
);
356-
}elseif(consoleMethod==='log'){
357-
// We don't expect any console.log calls to have a stack.
358-
throwFormattedError(
359-
`Do not pass withoutStack to assertConsoleLogDev logs, console.log does not have component stacks.`,
360-
);
361-
}
362-
363-
// Format is correct, check the values.
364-
constcurrentExpectedMessage=expectedMessageOrArray[0];
365-
constcurrentExpectedOptions=expectedMessageOrArray[1];
366-
if(
367-
typeofcurrentExpectedMessage!=='string'||
368-
typeofcurrentExpectedOptions!=='object'||
369-
currentExpectedOptions.withoutStack!==true
370-
){
371-
throwFormattedError(
372-
`Log entries that are arrays must be of the form [string, {withoutStack: true}]`+
373-
`\n\nInstead received [${typeofcurrentExpectedMessage}, ${JSON.stringify(
374-
currentExpectedOptions,
375-
)}].`,
376-
);
377-
}
378-
379-
expectedMessage=normalizeExpectedMessage(currentExpectedMessage);
380-
expectedWithoutStack=expectedMessageOrArray[1].withoutStack;
381-
}elseif(typeofexpectedMessageOrArray==='string'){
323+
if(typeofexpectedMessageOrArray==='string'){
382324
expectedMessage=normalizeExpectedMessage(expectedMessageOrArray);
383-
// withoutStack: inherit from global option - simplify when withoutStack is removed.
384-
if(consoleMethod==='log'){
385-
expectedWithoutStack=true;
386-
}else{
387-
expectedWithoutStack=withoutStack;
388-
}
389-
}elseif(
390-
typeofexpectedMessageOrArray==='object'&&
391-
expectedMessageOrArray!=null&&
392-
expectedMessageOrArray.withoutStack!=null
393-
){
394-
// Special case for common case of a wrong withoutStack value.
395-
throwFormattedError(
396-
`Did you forget to wrap a log with withoutStack in an array?`+
397-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2.`+
398-
`\n\nInstead received ${JSON.stringify(expectedMessageOrArray)}.`,
399-
);
400325
}elseif(expectedMessageOrArray!=null){
401326
throwFormattedError(
402-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
327+
`The expected message for ${matcherName}() must be a string. `+
403328
`Instead received ${JSON.stringify(expectedMessageOrArray)}.`,
404329
);
405330
}
@@ -499,18 +424,6 @@ export function createLogAssertion(
499424
}
500425

501426
if(matchesExpectedMessage){
502-
// withoutStack: Check for unexpected/missing component stacks.
503-
// These checks can be simplified when withoutStack is removed.
504-
if(isLikelyAComponentStack(normalizedMessage)){
505-
if(expectedWithoutStack===true&&!hasErrorStack){
506-
// Only report unexpected component stack if it's not an error stack
507-
// (error stacks look like component stacks after normalization)
508-
unexpectedIncludingComponentStack.push(normalizedMessage);
509-
}
510-
}elseif(expectedWithoutStack!==true&&!expectsErrorStack){
511-
unexpectedMissingComponentStack.push(normalizedMessage);
512-
}
513-
514427
// Check for unexpected/missing error stacks
515428
if(hasErrorStack&&!expectsErrorStack){
516429
// Error stack is present but \n in <stack> was not in the expected message
@@ -538,12 +451,7 @@ export function createLogAssertion(
538451
functionprintDiff(){
539452
return`${diff(
540453
expectedMessages
541-
.map(messageOrTuple=>{
542-
constmessage=Array.isArray(messageOrTuple)
543-
? messageOrTuple[0]
544-
: messageOrTuple;
545-
returnmessage.replace('\n',' ');
546-
})
454+
.map(message=>message.replace('\n',' '))
547455
.join('\n'),
548456
receivedLogs.map(message=>message.replace('\n',' ')).join('\n'),
549457
{
@@ -582,36 +490,6 @@ export function createLogAssertion(
582490
);
583491
}
584492

585-
// Any logs that include a component stack but shouldn't.
586-
if(unexpectedIncludingComponentStack.length>0){
587-
throwFormattedError(
588-
`${unexpectedIncludingComponentStack
589-
.map(
590-
stack=>
591-
`Unexpected component stack for:\n ${printReceived(stack)}`,
592-
)
593-
.join(
594-
'\n\n',
595-
)}\n\nIf this ${logName()} should include a component stack, remove {withoutStack: true} from this ${logName()}.`+
596-
`\nIf all ${logName()}s should include the component stack, you may need to remove {withoutStack: true} from the ${matcherName} call.`,
597-
);
598-
}
599-
600-
// Any logs that are missing a component stack without withoutStack.
601-
if(unexpectedMissingComponentStack.length>0){
602-
throwFormattedError(
603-
`${unexpectedMissingComponentStack
604-
.map(
605-
stack=>
606-
`Missing component stack for:\n ${printReceived(stack)}`,
607-
)
608-
.join(
609-
'\n\n',
610-
)}\n\nIf this ${logName()} should omit a component stack, pass [log, {withoutStack: true}].`+
611-
`\nIf all ${logName()}s should omit the component stack, add {withoutStack: true} to the ${matcherName} call.`,
612-
);
613-
}
614-
615493
// Any logs that include an error stack trace but \n in <stack> wasn't expected.
616494
if(unexpectedIncludingErrorStack.length>0){
617495
throwFormattedError(

‎packages/react-client/src/__tests__/ReactFlight-test.js‎

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,16 +1514,13 @@ describe('ReactFlight', () => {
15141514
},
15151515
};
15161516
consttransport=ReactNoopFlightServer.render(<inputvalue={obj}/>);
1517-
assertConsoleErrorDev(
1518-
[
1519-
'Only plain objects can be passed to Client Components from Server Components. '+
1520-
'Objects with toJSON methods are not supported. '+
1521-
'Convert it manually to a simple value before passing it to props.\n'+
1522-
' <input value={{toJSON: ...}}>\n'+
1523-
' ^^^^^^^^^^^^^^^',
1524-
],
1525-
{withoutStack: true},
1526-
);
1517+
assertConsoleErrorDev([
1518+
'Only plain objects can be passed to Client Components from Server Components. '+
1519+
'Objects with toJSON methods are not supported. '+
1520+
'Convert it manually to a simple value before passing it to props.\n'+
1521+
' <input value={{toJSON: ...}}>\n'+
1522+
' ^^^^^^^^^^^^^^^',
1523+
]);
15271524

15281525
ReactNoopFlightClient.read(transport);
15291526
assertConsoleErrorDev([
@@ -1545,14 +1542,11 @@ describe('ReactFlight', () => {
15451542
consttransport=ReactNoopFlightServer.render(
15461543
<div>Womp womp: {newMyError('spaghetti')}</div>,
15471544
);
1548-
assertConsoleErrorDev(
1549-
[
1550-
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1551-
' <div>Womp womp: {Error}</div>\n'+
1552-
' ^^^^^^^',
1553-
],
1554-
{withoutStack: true},
1555-
);
1545+
assertConsoleErrorDev([
1546+
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1547+
' <div>Womp womp: {Error}</div>\n'+
1548+
' ^^^^^^^',
1549+
]);
15561550

15571551
ReactNoopFlightClient.read(transport);
15581552
assertConsoleErrorDev([
@@ -1565,15 +1559,12 @@ describe('ReactFlight', () => {
15651559

15661560
it('should warn in DEV if a special object is passed to a host component',()=>{
15671561
consttransport=ReactNoopFlightServer.render(<inputvalue={Math}/>);
1568-
assertConsoleErrorDev(
1569-
[
1570-
'Only plain objects can be passed to Client Components from Server Components. '+
1571-
'Math objects are not supported.\n'+
1572-
' <input value={Math}>\n'+
1573-
' ^^^^^^',
1574-
],
1575-
{withoutStack: true},
1576-
);
1562+
assertConsoleErrorDev([
1563+
'Only plain objects can be passed to Client Components from Server Components. '+
1564+
'Math objects are not supported.\n'+
1565+
' <input value={Math}>\n'+
1566+
' ^^^^^^',
1567+
]);
15771568

15781569
ReactNoopFlightClient.read(transport);
15791570
assertConsoleErrorDev([
@@ -1589,15 +1580,12 @@ describe('ReactFlight', () => {
15891580
consttransport=ReactNoopFlightServer.render(
15901581
<inputvalue={{[Symbol.iterator]: {}}}/>,
15911582
);
1592-
assertConsoleErrorDev(
1593-
[
1594-
'Only plain objects can be passed to Client Components from Server Components. '+
1595-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1596-
' <input value={{}}>\n'+
1597-
' ^^^^',
1598-
],
1599-
{withoutStack: true},
1600-
);
1583+
assertConsoleErrorDev([
1584+
'Only plain objects can be passed to Client Components from Server Components. '+
1585+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1586+
' <input value={{}}>\n'+
1587+
' ^^^^',
1588+
]);
16011589

16021590
ReactNoopFlightClient.read(transport);
16031591
assertConsoleErrorDev([
@@ -1620,16 +1608,13 @@ describe('ReactFlight', () => {
16201608
}
16211609
constClient=clientReference(ClientImpl);
16221610
consttransport=ReactNoopFlightServer.render(<Clientvalue={obj}/>);
1623-
assertConsoleErrorDev(
1624-
[
1625-
'Only plain objects can be passed to Client Components from Server Components. '+
1626-
'Objects with toJSON methods are not supported. '+
1627-
'Convert it manually to a simple value before passing it to props.\n'+
1628-
' <... value={{toJSON: ...}}>\n'+
1629-
' ^^^^^^^^^^^^^^^',
1630-
],
1631-
{withoutStack: true},
1632-
);
1611+
assertConsoleErrorDev([
1612+
'Only plain objects can be passed to Client Components from Server Components. '+
1613+
'Objects with toJSON methods are not supported. '+
1614+
'Convert it manually to a simple value before passing it to props.\n'+
1615+
' <... value={{toJSON: ...}}>\n'+
1616+
' ^^^^^^^^^^^^^^^',
1617+
]);
16331618

16341619
ReactNoopFlightClient.read(transport);
16351620
assertConsoleErrorDev([
@@ -1655,16 +1640,13 @@ describe('ReactFlight', () => {
16551640
consttransport=ReactNoopFlightServer.render(
16561641
<Client>Current date: {obj}</Client>,
16571642
);
1658-
assertConsoleErrorDev(
1659-
[
1660-
'Only plain objects can be passed to Client Components from Server Components. '+
1661-
'Objects with toJSON methods are not supported. '+
1662-
'Convert it manually to a simple value before passing it to props.\n'+
1663-
' <>Current date: {{toJSON: ...}}</>\n'+
1664-
' ^^^^^^^^^^^^^^^',
1665-
],
1666-
{withoutStack: true},
1667-
);
1643+
assertConsoleErrorDev([
1644+
'Only plain objects can be passed to Client Components from Server Components. '+
1645+
'Objects with toJSON methods are not supported. '+
1646+
'Convert it manually to a simple value before passing it to props.\n'+
1647+
' <>Current date: {{toJSON: ...}}</>\n'+
1648+
' ^^^^^^^^^^^^^^^',
1649+
]);
16681650

16691651
ReactNoopFlightClient.read(transport);
16701652
assertConsoleErrorDev([
@@ -1683,15 +1665,12 @@ describe('ReactFlight', () => {
16831665
}
16841666
constClient=clientReference(ClientImpl);
16851667
consttransport=ReactNoopFlightServer.render(<Clientvalue={Math}/>);
1686-
assertConsoleErrorDev(
1687-
[
1688-
'Only plain objects can be passed to Client Components from Server Components. '+
1689-
'Math objects are not supported.\n'+
1690-
' <... value={Math}>\n'+
1691-
' ^^^^^^',
1692-
],
1693-
{withoutStack: true},
1694-
);
1668+
assertConsoleErrorDev([
1669+
'Only plain objects can be passed to Client Components from Server Components. '+
1670+
'Math objects are not supported.\n'+
1671+
' <... value={Math}>\n'+
1672+
' ^^^^^^',
1673+
]);
16951674

16961675
ReactNoopFlightClient.read(transport);
16971676
assertConsoleErrorDev([
@@ -1712,15 +1691,12 @@ describe('ReactFlight', () => {
17121691
consttransport=ReactNoopFlightServer.render(
17131692
<Clientvalue={{[Symbol.iterator]: {}}}/>,
17141693
);
1715-
assertConsoleErrorDev(
1716-
[
1717-
'Only plain objects can be passed to Client Components from Server Components. '+
1718-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1719-
' <... value={{}}>\n'+
1720-
' ^^^^',
1721-
],
1722-
{withoutStack: true},
1723-
);
1694+
assertConsoleErrorDev([
1695+
'Only plain objects can be passed to Client Components from Server Components. '+
1696+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1697+
' <... value={{}}>\n'+
1698+
' ^^^^',
1699+
]);
17241700

17251701
ReactNoopFlightClient.read(transport);
17261702

@@ -1744,13 +1720,10 @@ describe('ReactFlight', () => {
17441720
ReactNoopFlightClient.read(transport);
17451721

17461722
assertConsoleErrorDev([
1747-
[
1748-
'Only plain objects can be passed to Client Components from Server Components. '+
1749-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1750-
' <... value={{}}>\n'+
1751-
' ^^^^',
1752-
{withoutStack: true},
1753-
],
1723+
'Only plain objects can be passed to Client Components from Server Components. '+
1724+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1725+
' <... value={{}}>\n'+
1726+
' ^^^^',
17541727
'Only plain objects can be passed to Client Components from Server Components. '+
17551728
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
17561729
' <... value={{}}>\n'+
@@ -1769,13 +1742,10 @@ describe('ReactFlight', () => {
17691742
);
17701743
ReactNoopFlightClient.read(transport);
17711744
assertConsoleErrorDev([
1772-
[
1773-
'Only plain objects can be passed to Client Components from Server Components. '+
1774-
'Math objects are not supported.\n'+
1775-
' [..., Math, <h1/>]\n'+
1776-
' ^^^^',
1777-
{withoutStack: true},
1778-
],
1745+
'Only plain objects can be passed to Client Components from Server Components. '+
1746+
'Math objects are not supported.\n'+
1747+
' [..., Math, <h1/>]\n'+
1748+
' ^^^^',
17791749
'Only plain objects can be passed to Client Components from Server Components. '+
17801750
'Math objects are not supported.\n'+
17811751
' [..., Math, <h1/>]\n'+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [tests] remove withoutStack from assertConsole helpers (#35498) · react/react@e66ef64 · GitHub
Skip to content

Commit e66ef64

Browse files
authored
[tests] remove withoutStack from assertConsole helpers (#35498)
Stacked on #35497 ----- Now that the assert helpers require a component stack, we don't need the `{withoutStack: true}` option.
1 parent 8c34556 commit e66ef64

43 files changed

Lines changed: 874 additions & 2055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js‎

Lines changed: 12 additions & 643 deletions
Large diffs are not rendered by default.

‎packages/internal-test-utils/consoleMock.js‎

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,11 @@ export function createLogAssertion(
290290
}
291291
}
292292

293-
constwithoutStack=options.withoutStack;
294-
295-
if(consoleMethod==='log'&&withoutStack!==undefined){
296-
throwFormattedError(
297-
`Do not pass withoutStack to assertConsoleLogDev, console.log does not have component stacks.`,
298-
);
299-
}elseif(withoutStack!==undefined&&withoutStack!==true){
300-
throwFormattedError(
301-
`The second argument must be {withoutStack: true}.`+
302-
`\n\nInstead received ${JSON.stringify(options)}.`,
303-
);
304-
}
305-
306293
constobservedLogs=clearObservedErrors();
307294
constreceivedLogs=[];
308295
constmissingExpectedLogs=Array.from(expectedMessages);
309296

310297
constunexpectedLogs=[];
311-
constunexpectedMissingComponentStack=[];
312-
constunexpectedIncludingComponentStack=[];
313298
constunexpectedMissingErrorStack=[];
314299
constunexpectedIncludingErrorStack=[];
315300
constlogsMismatchingFormat=[];
@@ -334,72 +319,12 @@ export function createLogAssertion(
334319
}
335320

336321
letexpectedMessage;
337-
letexpectedWithoutStack;
338322
constexpectedMessageOrArray=expectedMessages[index];
339-
if(
340-
expectedMessageOrArray!=null&&
341-
Array.isArray(expectedMessageOrArray)
342-
){
343-
// Should be in the local form assert([['log', {withoutStack: true}]])
344-
345-
// Some validations for common mistakes.
346-
if(expectedMessageOrArray.length===1){
347-
throwFormattedError(
348-
`Did you forget to remove the array around the log?`+
349-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2, but there's only one item in the array. If this is intentional, remove the extra array.`,
350-
);
351-
}elseif(expectedMessageOrArray.length!==2){
352-
throwFormattedError(
353-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
354-
`Instead received ${expectedMessageOrArray}.`,
355-
);
356-
}elseif(consoleMethod==='log'){
357-
// We don't expect any console.log calls to have a stack.
358-
throwFormattedError(
359-
`Do not pass withoutStack to assertConsoleLogDev logs, console.log does not have component stacks.`,
360-
);
361-
}
362-
363-
// Format is correct, check the values.
364-
constcurrentExpectedMessage=expectedMessageOrArray[0];
365-
constcurrentExpectedOptions=expectedMessageOrArray[1];
366-
if(
367-
typeofcurrentExpectedMessage!=='string'||
368-
typeofcurrentExpectedOptions!=='object'||
369-
currentExpectedOptions.withoutStack!==true
370-
){
371-
throwFormattedError(
372-
`Log entries that are arrays must be of the form [string, {withoutStack: true}]`+
373-
`\n\nInstead received [${typeofcurrentExpectedMessage}, ${JSON.stringify(
374-
currentExpectedOptions,
375-
)}].`,
376-
);
377-
}
378-
379-
expectedMessage=normalizeExpectedMessage(currentExpectedMessage);
380-
expectedWithoutStack=expectedMessageOrArray[1].withoutStack;
381-
}elseif(typeofexpectedMessageOrArray==='string'){
323+
if(typeofexpectedMessageOrArray==='string'){
382324
expectedMessage=normalizeExpectedMessage(expectedMessageOrArray);
383-
// withoutStack: inherit from global option - simplify when withoutStack is removed.
384-
if(consoleMethod==='log'){
385-
expectedWithoutStack=true;
386-
}else{
387-
expectedWithoutStack=withoutStack;
388-
}
389-
}elseif(
390-
typeofexpectedMessageOrArray==='object'&&
391-
expectedMessageOrArray!=null&&
392-
expectedMessageOrArray.withoutStack!=null
393-
){
394-
// Special case for common case of a wrong withoutStack value.
395-
throwFormattedError(
396-
`Did you forget to wrap a log with withoutStack in an array?`+
397-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2.`+
398-
`\n\nInstead received ${JSON.stringify(expectedMessageOrArray)}.`,
399-
);
400325
}elseif(expectedMessageOrArray!=null){
401326
throwFormattedError(
402-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
327+
`The expected message for ${matcherName}() must be a string. `+
403328
`Instead received ${JSON.stringify(expectedMessageOrArray)}.`,
404329
);
405330
}
@@ -499,18 +424,6 @@ export function createLogAssertion(
499424
}
500425

501426
if(matchesExpectedMessage){
502-
// withoutStack: Check for unexpected/missing component stacks.
503-
// These checks can be simplified when withoutStack is removed.
504-
if(isLikelyAComponentStack(normalizedMessage)){
505-
if(expectedWithoutStack===true&&!hasErrorStack){
506-
// Only report unexpected component stack if it's not an error stack
507-
// (error stacks look like component stacks after normalization)
508-
unexpectedIncludingComponentStack.push(normalizedMessage);
509-
}
510-
}elseif(expectedWithoutStack!==true&&!expectsErrorStack){
511-
unexpectedMissingComponentStack.push(normalizedMessage);
512-
}
513-
514427
// Check for unexpected/missing error stacks
515428
if(hasErrorStack&&!expectsErrorStack){
516429
// Error stack is present but \n in <stack> was not in the expected message
@@ -538,12 +451,7 @@ export function createLogAssertion(
538451
functionprintDiff(){
539452
return`${diff(
540453
expectedMessages
541-
.map(messageOrTuple=>{
542-
constmessage=Array.isArray(messageOrTuple)
543-
? messageOrTuple[0]
544-
: messageOrTuple;
545-
returnmessage.replace('\n',' ');
546-
})
454+
.map(message=>message.replace('\n',' '))
547455
.join('\n'),
548456
receivedLogs.map(message=>message.replace('\n',' ')).join('\n'),
549457
{
@@ -582,36 +490,6 @@ export function createLogAssertion(
582490
);
583491
}
584492

585-
// Any logs that include a component stack but shouldn't.
586-
if(unexpectedIncludingComponentStack.length>0){
587-
throwFormattedError(
588-
`${unexpectedIncludingComponentStack
589-
.map(
590-
stack=>
591-
`Unexpected component stack for:\n ${printReceived(stack)}`,
592-
)
593-
.join(
594-
'\n\n',
595-
)}\n\nIf this ${logName()} should include a component stack, remove {withoutStack: true} from this ${logName()}.`+
596-
`\nIf all ${logName()}s should include the component stack, you may need to remove {withoutStack: true} from the ${matcherName} call.`,
597-
);
598-
}
599-
600-
// Any logs that are missing a component stack without withoutStack.
601-
if(unexpectedMissingComponentStack.length>0){
602-
throwFormattedError(
603-
`${unexpectedMissingComponentStack
604-
.map(
605-
stack=>
606-
`Missing component stack for:\n ${printReceived(stack)}`,
607-
)
608-
.join(
609-
'\n\n',
610-
)}\n\nIf this ${logName()} should omit a component stack, pass [log, {withoutStack: true}].`+
611-
`\nIf all ${logName()}s should omit the component stack, add {withoutStack: true} to the ${matcherName} call.`,
612-
);
613-
}
614-
615493
// Any logs that include an error stack trace but \n in <stack> wasn't expected.
616494
if(unexpectedIncludingErrorStack.length>0){
617495
throwFormattedError(

‎packages/react-client/src/__tests__/ReactFlight-test.js‎

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,16 +1514,13 @@ describe('ReactFlight', () => {
15141514
},
15151515
};
15161516
consttransport=ReactNoopFlightServer.render(<inputvalue={obj}/>);
1517-
assertConsoleErrorDev(
1518-
[
1519-
'Only plain objects can be passed to Client Components from Server Components. '+
1520-
'Objects with toJSON methods are not supported. '+
1521-
'Convert it manually to a simple value before passing it to props.\n'+
1522-
' <input value={{toJSON: ...}}>\n'+
1523-
' ^^^^^^^^^^^^^^^',
1524-
],
1525-
{withoutStack: true},
1526-
);
1517+
assertConsoleErrorDev([
1518+
'Only plain objects can be passed to Client Components from Server Components. '+
1519+
'Objects with toJSON methods are not supported. '+
1520+
'Convert it manually to a simple value before passing it to props.\n'+
1521+
' <input value={{toJSON: ...}}>\n'+
1522+
' ^^^^^^^^^^^^^^^',
1523+
]);
15271524

15281525
ReactNoopFlightClient.read(transport);
15291526
assertConsoleErrorDev([
@@ -1545,14 +1542,11 @@ describe('ReactFlight', () => {
15451542
consttransport=ReactNoopFlightServer.render(
15461543
<div>Womp womp: {newMyError('spaghetti')}</div>,
15471544
);
1548-
assertConsoleErrorDev(
1549-
[
1550-
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1551-
' <div>Womp womp: {Error}</div>\n'+
1552-
' ^^^^^^^',
1553-
],
1554-
{withoutStack: true},
1555-
);
1545+
assertConsoleErrorDev([
1546+
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1547+
' <div>Womp womp: {Error}</div>\n'+
1548+
' ^^^^^^^',
1549+
]);
15561550

15571551
ReactNoopFlightClient.read(transport);
15581552
assertConsoleErrorDev([
@@ -1565,15 +1559,12 @@ describe('ReactFlight', () => {
15651559

15661560
it('should warn in DEV if a special object is passed to a host component',()=>{
15671561
consttransport=ReactNoopFlightServer.render(<inputvalue={Math}/>);
1568-
assertConsoleErrorDev(
1569-
[
1570-
'Only plain objects can be passed to Client Components from Server Components. '+
1571-
'Math objects are not supported.\n'+
1572-
' <input value={Math}>\n'+
1573-
' ^^^^^^',
1574-
],
1575-
{withoutStack: true},
1576-
);
1562+
assertConsoleErrorDev([
1563+
'Only plain objects can be passed to Client Components from Server Components. '+
1564+
'Math objects are not supported.\n'+
1565+
' <input value={Math}>\n'+
1566+
' ^^^^^^',
1567+
]);
15771568

15781569
ReactNoopFlightClient.read(transport);
15791570
assertConsoleErrorDev([
@@ -1589,15 +1580,12 @@ describe('ReactFlight', () => {
15891580
consttransport=ReactNoopFlightServer.render(
15901581
<inputvalue={{[Symbol.iterator]: {}}}/>,
15911582
);
1592-
assertConsoleErrorDev(
1593-
[
1594-
'Only plain objects can be passed to Client Components from Server Components. '+
1595-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1596-
' <input value={{}}>\n'+
1597-
' ^^^^',
1598-
],
1599-
{withoutStack: true},
1600-
);
1583+
assertConsoleErrorDev([
1584+
'Only plain objects can be passed to Client Components from Server Components. '+
1585+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1586+
' <input value={{}}>\n'+
1587+
' ^^^^',
1588+
]);
16011589

16021590
ReactNoopFlightClient.read(transport);
16031591
assertConsoleErrorDev([
@@ -1620,16 +1608,13 @@ describe('ReactFlight', () => {
16201608
}
16211609
constClient=clientReference(ClientImpl);
16221610
consttransport=ReactNoopFlightServer.render(<Clientvalue={obj}/>);
1623-
assertConsoleErrorDev(
1624-
[
1625-
'Only plain objects can be passed to Client Components from Server Components. '+
1626-
'Objects with toJSON methods are not supported. '+
1627-
'Convert it manually to a simple value before passing it to props.\n'+
1628-
' <... value={{toJSON: ...}}>\n'+
1629-
' ^^^^^^^^^^^^^^^',
1630-
],
1631-
{withoutStack: true},
1632-
);
1611+
assertConsoleErrorDev([
1612+
'Only plain objects can be passed to Client Components from Server Components. '+
1613+
'Objects with toJSON methods are not supported. '+
1614+
'Convert it manually to a simple value before passing it to props.\n'+
1615+
' <... value={{toJSON: ...}}>\n'+
1616+
' ^^^^^^^^^^^^^^^',
1617+
]);
16331618

16341619
ReactNoopFlightClient.read(transport);
16351620
assertConsoleErrorDev([
@@ -1655,16 +1640,13 @@ describe('ReactFlight', () => {
16551640
consttransport=ReactNoopFlightServer.render(
16561641
<Client>Current date: {obj}</Client>,
16571642
);
1658-
assertConsoleErrorDev(
1659-
[
1660-
'Only plain objects can be passed to Client Components from Server Components. '+
1661-
'Objects with toJSON methods are not supported. '+
1662-
'Convert it manually to a simple value before passing it to props.\n'+
1663-
' <>Current date: {{toJSON: ...}}</>\n'+
1664-
' ^^^^^^^^^^^^^^^',
1665-
],
1666-
{withoutStack: true},
1667-
);
1643+
assertConsoleErrorDev([
1644+
'Only plain objects can be passed to Client Components from Server Components. '+
1645+
'Objects with toJSON methods are not supported. '+
1646+
'Convert it manually to a simple value before passing it to props.\n'+
1647+
' <>Current date: {{toJSON: ...}}</>\n'+
1648+
' ^^^^^^^^^^^^^^^',
1649+
]);
16681650

16691651
ReactNoopFlightClient.read(transport);
16701652
assertConsoleErrorDev([
@@ -1683,15 +1665,12 @@ describe('ReactFlight', () => {
16831665
}
16841666
constClient=clientReference(ClientImpl);
16851667
consttransport=ReactNoopFlightServer.render(<Clientvalue={Math}/>);
1686-
assertConsoleErrorDev(
1687-
[
1688-
'Only plain objects can be passed to Client Components from Server Components. '+
1689-
'Math objects are not supported.\n'+
1690-
' <... value={Math}>\n'+
1691-
' ^^^^^^',
1692-
],
1693-
{withoutStack: true},
1694-
);
1668+
assertConsoleErrorDev([
1669+
'Only plain objects can be passed to Client Components from Server Components. '+
1670+
'Math objects are not supported.\n'+
1671+
' <... value={Math}>\n'+
1672+
' ^^^^^^',
1673+
]);
16951674

16961675
ReactNoopFlightClient.read(transport);
16971676
assertConsoleErrorDev([
@@ -1712,15 +1691,12 @@ describe('ReactFlight', () => {
17121691
consttransport=ReactNoopFlightServer.render(
17131692
<Clientvalue={{[Symbol.iterator]: {}}}/>,
17141693
);
1715-
assertConsoleErrorDev(
1716-
[
1717-
'Only plain objects can be passed to Client Components from Server Components. '+
1718-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1719-
' <... value={{}}>\n'+
1720-
' ^^^^',
1721-
],
1722-
{withoutStack: true},
1723-
);
1694+
assertConsoleErrorDev([
1695+
'Only plain objects can be passed to Client Components from Server Components. '+
1696+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1697+
' <... value={{}}>\n'+
1698+
' ^^^^',
1699+
]);
17241700

17251701
ReactNoopFlightClient.read(transport);
17261702

@@ -1744,13 +1720,10 @@ describe('ReactFlight', () => {
17441720
ReactNoopFlightClient.read(transport);
17451721

17461722
assertConsoleErrorDev([
1747-
[
1748-
'Only plain objects can be passed to Client Components from Server Components. '+
1749-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1750-
' <... value={{}}>\n'+
1751-
' ^^^^',
1752-
{withoutStack: true},
1753-
],
1723+
'Only plain objects can be passed to Client Components from Server Components. '+
1724+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1725+
' <... value={{}}>\n'+
1726+
' ^^^^',
17541727
'Only plain objects can be passed to Client Components from Server Components. '+
17551728
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
17561729
' <... value={{}}>\n'+
@@ -1769,13 +1742,10 @@ describe('ReactFlight', () => {
17691742
);
17701743
ReactNoopFlightClient.read(transport);
17711744
assertConsoleErrorDev([
1772-
[
1773-
'Only plain objects can be passed to Client Components from Server Components. '+
1774-
'Math objects are not supported.\n'+
1775-
' [..., Math, <h1/>]\n'+
1776-
' ^^^^',
1777-
{withoutStack: true},
1778-
],
1745+
'Only plain objects can be passed to Client Components from Server Components. '+
1746+
'Math objects are not supported.\n'+
1747+
' [..., Math, <h1/>]\n'+
1748+
' ^^^^',
17791749
'Only plain objects can be passed to Client Components from Server Components. '+
17801750
'Math objects are not supported.\n'+
17811751
' [..., Math, <h1/>]\n'+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [tests] remove withoutStack from assertConsole helpers (#35498) · react/react@e66ef64 · GitHub
Skip to content

Commit e66ef64

Browse files
authored
[tests] remove withoutStack from assertConsole helpers (#35498)
Stacked on #35497 ----- Now that the assert helpers require a component stack, we don't need the `{withoutStack: true}` option.
1 parent 8c34556 commit e66ef64

43 files changed

Lines changed: 874 additions & 2055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js‎

Lines changed: 12 additions & 643 deletions
Large diffs are not rendered by default.

‎packages/internal-test-utils/consoleMock.js‎

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,11 @@ export function createLogAssertion(
290290
}
291291
}
292292

293-
constwithoutStack=options.withoutStack;
294-
295-
if(consoleMethod==='log'&&withoutStack!==undefined){
296-
throwFormattedError(
297-
`Do not pass withoutStack to assertConsoleLogDev, console.log does not have component stacks.`,
298-
);
299-
}elseif(withoutStack!==undefined&&withoutStack!==true){
300-
throwFormattedError(
301-
`The second argument must be {withoutStack: true}.`+
302-
`\n\nInstead received ${JSON.stringify(options)}.`,
303-
);
304-
}
305-
306293
constobservedLogs=clearObservedErrors();
307294
constreceivedLogs=[];
308295
constmissingExpectedLogs=Array.from(expectedMessages);
309296

310297
constunexpectedLogs=[];
311-
constunexpectedMissingComponentStack=[];
312-
constunexpectedIncludingComponentStack=[];
313298
constunexpectedMissingErrorStack=[];
314299
constunexpectedIncludingErrorStack=[];
315300
constlogsMismatchingFormat=[];
@@ -334,72 +319,12 @@ export function createLogAssertion(
334319
}
335320

336321
letexpectedMessage;
337-
letexpectedWithoutStack;
338322
constexpectedMessageOrArray=expectedMessages[index];
339-
if(
340-
expectedMessageOrArray!=null&&
341-
Array.isArray(expectedMessageOrArray)
342-
){
343-
// Should be in the local form assert([['log', {withoutStack: true}]])
344-
345-
// Some validations for common mistakes.
346-
if(expectedMessageOrArray.length===1){
347-
throwFormattedError(
348-
`Did you forget to remove the array around the log?`+
349-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2, but there's only one item in the array. If this is intentional, remove the extra array.`,
350-
);
351-
}elseif(expectedMessageOrArray.length!==2){
352-
throwFormattedError(
353-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
354-
`Instead received ${expectedMessageOrArray}.`,
355-
);
356-
}elseif(consoleMethod==='log'){
357-
// We don't expect any console.log calls to have a stack.
358-
throwFormattedError(
359-
`Do not pass withoutStack to assertConsoleLogDev logs, console.log does not have component stacks.`,
360-
);
361-
}
362-
363-
// Format is correct, check the values.
364-
constcurrentExpectedMessage=expectedMessageOrArray[0];
365-
constcurrentExpectedOptions=expectedMessageOrArray[1];
366-
if(
367-
typeofcurrentExpectedMessage!=='string'||
368-
typeofcurrentExpectedOptions!=='object'||
369-
currentExpectedOptions.withoutStack!==true
370-
){
371-
throwFormattedError(
372-
`Log entries that are arrays must be of the form [string, {withoutStack: true}]`+
373-
`\n\nInstead received [${typeofcurrentExpectedMessage}, ${JSON.stringify(
374-
currentExpectedOptions,
375-
)}].`,
376-
);
377-
}
378-
379-
expectedMessage=normalizeExpectedMessage(currentExpectedMessage);
380-
expectedWithoutStack=expectedMessageOrArray[1].withoutStack;
381-
}elseif(typeofexpectedMessageOrArray==='string'){
323+
if(typeofexpectedMessageOrArray==='string'){
382324
expectedMessage=normalizeExpectedMessage(expectedMessageOrArray);
383-
// withoutStack: inherit from global option - simplify when withoutStack is removed.
384-
if(consoleMethod==='log'){
385-
expectedWithoutStack=true;
386-
}else{
387-
expectedWithoutStack=withoutStack;
388-
}
389-
}elseif(
390-
typeofexpectedMessageOrArray==='object'&&
391-
expectedMessageOrArray!=null&&
392-
expectedMessageOrArray.withoutStack!=null
393-
){
394-
// Special case for common case of a wrong withoutStack value.
395-
throwFormattedError(
396-
`Did you forget to wrap a log with withoutStack in an array?`+
397-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2.`+
398-
`\n\nInstead received ${JSON.stringify(expectedMessageOrArray)}.`,
399-
);
400325
}elseif(expectedMessageOrArray!=null){
401326
throwFormattedError(
402-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
327+
`The expected message for ${matcherName}() must be a string. `+
403328
`Instead received ${JSON.stringify(expectedMessageOrArray)}.`,
404329
);
405330
}
@@ -499,18 +424,6 @@ export function createLogAssertion(
499424
}
500425

501426
if(matchesExpectedMessage){
502-
// withoutStack: Check for unexpected/missing component stacks.
503-
// These checks can be simplified when withoutStack is removed.
504-
if(isLikelyAComponentStack(normalizedMessage)){
505-
if(expectedWithoutStack===true&&!hasErrorStack){
506-
// Only report unexpected component stack if it's not an error stack
507-
// (error stacks look like component stacks after normalization)
508-
unexpectedIncludingComponentStack.push(normalizedMessage);
509-
}
510-
}elseif(expectedWithoutStack!==true&&!expectsErrorStack){
511-
unexpectedMissingComponentStack.push(normalizedMessage);
512-
}
513-
514427
// Check for unexpected/missing error stacks
515428
if(hasErrorStack&&!expectsErrorStack){
516429
// Error stack is present but \n in <stack> was not in the expected message
@@ -538,12 +451,7 @@ export function createLogAssertion(
538451
functionprintDiff(){
539452
return`${diff(
540453
expectedMessages
541-
.map(messageOrTuple=>{
542-
constmessage=Array.isArray(messageOrTuple)
543-
? messageOrTuple[0]
544-
: messageOrTuple;
545-
returnmessage.replace('\n',' ');
546-
})
454+
.map(message=>message.replace('\n',' '))
547455
.join('\n'),
548456
receivedLogs.map(message=>message.replace('\n',' ')).join('\n'),
549457
{
@@ -582,36 +490,6 @@ export function createLogAssertion(
582490
);
583491
}
584492

585-
// Any logs that include a component stack but shouldn't.
586-
if(unexpectedIncludingComponentStack.length>0){
587-
throwFormattedError(
588-
`${unexpectedIncludingComponentStack
589-
.map(
590-
stack=>
591-
`Unexpected component stack for:\n ${printReceived(stack)}`,
592-
)
593-
.join(
594-
'\n\n',
595-
)}\n\nIf this ${logName()} should include a component stack, remove {withoutStack: true} from this ${logName()}.`+
596-
`\nIf all ${logName()}s should include the component stack, you may need to remove {withoutStack: true} from the ${matcherName} call.`,
597-
);
598-
}
599-
600-
// Any logs that are missing a component stack without withoutStack.
601-
if(unexpectedMissingComponentStack.length>0){
602-
throwFormattedError(
603-
`${unexpectedMissingComponentStack
604-
.map(
605-
stack=>
606-
`Missing component stack for:\n ${printReceived(stack)}`,
607-
)
608-
.join(
609-
'\n\n',
610-
)}\n\nIf this ${logName()} should omit a component stack, pass [log, {withoutStack: true}].`+
611-
`\nIf all ${logName()}s should omit the component stack, add {withoutStack: true} to the ${matcherName} call.`,
612-
);
613-
}
614-
615493
// Any logs that include an error stack trace but \n in <stack> wasn't expected.
616494
if(unexpectedIncludingErrorStack.length>0){
617495
throwFormattedError(

‎packages/react-client/src/__tests__/ReactFlight-test.js‎

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,16 +1514,13 @@ describe('ReactFlight', () => {
15141514
},
15151515
};
15161516
consttransport=ReactNoopFlightServer.render(<inputvalue={obj}/>);
1517-
assertConsoleErrorDev(
1518-
[
1519-
'Only plain objects can be passed to Client Components from Server Components. '+
1520-
'Objects with toJSON methods are not supported. '+
1521-
'Convert it manually to a simple value before passing it to props.\n'+
1522-
' <input value={{toJSON: ...}}>\n'+
1523-
' ^^^^^^^^^^^^^^^',
1524-
],
1525-
{withoutStack: true},
1526-
);
1517+
assertConsoleErrorDev([
1518+
'Only plain objects can be passed to Client Components from Server Components. '+
1519+
'Objects with toJSON methods are not supported. '+
1520+
'Convert it manually to a simple value before passing it to props.\n'+
1521+
' <input value={{toJSON: ...}}>\n'+
1522+
' ^^^^^^^^^^^^^^^',
1523+
]);
15271524

15281525
ReactNoopFlightClient.read(transport);
15291526
assertConsoleErrorDev([
@@ -1545,14 +1542,11 @@ describe('ReactFlight', () => {
15451542
consttransport=ReactNoopFlightServer.render(
15461543
<div>Womp womp: {newMyError('spaghetti')}</div>,
15471544
);
1548-
assertConsoleErrorDev(
1549-
[
1550-
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1551-
' <div>Womp womp: {Error}</div>\n'+
1552-
' ^^^^^^^',
1553-
],
1554-
{withoutStack: true},
1555-
);
1545+
assertConsoleErrorDev([
1546+
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1547+
' <div>Womp womp: {Error}</div>\n'+
1548+
' ^^^^^^^',
1549+
]);
15561550

15571551
ReactNoopFlightClient.read(transport);
15581552
assertConsoleErrorDev([
@@ -1565,15 +1559,12 @@ describe('ReactFlight', () => {
15651559

15661560
it('should warn in DEV if a special object is passed to a host component',()=>{
15671561
consttransport=ReactNoopFlightServer.render(<inputvalue={Math}/>);
1568-
assertConsoleErrorDev(
1569-
[
1570-
'Only plain objects can be passed to Client Components from Server Components. '+
1571-
'Math objects are not supported.\n'+
1572-
' <input value={Math}>\n'+
1573-
' ^^^^^^',
1574-
],
1575-
{withoutStack: true},
1576-
);
1562+
assertConsoleErrorDev([
1563+
'Only plain objects can be passed to Client Components from Server Components. '+
1564+
'Math objects are not supported.\n'+
1565+
' <input value={Math}>\n'+
1566+
' ^^^^^^',
1567+
]);
15771568

15781569
ReactNoopFlightClient.read(transport);
15791570
assertConsoleErrorDev([
@@ -1589,15 +1580,12 @@ describe('ReactFlight', () => {
15891580
consttransport=ReactNoopFlightServer.render(
15901581
<inputvalue={{[Symbol.iterator]: {}}}/>,
15911582
);
1592-
assertConsoleErrorDev(
1593-
[
1594-
'Only plain objects can be passed to Client Components from Server Components. '+
1595-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1596-
' <input value={{}}>\n'+
1597-
' ^^^^',
1598-
],
1599-
{withoutStack: true},
1600-
);
1583+
assertConsoleErrorDev([
1584+
'Only plain objects can be passed to Client Components from Server Components. '+
1585+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1586+
' <input value={{}}>\n'+
1587+
' ^^^^',
1588+
]);
16011589

16021590
ReactNoopFlightClient.read(transport);
16031591
assertConsoleErrorDev([
@@ -1620,16 +1608,13 @@ describe('ReactFlight', () => {
16201608
}
16211609
constClient=clientReference(ClientImpl);
16221610
consttransport=ReactNoopFlightServer.render(<Clientvalue={obj}/>);
1623-
assertConsoleErrorDev(
1624-
[
1625-
'Only plain objects can be passed to Client Components from Server Components. '+
1626-
'Objects with toJSON methods are not supported. '+
1627-
'Convert it manually to a simple value before passing it to props.\n'+
1628-
' <... value={{toJSON: ...}}>\n'+
1629-
' ^^^^^^^^^^^^^^^',
1630-
],
1631-
{withoutStack: true},
1632-
);
1611+
assertConsoleErrorDev([
1612+
'Only plain objects can be passed to Client Components from Server Components. '+
1613+
'Objects with toJSON methods are not supported. '+
1614+
'Convert it manually to a simple value before passing it to props.\n'+
1615+
' <... value={{toJSON: ...}}>\n'+
1616+
' ^^^^^^^^^^^^^^^',
1617+
]);
16331618

16341619
ReactNoopFlightClient.read(transport);
16351620
assertConsoleErrorDev([
@@ -1655,16 +1640,13 @@ describe('ReactFlight', () => {
16551640
consttransport=ReactNoopFlightServer.render(
16561641
<Client>Current date: {obj}</Client>,
16571642
);
1658-
assertConsoleErrorDev(
1659-
[
1660-
'Only plain objects can be passed to Client Components from Server Components. '+
1661-
'Objects with toJSON methods are not supported. '+
1662-
'Convert it manually to a simple value before passing it to props.\n'+
1663-
' <>Current date: {{toJSON: ...}}</>\n'+
1664-
' ^^^^^^^^^^^^^^^',
1665-
],
1666-
{withoutStack: true},
1667-
);
1643+
assertConsoleErrorDev([
1644+
'Only plain objects can be passed to Client Components from Server Components. '+
1645+
'Objects with toJSON methods are not supported. '+
1646+
'Convert it manually to a simple value before passing it to props.\n'+
1647+
' <>Current date: {{toJSON: ...}}</>\n'+
1648+
' ^^^^^^^^^^^^^^^',
1649+
]);
16681650

16691651
ReactNoopFlightClient.read(transport);
16701652
assertConsoleErrorDev([
@@ -1683,15 +1665,12 @@ describe('ReactFlight', () => {
16831665
}
16841666
constClient=clientReference(ClientImpl);
16851667
consttransport=ReactNoopFlightServer.render(<Clientvalue={Math}/>);
1686-
assertConsoleErrorDev(
1687-
[
1688-
'Only plain objects can be passed to Client Components from Server Components. '+
1689-
'Math objects are not supported.\n'+
1690-
' <... value={Math}>\n'+
1691-
' ^^^^^^',
1692-
],
1693-
{withoutStack: true},
1694-
);
1668+
assertConsoleErrorDev([
1669+
'Only plain objects can be passed to Client Components from Server Components. '+
1670+
'Math objects are not supported.\n'+
1671+
' <... value={Math}>\n'+
1672+
' ^^^^^^',
1673+
]);
16951674

16961675
ReactNoopFlightClient.read(transport);
16971676
assertConsoleErrorDev([
@@ -1712,15 +1691,12 @@ describe('ReactFlight', () => {
17121691
consttransport=ReactNoopFlightServer.render(
17131692
<Clientvalue={{[Symbol.iterator]: {}}}/>,
17141693
);
1715-
assertConsoleErrorDev(
1716-
[
1717-
'Only plain objects can be passed to Client Components from Server Components. '+
1718-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1719-
' <... value={{}}>\n'+
1720-
' ^^^^',
1721-
],
1722-
{withoutStack: true},
1723-
);
1694+
assertConsoleErrorDev([
1695+
'Only plain objects can be passed to Client Components from Server Components. '+
1696+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1697+
' <... value={{}}>\n'+
1698+
' ^^^^',
1699+
]);
17241700

17251701
ReactNoopFlightClient.read(transport);
17261702

@@ -1744,13 +1720,10 @@ describe('ReactFlight', () => {
17441720
ReactNoopFlightClient.read(transport);
17451721

17461722
assertConsoleErrorDev([
1747-
[
1748-
'Only plain objects can be passed to Client Components from Server Components. '+
1749-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1750-
' <... value={{}}>\n'+
1751-
' ^^^^',
1752-
{withoutStack: true},
1753-
],
1723+
'Only plain objects can be passed to Client Components from Server Components. '+
1724+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1725+
' <... value={{}}>\n'+
1726+
' ^^^^',
17541727
'Only plain objects can be passed to Client Components from Server Components. '+
17551728
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
17561729
' <... value={{}}>\n'+
@@ -1769,13 +1742,10 @@ describe('ReactFlight', () => {
17691742
);
17701743
ReactNoopFlightClient.read(transport);
17711744
assertConsoleErrorDev([
1772-
[
1773-
'Only plain objects can be passed to Client Components from Server Components. '+
1774-
'Math objects are not supported.\n'+
1775-
' [..., Math, <h1/>]\n'+
1776-
' ^^^^',
1777-
{withoutStack: true},
1778-
],
1745+
'Only plain objects can be passed to Client Components from Server Components. '+
1746+
'Math objects are not supported.\n'+
1747+
' [..., Math, <h1/>]\n'+
1748+
' ^^^^',
17791749
'Only plain objects can be passed to Client Components from Server Components. '+
17801750
'Math objects are not supported.\n'+
17811751
' [..., Math, <h1/>]\n'+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' [tests] remove withoutStack from assertConsole helpers (#35498) · react/react@e66ef64 · GitHub
Skip to content

Commit e66ef64

Browse files
authored
[tests] remove withoutStack from assertConsole helpers (#35498)
Stacked on #35497 ----- Now that the assert helpers require a component stack, we don't need the `{withoutStack: true}` option.
1 parent 8c34556 commit e66ef64

43 files changed

Lines changed: 874 additions & 2055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js‎

Lines changed: 12 additions & 643 deletions
Large diffs are not rendered by default.

‎packages/internal-test-utils/consoleMock.js‎

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,11 @@ export function createLogAssertion(
290290
}
291291
}
292292

293-
constwithoutStack=options.withoutStack;
294-
295-
if(consoleMethod==='log'&&withoutStack!==undefined){
296-
throwFormattedError(
297-
`Do not pass withoutStack to assertConsoleLogDev, console.log does not have component stacks.`,
298-
);
299-
}elseif(withoutStack!==undefined&&withoutStack!==true){
300-
throwFormattedError(
301-
`The second argument must be {withoutStack: true}.`+
302-
`\n\nInstead received ${JSON.stringify(options)}.`,
303-
);
304-
}
305-
306293
constobservedLogs=clearObservedErrors();
307294
constreceivedLogs=[];
308295
constmissingExpectedLogs=Array.from(expectedMessages);
309296

310297
constunexpectedLogs=[];
311-
constunexpectedMissingComponentStack=[];
312-
constunexpectedIncludingComponentStack=[];
313298
constunexpectedMissingErrorStack=[];
314299
constunexpectedIncludingErrorStack=[];
315300
constlogsMismatchingFormat=[];
@@ -334,72 +319,12 @@ export function createLogAssertion(
334319
}
335320

336321
letexpectedMessage;
337-
letexpectedWithoutStack;
338322
constexpectedMessageOrArray=expectedMessages[index];
339-
if(
340-
expectedMessageOrArray!=null&&
341-
Array.isArray(expectedMessageOrArray)
342-
){
343-
// Should be in the local form assert([['log', {withoutStack: true}]])
344-
345-
// Some validations for common mistakes.
346-
if(expectedMessageOrArray.length===1){
347-
throwFormattedError(
348-
`Did you forget to remove the array around the log?`+
349-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2, but there's only one item in the array. If this is intentional, remove the extra array.`,
350-
);
351-
}elseif(expectedMessageOrArray.length!==2){
352-
throwFormattedError(
353-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
354-
`Instead received ${expectedMessageOrArray}.`,
355-
);
356-
}elseif(consoleMethod==='log'){
357-
// We don't expect any console.log calls to have a stack.
358-
throwFormattedError(
359-
`Do not pass withoutStack to assertConsoleLogDev logs, console.log does not have component stacks.`,
360-
);
361-
}
362-
363-
// Format is correct, check the values.
364-
constcurrentExpectedMessage=expectedMessageOrArray[0];
365-
constcurrentExpectedOptions=expectedMessageOrArray[1];
366-
if(
367-
typeofcurrentExpectedMessage!=='string'||
368-
typeofcurrentExpectedOptions!=='object'||
369-
currentExpectedOptions.withoutStack!==true
370-
){
371-
throwFormattedError(
372-
`Log entries that are arrays must be of the form [string, {withoutStack: true}]`+
373-
`\n\nInstead received [${typeofcurrentExpectedMessage}, ${JSON.stringify(
374-
currentExpectedOptions,
375-
)}].`,
376-
);
377-
}
378-
379-
expectedMessage=normalizeExpectedMessage(currentExpectedMessage);
380-
expectedWithoutStack=expectedMessageOrArray[1].withoutStack;
381-
}elseif(typeofexpectedMessageOrArray==='string'){
323+
if(typeofexpectedMessageOrArray==='string'){
382324
expectedMessage=normalizeExpectedMessage(expectedMessageOrArray);
383-
// withoutStack: inherit from global option - simplify when withoutStack is removed.
384-
if(consoleMethod==='log'){
385-
expectedWithoutStack=true;
386-
}else{
387-
expectedWithoutStack=withoutStack;
388-
}
389-
}elseif(
390-
typeofexpectedMessageOrArray==='object'&&
391-
expectedMessageOrArray!=null&&
392-
expectedMessageOrArray.withoutStack!=null
393-
){
394-
// Special case for common case of a wrong withoutStack value.
395-
throwFormattedError(
396-
`Did you forget to wrap a log with withoutStack in an array?`+
397-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2.`+
398-
`\n\nInstead received ${JSON.stringify(expectedMessageOrArray)}.`,
399-
);
400325
}elseif(expectedMessageOrArray!=null){
401326
throwFormattedError(
402-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
327+
`The expected message for ${matcherName}() must be a string. `+
403328
`Instead received ${JSON.stringify(expectedMessageOrArray)}.`,
404329
);
405330
}
@@ -499,18 +424,6 @@ export function createLogAssertion(
499424
}
500425

501426
if(matchesExpectedMessage){
502-
// withoutStack: Check for unexpected/missing component stacks.
503-
// These checks can be simplified when withoutStack is removed.
504-
if(isLikelyAComponentStack(normalizedMessage)){
505-
if(expectedWithoutStack===true&&!hasErrorStack){
506-
// Only report unexpected component stack if it's not an error stack
507-
// (error stacks look like component stacks after normalization)
508-
unexpectedIncludingComponentStack.push(normalizedMessage);
509-
}
510-
}elseif(expectedWithoutStack!==true&&!expectsErrorStack){
511-
unexpectedMissingComponentStack.push(normalizedMessage);
512-
}
513-
514427
// Check for unexpected/missing error stacks
515428
if(hasErrorStack&&!expectsErrorStack){
516429
// Error stack is present but \n in <stack> was not in the expected message
@@ -538,12 +451,7 @@ export function createLogAssertion(
538451
functionprintDiff(){
539452
return`${diff(
540453
expectedMessages
541-
.map(messageOrTuple=>{
542-
constmessage=Array.isArray(messageOrTuple)
543-
? messageOrTuple[0]
544-
: messageOrTuple;
545-
returnmessage.replace('\n',' ');
546-
})
454+
.map(message=>message.replace('\n',' '))
547455
.join('\n'),
548456
receivedLogs.map(message=>message.replace('\n',' ')).join('\n'),
549457
{
@@ -582,36 +490,6 @@ export function createLogAssertion(
582490
);
583491
}
584492

585-
// Any logs that include a component stack but shouldn't.
586-
if(unexpectedIncludingComponentStack.length>0){
587-
throwFormattedError(
588-
`${unexpectedIncludingComponentStack
589-
.map(
590-
stack=>
591-
`Unexpected component stack for:\n ${printReceived(stack)}`,
592-
)
593-
.join(
594-
'\n\n',
595-
)}\n\nIf this ${logName()} should include a component stack, remove {withoutStack: true} from this ${logName()}.`+
596-
`\nIf all ${logName()}s should include the component stack, you may need to remove {withoutStack: true} from the ${matcherName} call.`,
597-
);
598-
}
599-
600-
// Any logs that are missing a component stack without withoutStack.
601-
if(unexpectedMissingComponentStack.length>0){
602-
throwFormattedError(
603-
`${unexpectedMissingComponentStack
604-
.map(
605-
stack=>
606-
`Missing component stack for:\n ${printReceived(stack)}`,
607-
)
608-
.join(
609-
'\n\n',
610-
)}\n\nIf this ${logName()} should omit a component stack, pass [log, {withoutStack: true}].`+
611-
`\nIf all ${logName()}s should omit the component stack, add {withoutStack: true} to the ${matcherName} call.`,
612-
);
613-
}
614-
615493
// Any logs that include an error stack trace but \n in <stack> wasn't expected.
616494
if(unexpectedIncludingErrorStack.length>0){
617495
throwFormattedError(

‎packages/react-client/src/__tests__/ReactFlight-test.js‎

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,16 +1514,13 @@ describe('ReactFlight', () => {
15141514
},
15151515
};
15161516
consttransport=ReactNoopFlightServer.render(<inputvalue={obj}/>);
1517-
assertConsoleErrorDev(
1518-
[
1519-
'Only plain objects can be passed to Client Components from Server Components. '+
1520-
'Objects with toJSON methods are not supported. '+
1521-
'Convert it manually to a simple value before passing it to props.\n'+
1522-
' <input value={{toJSON: ...}}>\n'+
1523-
' ^^^^^^^^^^^^^^^',
1524-
],
1525-
{withoutStack: true},
1526-
);
1517+
assertConsoleErrorDev([
1518+
'Only plain objects can be passed to Client Components from Server Components. '+
1519+
'Objects with toJSON methods are not supported. '+
1520+
'Convert it manually to a simple value before passing it to props.\n'+
1521+
' <input value={{toJSON: ...}}>\n'+
1522+
' ^^^^^^^^^^^^^^^',
1523+
]);
15271524

15281525
ReactNoopFlightClient.read(transport);
15291526
assertConsoleErrorDev([
@@ -1545,14 +1542,11 @@ describe('ReactFlight', () => {
15451542
consttransport=ReactNoopFlightServer.render(
15461543
<div>Womp womp: {newMyError('spaghetti')}</div>,
15471544
);
1548-
assertConsoleErrorDev(
1549-
[
1550-
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1551-
' <div>Womp womp: {Error}</div>\n'+
1552-
' ^^^^^^^',
1553-
],
1554-
{withoutStack: true},
1555-
);
1545+
assertConsoleErrorDev([
1546+
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1547+
' <div>Womp womp: {Error}</div>\n'+
1548+
' ^^^^^^^',
1549+
]);
15561550

15571551
ReactNoopFlightClient.read(transport);
15581552
assertConsoleErrorDev([
@@ -1565,15 +1559,12 @@ describe('ReactFlight', () => {
15651559

15661560
it('should warn in DEV if a special object is passed to a host component',()=>{
15671561
consttransport=ReactNoopFlightServer.render(<inputvalue={Math}/>);
1568-
assertConsoleErrorDev(
1569-
[
1570-
'Only plain objects can be passed to Client Components from Server Components. '+
1571-
'Math objects are not supported.\n'+
1572-
' <input value={Math}>\n'+
1573-
' ^^^^^^',
1574-
],
1575-
{withoutStack: true},
1576-
);
1562+
assertConsoleErrorDev([
1563+
'Only plain objects can be passed to Client Components from Server Components. '+
1564+
'Math objects are not supported.\n'+
1565+
' <input value={Math}>\n'+
1566+
' ^^^^^^',
1567+
]);
15771568

15781569
ReactNoopFlightClient.read(transport);
15791570
assertConsoleErrorDev([
@@ -1589,15 +1580,12 @@ describe('ReactFlight', () => {
15891580
consttransport=ReactNoopFlightServer.render(
15901581
<inputvalue={{[Symbol.iterator]: {}}}/>,
15911582
);
1592-
assertConsoleErrorDev(
1593-
[
1594-
'Only plain objects can be passed to Client Components from Server Components. '+
1595-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1596-
' <input value={{}}>\n'+
1597-
' ^^^^',
1598-
],
1599-
{withoutStack: true},
1600-
);
1583+
assertConsoleErrorDev([
1584+
'Only plain objects can be passed to Client Components from Server Components. '+
1585+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1586+
' <input value={{}}>\n'+
1587+
' ^^^^',
1588+
]);
16011589

16021590
ReactNoopFlightClient.read(transport);
16031591
assertConsoleErrorDev([
@@ -1620,16 +1608,13 @@ describe('ReactFlight', () => {
16201608
}
16211609
constClient=clientReference(ClientImpl);
16221610
consttransport=ReactNoopFlightServer.render(<Clientvalue={obj}/>);
1623-
assertConsoleErrorDev(
1624-
[
1625-
'Only plain objects can be passed to Client Components from Server Components. '+
1626-
'Objects with toJSON methods are not supported. '+
1627-
'Convert it manually to a simple value before passing it to props.\n'+
1628-
' <... value={{toJSON: ...}}>\n'+
1629-
' ^^^^^^^^^^^^^^^',
1630-
],
1631-
{withoutStack: true},
1632-
);
1611+
assertConsoleErrorDev([
1612+
'Only plain objects can be passed to Client Components from Server Components. '+
1613+
'Objects with toJSON methods are not supported. '+
1614+
'Convert it manually to a simple value before passing it to props.\n'+
1615+
' <... value={{toJSON: ...}}>\n'+
1616+
' ^^^^^^^^^^^^^^^',
1617+
]);
16331618

16341619
ReactNoopFlightClient.read(transport);
16351620
assertConsoleErrorDev([
@@ -1655,16 +1640,13 @@ describe('ReactFlight', () => {
16551640
consttransport=ReactNoopFlightServer.render(
16561641
<Client>Current date: {obj}</Client>,
16571642
);
1658-
assertConsoleErrorDev(
1659-
[
1660-
'Only plain objects can be passed to Client Components from Server Components. '+
1661-
'Objects with toJSON methods are not supported. '+
1662-
'Convert it manually to a simple value before passing it to props.\n'+
1663-
' <>Current date: {{toJSON: ...}}</>\n'+
1664-
' ^^^^^^^^^^^^^^^',
1665-
],
1666-
{withoutStack: true},
1667-
);
1643+
assertConsoleErrorDev([
1644+
'Only plain objects can be passed to Client Components from Server Components. '+
1645+
'Objects with toJSON methods are not supported. '+
1646+
'Convert it manually to a simple value before passing it to props.\n'+
1647+
' <>Current date: {{toJSON: ...}}</>\n'+
1648+
' ^^^^^^^^^^^^^^^',
1649+
]);
16681650

16691651
ReactNoopFlightClient.read(transport);
16701652
assertConsoleErrorDev([
@@ -1683,15 +1665,12 @@ describe('ReactFlight', () => {
16831665
}
16841666
constClient=clientReference(ClientImpl);
16851667
consttransport=ReactNoopFlightServer.render(<Clientvalue={Math}/>);
1686-
assertConsoleErrorDev(
1687-
[
1688-
'Only plain objects can be passed to Client Components from Server Components. '+
1689-
'Math objects are not supported.\n'+
1690-
' <... value={Math}>\n'+
1691-
' ^^^^^^',
1692-
],
1693-
{withoutStack: true},
1694-
);
1668+
assertConsoleErrorDev([
1669+
'Only plain objects can be passed to Client Components from Server Components. '+
1670+
'Math objects are not supported.\n'+
1671+
' <... value={Math}>\n'+
1672+
' ^^^^^^',
1673+
]);
16951674

16961675
ReactNoopFlightClient.read(transport);
16971676
assertConsoleErrorDev([
@@ -1712,15 +1691,12 @@ describe('ReactFlight', () => {
17121691
consttransport=ReactNoopFlightServer.render(
17131692
<Clientvalue={{[Symbol.iterator]: {}}}/>,
17141693
);
1715-
assertConsoleErrorDev(
1716-
[
1717-
'Only plain objects can be passed to Client Components from Server Components. '+
1718-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1719-
' <... value={{}}>\n'+
1720-
' ^^^^',
1721-
],
1722-
{withoutStack: true},
1723-
);
1694+
assertConsoleErrorDev([
1695+
'Only plain objects can be passed to Client Components from Server Components. '+
1696+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1697+
' <... value={{}}>\n'+
1698+
' ^^^^',
1699+
]);
17241700

17251701
ReactNoopFlightClient.read(transport);
17261702

@@ -1744,13 +1720,10 @@ describe('ReactFlight', () => {
17441720
ReactNoopFlightClient.read(transport);
17451721

17461722
assertConsoleErrorDev([
1747-
[
1748-
'Only plain objects can be passed to Client Components from Server Components. '+
1749-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1750-
' <... value={{}}>\n'+
1751-
' ^^^^',
1752-
{withoutStack: true},
1753-
],
1723+
'Only plain objects can be passed to Client Components from Server Components. '+
1724+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1725+
' <... value={{}}>\n'+
1726+
' ^^^^',
17541727
'Only plain objects can be passed to Client Components from Server Components. '+
17551728
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
17561729
' <... value={{}}>\n'+
@@ -1769,13 +1742,10 @@ describe('ReactFlight', () => {
17691742
);
17701743
ReactNoopFlightClient.read(transport);
17711744
assertConsoleErrorDev([
1772-
[
1773-
'Only plain objects can be passed to Client Components from Server Components. '+
1774-
'Math objects are not supported.\n'+
1775-
' [..., Math, <h1/>]\n'+
1776-
' ^^^^',
1777-
{withoutStack: true},
1778-
],
1745+
'Only plain objects can be passed to Client Components from Server Components. '+
1746+
'Math objects are not supported.\n'+
1747+
' [..., Math, <h1/>]\n'+
1748+
' ^^^^',
17791749
'Only plain objects can be passed to Client Components from Server Components. '+
17801750
'Math objects are not supported.\n'+
17811751
' [..., Math, <h1/>]\n'+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [tests] remove withoutStack from assertConsole helpers (#35498) · react/react@e66ef64 · GitHub
Skip to content

Commit e66ef64

Browse files
authored
[tests] remove withoutStack from assertConsole helpers (#35498)
Stacked on #35497 ----- Now that the assert helpers require a component stack, we don't need the `{withoutStack: true}` option.
1 parent 8c34556 commit e66ef64

43 files changed

Lines changed: 874 additions & 2055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js‎

Lines changed: 12 additions & 643 deletions
Large diffs are not rendered by default.

‎packages/internal-test-utils/consoleMock.js‎

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,11 @@ export function createLogAssertion(
290290
}
291291
}
292292

293-
constwithoutStack=options.withoutStack;
294-
295-
if(consoleMethod==='log'&&withoutStack!==undefined){
296-
throwFormattedError(
297-
`Do not pass withoutStack to assertConsoleLogDev, console.log does not have component stacks.`,
298-
);
299-
}elseif(withoutStack!==undefined&&withoutStack!==true){
300-
throwFormattedError(
301-
`The second argument must be {withoutStack: true}.`+
302-
`\n\nInstead received ${JSON.stringify(options)}.`,
303-
);
304-
}
305-
306293
constobservedLogs=clearObservedErrors();
307294
constreceivedLogs=[];
308295
constmissingExpectedLogs=Array.from(expectedMessages);
309296

310297
constunexpectedLogs=[];
311-
constunexpectedMissingComponentStack=[];
312-
constunexpectedIncludingComponentStack=[];
313298
constunexpectedMissingErrorStack=[];
314299
constunexpectedIncludingErrorStack=[];
315300
constlogsMismatchingFormat=[];
@@ -334,72 +319,12 @@ export function createLogAssertion(
334319
}
335320

336321
letexpectedMessage;
337-
letexpectedWithoutStack;
338322
constexpectedMessageOrArray=expectedMessages[index];
339-
if(
340-
expectedMessageOrArray!=null&&
341-
Array.isArray(expectedMessageOrArray)
342-
){
343-
// Should be in the local form assert([['log', {withoutStack: true}]])
344-
345-
// Some validations for common mistakes.
346-
if(expectedMessageOrArray.length===1){
347-
throwFormattedError(
348-
`Did you forget to remove the array around the log?`+
349-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2, but there's only one item in the array. If this is intentional, remove the extra array.`,
350-
);
351-
}elseif(expectedMessageOrArray.length!==2){
352-
throwFormattedError(
353-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
354-
`Instead received ${expectedMessageOrArray}.`,
355-
);
356-
}elseif(consoleMethod==='log'){
357-
// We don't expect any console.log calls to have a stack.
358-
throwFormattedError(
359-
`Do not pass withoutStack to assertConsoleLogDev logs, console.log does not have component stacks.`,
360-
);
361-
}
362-
363-
// Format is correct, check the values.
364-
constcurrentExpectedMessage=expectedMessageOrArray[0];
365-
constcurrentExpectedOptions=expectedMessageOrArray[1];
366-
if(
367-
typeofcurrentExpectedMessage!=='string'||
368-
typeofcurrentExpectedOptions!=='object'||
369-
currentExpectedOptions.withoutStack!==true
370-
){
371-
throwFormattedError(
372-
`Log entries that are arrays must be of the form [string, {withoutStack: true}]`+
373-
`\n\nInstead received [${typeofcurrentExpectedMessage}, ${JSON.stringify(
374-
currentExpectedOptions,
375-
)}].`,
376-
);
377-
}
378-
379-
expectedMessage=normalizeExpectedMessage(currentExpectedMessage);
380-
expectedWithoutStack=expectedMessageOrArray[1].withoutStack;
381-
}elseif(typeofexpectedMessageOrArray==='string'){
323+
if(typeofexpectedMessageOrArray==='string'){
382324
expectedMessage=normalizeExpectedMessage(expectedMessageOrArray);
383-
// withoutStack: inherit from global option - simplify when withoutStack is removed.
384-
if(consoleMethod==='log'){
385-
expectedWithoutStack=true;
386-
}else{
387-
expectedWithoutStack=withoutStack;
388-
}
389-
}elseif(
390-
typeofexpectedMessageOrArray==='object'&&
391-
expectedMessageOrArray!=null&&
392-
expectedMessageOrArray.withoutStack!=null
393-
){
394-
// Special case for common case of a wrong withoutStack value.
395-
throwFormattedError(
396-
`Did you forget to wrap a log with withoutStack in an array?`+
397-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2.`+
398-
`\n\nInstead received ${JSON.stringify(expectedMessageOrArray)}.`,
399-
);
400325
}elseif(expectedMessageOrArray!=null){
401326
throwFormattedError(
402-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
327+
`The expected message for ${matcherName}() must be a string. `+
403328
`Instead received ${JSON.stringify(expectedMessageOrArray)}.`,
404329
);
405330
}
@@ -499,18 +424,6 @@ export function createLogAssertion(
499424
}
500425

501426
if(matchesExpectedMessage){
502-
// withoutStack: Check for unexpected/missing component stacks.
503-
// These checks can be simplified when withoutStack is removed.
504-
if(isLikelyAComponentStack(normalizedMessage)){
505-
if(expectedWithoutStack===true&&!hasErrorStack){
506-
// Only report unexpected component stack if it's not an error stack
507-
// (error stacks look like component stacks after normalization)
508-
unexpectedIncludingComponentStack.push(normalizedMessage);
509-
}
510-
}elseif(expectedWithoutStack!==true&&!expectsErrorStack){
511-
unexpectedMissingComponentStack.push(normalizedMessage);
512-
}
513-
514427
// Check for unexpected/missing error stacks
515428
if(hasErrorStack&&!expectsErrorStack){
516429
// Error stack is present but \n in <stack> was not in the expected message
@@ -538,12 +451,7 @@ export function createLogAssertion(
538451
functionprintDiff(){
539452
return`${diff(
540453
expectedMessages
541-
.map(messageOrTuple=>{
542-
constmessage=Array.isArray(messageOrTuple)
543-
? messageOrTuple[0]
544-
: messageOrTuple;
545-
returnmessage.replace('\n',' ');
546-
})
454+
.map(message=>message.replace('\n',' '))
547455
.join('\n'),
548456
receivedLogs.map(message=>message.replace('\n',' ')).join('\n'),
549457
{
@@ -582,36 +490,6 @@ export function createLogAssertion(
582490
);
583491
}
584492

585-
// Any logs that include a component stack but shouldn't.
586-
if(unexpectedIncludingComponentStack.length>0){
587-
throwFormattedError(
588-
`${unexpectedIncludingComponentStack
589-
.map(
590-
stack=>
591-
`Unexpected component stack for:\n ${printReceived(stack)}`,
592-
)
593-
.join(
594-
'\n\n',
595-
)}\n\nIf this ${logName()} should include a component stack, remove {withoutStack: true} from this ${logName()}.`+
596-
`\nIf all ${logName()}s should include the component stack, you may need to remove {withoutStack: true} from the ${matcherName} call.`,
597-
);
598-
}
599-
600-
// Any logs that are missing a component stack without withoutStack.
601-
if(unexpectedMissingComponentStack.length>0){
602-
throwFormattedError(
603-
`${unexpectedMissingComponentStack
604-
.map(
605-
stack=>
606-
`Missing component stack for:\n ${printReceived(stack)}`,
607-
)
608-
.join(
609-
'\n\n',
610-
)}\n\nIf this ${logName()} should omit a component stack, pass [log, {withoutStack: true}].`+
611-
`\nIf all ${logName()}s should omit the component stack, add {withoutStack: true} to the ${matcherName} call.`,
612-
);
613-
}
614-
615493
// Any logs that include an error stack trace but \n in <stack> wasn't expected.
616494
if(unexpectedIncludingErrorStack.length>0){
617495
throwFormattedError(

‎packages/react-client/src/__tests__/ReactFlight-test.js‎

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,16 +1514,13 @@ describe('ReactFlight', () => {
15141514
},
15151515
};
15161516
consttransport=ReactNoopFlightServer.render(<inputvalue={obj}/>);
1517-
assertConsoleErrorDev(
1518-
[
1519-
'Only plain objects can be passed to Client Components from Server Components. '+
1520-
'Objects with toJSON methods are not supported. '+
1521-
'Convert it manually to a simple value before passing it to props.\n'+
1522-
' <input value={{toJSON: ...}}>\n'+
1523-
' ^^^^^^^^^^^^^^^',
1524-
],
1525-
{withoutStack: true},
1526-
);
1517+
assertConsoleErrorDev([
1518+
'Only plain objects can be passed to Client Components from Server Components. '+
1519+
'Objects with toJSON methods are not supported. '+
1520+
'Convert it manually to a simple value before passing it to props.\n'+
1521+
' <input value={{toJSON: ...}}>\n'+
1522+
' ^^^^^^^^^^^^^^^',
1523+
]);
15271524

15281525
ReactNoopFlightClient.read(transport);
15291526
assertConsoleErrorDev([
@@ -1545,14 +1542,11 @@ describe('ReactFlight', () => {
15451542
consttransport=ReactNoopFlightServer.render(
15461543
<div>Womp womp: {newMyError('spaghetti')}</div>,
15471544
);
1548-
assertConsoleErrorDev(
1549-
[
1550-
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1551-
' <div>Womp womp: {Error}</div>\n'+
1552-
' ^^^^^^^',
1553-
],
1554-
{withoutStack: true},
1555-
);
1545+
assertConsoleErrorDev([
1546+
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1547+
' <div>Womp womp: {Error}</div>\n'+
1548+
' ^^^^^^^',
1549+
]);
15561550

15571551
ReactNoopFlightClient.read(transport);
15581552
assertConsoleErrorDev([
@@ -1565,15 +1559,12 @@ describe('ReactFlight', () => {
15651559

15661560
it('should warn in DEV if a special object is passed to a host component',()=>{
15671561
consttransport=ReactNoopFlightServer.render(<inputvalue={Math}/>);
1568-
assertConsoleErrorDev(
1569-
[
1570-
'Only plain objects can be passed to Client Components from Server Components. '+
1571-
'Math objects are not supported.\n'+
1572-
' <input value={Math}>\n'+
1573-
' ^^^^^^',
1574-
],
1575-
{withoutStack: true},
1576-
);
1562+
assertConsoleErrorDev([
1563+
'Only plain objects can be passed to Client Components from Server Components. '+
1564+
'Math objects are not supported.\n'+
1565+
' <input value={Math}>\n'+
1566+
' ^^^^^^',
1567+
]);
15771568

15781569
ReactNoopFlightClient.read(transport);
15791570
assertConsoleErrorDev([
@@ -1589,15 +1580,12 @@ describe('ReactFlight', () => {
15891580
consttransport=ReactNoopFlightServer.render(
15901581
<inputvalue={{[Symbol.iterator]: {}}}/>,
15911582
);
1592-
assertConsoleErrorDev(
1593-
[
1594-
'Only plain objects can be passed to Client Components from Server Components. '+
1595-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1596-
' <input value={{}}>\n'+
1597-
' ^^^^',
1598-
],
1599-
{withoutStack: true},
1600-
);
1583+
assertConsoleErrorDev([
1584+
'Only plain objects can be passed to Client Components from Server Components. '+
1585+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1586+
' <input value={{}}>\n'+
1587+
' ^^^^',
1588+
]);
16011589

16021590
ReactNoopFlightClient.read(transport);
16031591
assertConsoleErrorDev([
@@ -1620,16 +1608,13 @@ describe('ReactFlight', () => {
16201608
}
16211609
constClient=clientReference(ClientImpl);
16221610
consttransport=ReactNoopFlightServer.render(<Clientvalue={obj}/>);
1623-
assertConsoleErrorDev(
1624-
[
1625-
'Only plain objects can be passed to Client Components from Server Components. '+
1626-
'Objects with toJSON methods are not supported. '+
1627-
'Convert it manually to a simple value before passing it to props.\n'+
1628-
' <... value={{toJSON: ...}}>\n'+
1629-
' ^^^^^^^^^^^^^^^',
1630-
],
1631-
{withoutStack: true},
1632-
);
1611+
assertConsoleErrorDev([
1612+
'Only plain objects can be passed to Client Components from Server Components. '+
1613+
'Objects with toJSON methods are not supported. '+
1614+
'Convert it manually to a simple value before passing it to props.\n'+
1615+
' <... value={{toJSON: ...}}>\n'+
1616+
' ^^^^^^^^^^^^^^^',
1617+
]);
16331618

16341619
ReactNoopFlightClient.read(transport);
16351620
assertConsoleErrorDev([
@@ -1655,16 +1640,13 @@ describe('ReactFlight', () => {
16551640
consttransport=ReactNoopFlightServer.render(
16561641
<Client>Current date: {obj}</Client>,
16571642
);
1658-
assertConsoleErrorDev(
1659-
[
1660-
'Only plain objects can be passed to Client Components from Server Components. '+
1661-
'Objects with toJSON methods are not supported. '+
1662-
'Convert it manually to a simple value before passing it to props.\n'+
1663-
' <>Current date: {{toJSON: ...}}</>\n'+
1664-
' ^^^^^^^^^^^^^^^',
1665-
],
1666-
{withoutStack: true},
1667-
);
1643+
assertConsoleErrorDev([
1644+
'Only plain objects can be passed to Client Components from Server Components. '+
1645+
'Objects with toJSON methods are not supported. '+
1646+
'Convert it manually to a simple value before passing it to props.\n'+
1647+
' <>Current date: {{toJSON: ...}}</>\n'+
1648+
' ^^^^^^^^^^^^^^^',
1649+
]);
16681650

16691651
ReactNoopFlightClient.read(transport);
16701652
assertConsoleErrorDev([
@@ -1683,15 +1665,12 @@ describe('ReactFlight', () => {
16831665
}
16841666
constClient=clientReference(ClientImpl);
16851667
consttransport=ReactNoopFlightServer.render(<Clientvalue={Math}/>);
1686-
assertConsoleErrorDev(
1687-
[
1688-
'Only plain objects can be passed to Client Components from Server Components. '+
1689-
'Math objects are not supported.\n'+
1690-
' <... value={Math}>\n'+
1691-
' ^^^^^^',
1692-
],
1693-
{withoutStack: true},
1694-
);
1668+
assertConsoleErrorDev([
1669+
'Only plain objects can be passed to Client Components from Server Components. '+
1670+
'Math objects are not supported.\n'+
1671+
' <... value={Math}>\n'+
1672+
' ^^^^^^',
1673+
]);
16951674

16961675
ReactNoopFlightClient.read(transport);
16971676
assertConsoleErrorDev([
@@ -1712,15 +1691,12 @@ describe('ReactFlight', () => {
17121691
consttransport=ReactNoopFlightServer.render(
17131692
<Clientvalue={{[Symbol.iterator]: {}}}/>,
17141693
);
1715-
assertConsoleErrorDev(
1716-
[
1717-
'Only plain objects can be passed to Client Components from Server Components. '+
1718-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1719-
' <... value={{}}>\n'+
1720-
' ^^^^',
1721-
],
1722-
{withoutStack: true},
1723-
);
1694+
assertConsoleErrorDev([
1695+
'Only plain objects can be passed to Client Components from Server Components. '+
1696+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1697+
' <... value={{}}>\n'+
1698+
' ^^^^',
1699+
]);
17241700

17251701
ReactNoopFlightClient.read(transport);
17261702

@@ -1744,13 +1720,10 @@ describe('ReactFlight', () => {
17441720
ReactNoopFlightClient.read(transport);
17451721

17461722
assertConsoleErrorDev([
1747-
[
1748-
'Only plain objects can be passed to Client Components from Server Components. '+
1749-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1750-
' <... value={{}}>\n'+
1751-
' ^^^^',
1752-
{withoutStack: true},
1753-
],
1723+
'Only plain objects can be passed to Client Components from Server Components. '+
1724+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1725+
' <... value={{}}>\n'+
1726+
' ^^^^',
17541727
'Only plain objects can be passed to Client Components from Server Components. '+
17551728
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
17561729
' <... value={{}}>\n'+
@@ -1769,13 +1742,10 @@ describe('ReactFlight', () => {
17691742
);
17701743
ReactNoopFlightClient.read(transport);
17711744
assertConsoleErrorDev([
1772-
[
1773-
'Only plain objects can be passed to Client Components from Server Components. '+
1774-
'Math objects are not supported.\n'+
1775-
' [..., Math, <h1/>]\n'+
1776-
' ^^^^',
1777-
{withoutStack: true},
1778-
],
1745+
'Only plain objects can be passed to Client Components from Server Components. '+
1746+
'Math objects are not supported.\n'+
1747+
' [..., Math, <h1/>]\n'+
1748+
' ^^^^',
17791749
'Only plain objects can be passed to Client Components from Server Components. '+
17801750
'Math objects are not supported.\n'+
17811751
' [..., Math, <h1/>]\n'+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [tests] remove withoutStack from assertConsole helpers (#35498) · react/react@e66ef64 · GitHub
Skip to content

Commit e66ef64

Browse files
authored
[tests] remove withoutStack from assertConsole helpers (#35498)
Stacked on #35497 ----- Now that the assert helpers require a component stack, we don't need the `{withoutStack: true}` option.
1 parent 8c34556 commit e66ef64

43 files changed

Lines changed: 874 additions & 2055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js‎

Lines changed: 12 additions & 643 deletions
Large diffs are not rendered by default.

‎packages/internal-test-utils/consoleMock.js‎

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,11 @@ export function createLogAssertion(
290290
}
291291
}
292292

293-
constwithoutStack=options.withoutStack;
294-
295-
if(consoleMethod==='log'&&withoutStack!==undefined){
296-
throwFormattedError(
297-
`Do not pass withoutStack to assertConsoleLogDev, console.log does not have component stacks.`,
298-
);
299-
}elseif(withoutStack!==undefined&&withoutStack!==true){
300-
throwFormattedError(
301-
`The second argument must be {withoutStack: true}.`+
302-
`\n\nInstead received ${JSON.stringify(options)}.`,
303-
);
304-
}
305-
306293
constobservedLogs=clearObservedErrors();
307294
constreceivedLogs=[];
308295
constmissingExpectedLogs=Array.from(expectedMessages);
309296

310297
constunexpectedLogs=[];
311-
constunexpectedMissingComponentStack=[];
312-
constunexpectedIncludingComponentStack=[];
313298
constunexpectedMissingErrorStack=[];
314299
constunexpectedIncludingErrorStack=[];
315300
constlogsMismatchingFormat=[];
@@ -334,72 +319,12 @@ export function createLogAssertion(
334319
}
335320

336321
letexpectedMessage;
337-
letexpectedWithoutStack;
338322
constexpectedMessageOrArray=expectedMessages[index];
339-
if(
340-
expectedMessageOrArray!=null&&
341-
Array.isArray(expectedMessageOrArray)
342-
){
343-
// Should be in the local form assert([['log', {withoutStack: true}]])
344-
345-
// Some validations for common mistakes.
346-
if(expectedMessageOrArray.length===1){
347-
throwFormattedError(
348-
`Did you forget to remove the array around the log?`+
349-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2, but there's only one item in the array. If this is intentional, remove the extra array.`,
350-
);
351-
}elseif(expectedMessageOrArray.length!==2){
352-
throwFormattedError(
353-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
354-
`Instead received ${expectedMessageOrArray}.`,
355-
);
356-
}elseif(consoleMethod==='log'){
357-
// We don't expect any console.log calls to have a stack.
358-
throwFormattedError(
359-
`Do not pass withoutStack to assertConsoleLogDev logs, console.log does not have component stacks.`,
360-
);
361-
}
362-
363-
// Format is correct, check the values.
364-
constcurrentExpectedMessage=expectedMessageOrArray[0];
365-
constcurrentExpectedOptions=expectedMessageOrArray[1];
366-
if(
367-
typeofcurrentExpectedMessage!=='string'||
368-
typeofcurrentExpectedOptions!=='object'||
369-
currentExpectedOptions.withoutStack!==true
370-
){
371-
throwFormattedError(
372-
`Log entries that are arrays must be of the form [string, {withoutStack: true}]`+
373-
`\n\nInstead received [${typeofcurrentExpectedMessage}, ${JSON.stringify(
374-
currentExpectedOptions,
375-
)}].`,
376-
);
377-
}
378-
379-
expectedMessage=normalizeExpectedMessage(currentExpectedMessage);
380-
expectedWithoutStack=expectedMessageOrArray[1].withoutStack;
381-
}elseif(typeofexpectedMessageOrArray==='string'){
323+
if(typeofexpectedMessageOrArray==='string'){
382324
expectedMessage=normalizeExpectedMessage(expectedMessageOrArray);
383-
// withoutStack: inherit from global option - simplify when withoutStack is removed.
384-
if(consoleMethod==='log'){
385-
expectedWithoutStack=true;
386-
}else{
387-
expectedWithoutStack=withoutStack;
388-
}
389-
}elseif(
390-
typeofexpectedMessageOrArray==='object'&&
391-
expectedMessageOrArray!=null&&
392-
expectedMessageOrArray.withoutStack!=null
393-
){
394-
// Special case for common case of a wrong withoutStack value.
395-
throwFormattedError(
396-
`Did you forget to wrap a log with withoutStack in an array?`+
397-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2.`+
398-
`\n\nInstead received ${JSON.stringify(expectedMessageOrArray)}.`,
399-
);
400325
}elseif(expectedMessageOrArray!=null){
401326
throwFormattedError(
402-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
327+
`The expected message for ${matcherName}() must be a string. `+
403328
`Instead received ${JSON.stringify(expectedMessageOrArray)}.`,
404329
);
405330
}
@@ -499,18 +424,6 @@ export function createLogAssertion(
499424
}
500425

501426
if(matchesExpectedMessage){
502-
// withoutStack: Check for unexpected/missing component stacks.
503-
// These checks can be simplified when withoutStack is removed.
504-
if(isLikelyAComponentStack(normalizedMessage)){
505-
if(expectedWithoutStack===true&&!hasErrorStack){
506-
// Only report unexpected component stack if it's not an error stack
507-
// (error stacks look like component stacks after normalization)
508-
unexpectedIncludingComponentStack.push(normalizedMessage);
509-
}
510-
}elseif(expectedWithoutStack!==true&&!expectsErrorStack){
511-
unexpectedMissingComponentStack.push(normalizedMessage);
512-
}
513-
514427
// Check for unexpected/missing error stacks
515428
if(hasErrorStack&&!expectsErrorStack){
516429
// Error stack is present but \n in <stack> was not in the expected message
@@ -538,12 +451,7 @@ export function createLogAssertion(
538451
functionprintDiff(){
539452
return`${diff(
540453
expectedMessages
541-
.map(messageOrTuple=>{
542-
constmessage=Array.isArray(messageOrTuple)
543-
? messageOrTuple[0]
544-
: messageOrTuple;
545-
returnmessage.replace('\n',' ');
546-
})
454+
.map(message=>message.replace('\n',' '))
547455
.join('\n'),
548456
receivedLogs.map(message=>message.replace('\n',' ')).join('\n'),
549457
{
@@ -582,36 +490,6 @@ export function createLogAssertion(
582490
);
583491
}
584492

585-
// Any logs that include a component stack but shouldn't.
586-
if(unexpectedIncludingComponentStack.length>0){
587-
throwFormattedError(
588-
`${unexpectedIncludingComponentStack
589-
.map(
590-
stack=>
591-
`Unexpected component stack for:\n ${printReceived(stack)}`,
592-
)
593-
.join(
594-
'\n\n',
595-
)}\n\nIf this ${logName()} should include a component stack, remove {withoutStack: true} from this ${logName()}.`+
596-
`\nIf all ${logName()}s should include the component stack, you may need to remove {withoutStack: true} from the ${matcherName} call.`,
597-
);
598-
}
599-
600-
// Any logs that are missing a component stack without withoutStack.
601-
if(unexpectedMissingComponentStack.length>0){
602-
throwFormattedError(
603-
`${unexpectedMissingComponentStack
604-
.map(
605-
stack=>
606-
`Missing component stack for:\n ${printReceived(stack)}`,
607-
)
608-
.join(
609-
'\n\n',
610-
)}\n\nIf this ${logName()} should omit a component stack, pass [log, {withoutStack: true}].`+
611-
`\nIf all ${logName()}s should omit the component stack, add {withoutStack: true} to the ${matcherName} call.`,
612-
);
613-
}
614-
615493
// Any logs that include an error stack trace but \n in <stack> wasn't expected.
616494
if(unexpectedIncludingErrorStack.length>0){
617495
throwFormattedError(

‎packages/react-client/src/__tests__/ReactFlight-test.js‎

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,16 +1514,13 @@ describe('ReactFlight', () => {
15141514
},
15151515
};
15161516
consttransport=ReactNoopFlightServer.render(<inputvalue={obj}/>);
1517-
assertConsoleErrorDev(
1518-
[
1519-
'Only plain objects can be passed to Client Components from Server Components. '+
1520-
'Objects with toJSON methods are not supported. '+
1521-
'Convert it manually to a simple value before passing it to props.\n'+
1522-
' <input value={{toJSON: ...}}>\n'+
1523-
' ^^^^^^^^^^^^^^^',
1524-
],
1525-
{withoutStack: true},
1526-
);
1517+
assertConsoleErrorDev([
1518+
'Only plain objects can be passed to Client Components from Server Components. '+
1519+
'Objects with toJSON methods are not supported. '+
1520+
'Convert it manually to a simple value before passing it to props.\n'+
1521+
' <input value={{toJSON: ...}}>\n'+
1522+
' ^^^^^^^^^^^^^^^',
1523+
]);
15271524

15281525
ReactNoopFlightClient.read(transport);
15291526
assertConsoleErrorDev([
@@ -1545,14 +1542,11 @@ describe('ReactFlight', () => {
15451542
consttransport=ReactNoopFlightServer.render(
15461543
<div>Womp womp: {newMyError('spaghetti')}</div>,
15471544
);
1548-
assertConsoleErrorDev(
1549-
[
1550-
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1551-
' <div>Womp womp: {Error}</div>\n'+
1552-
' ^^^^^^^',
1553-
],
1554-
{withoutStack: true},
1555-
);
1545+
assertConsoleErrorDev([
1546+
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1547+
' <div>Womp womp: {Error}</div>\n'+
1548+
' ^^^^^^^',
1549+
]);
15561550

15571551
ReactNoopFlightClient.read(transport);
15581552
assertConsoleErrorDev([
@@ -1565,15 +1559,12 @@ describe('ReactFlight', () => {
15651559

15661560
it('should warn in DEV if a special object is passed to a host component',()=>{
15671561
consttransport=ReactNoopFlightServer.render(<inputvalue={Math}/>);
1568-
assertConsoleErrorDev(
1569-
[
1570-
'Only plain objects can be passed to Client Components from Server Components. '+
1571-
'Math objects are not supported.\n'+
1572-
' <input value={Math}>\n'+
1573-
' ^^^^^^',
1574-
],
1575-
{withoutStack: true},
1576-
);
1562+
assertConsoleErrorDev([
1563+
'Only plain objects can be passed to Client Components from Server Components. '+
1564+
'Math objects are not supported.\n'+
1565+
' <input value={Math}>\n'+
1566+
' ^^^^^^',
1567+
]);
15771568

15781569
ReactNoopFlightClient.read(transport);
15791570
assertConsoleErrorDev([
@@ -1589,15 +1580,12 @@ describe('ReactFlight', () => {
15891580
consttransport=ReactNoopFlightServer.render(
15901581
<inputvalue={{[Symbol.iterator]: {}}}/>,
15911582
);
1592-
assertConsoleErrorDev(
1593-
[
1594-
'Only plain objects can be passed to Client Components from Server Components. '+
1595-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1596-
' <input value={{}}>\n'+
1597-
' ^^^^',
1598-
],
1599-
{withoutStack: true},
1600-
);
1583+
assertConsoleErrorDev([
1584+
'Only plain objects can be passed to Client Components from Server Components. '+
1585+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1586+
' <input value={{}}>\n'+
1587+
' ^^^^',
1588+
]);
16011589

16021590
ReactNoopFlightClient.read(transport);
16031591
assertConsoleErrorDev([
@@ -1620,16 +1608,13 @@ describe('ReactFlight', () => {
16201608
}
16211609
constClient=clientReference(ClientImpl);
16221610
consttransport=ReactNoopFlightServer.render(<Clientvalue={obj}/>);
1623-
assertConsoleErrorDev(
1624-
[
1625-
'Only plain objects can be passed to Client Components from Server Components. '+
1626-
'Objects with toJSON methods are not supported. '+
1627-
'Convert it manually to a simple value before passing it to props.\n'+
1628-
' <... value={{toJSON: ...}}>\n'+
1629-
' ^^^^^^^^^^^^^^^',
1630-
],
1631-
{withoutStack: true},
1632-
);
1611+
assertConsoleErrorDev([
1612+
'Only plain objects can be passed to Client Components from Server Components. '+
1613+
'Objects with toJSON methods are not supported. '+
1614+
'Convert it manually to a simple value before passing it to props.\n'+
1615+
' <... value={{toJSON: ...}}>\n'+
1616+
' ^^^^^^^^^^^^^^^',
1617+
]);
16331618

16341619
ReactNoopFlightClient.read(transport);
16351620
assertConsoleErrorDev([
@@ -1655,16 +1640,13 @@ describe('ReactFlight', () => {
16551640
consttransport=ReactNoopFlightServer.render(
16561641
<Client>Current date: {obj}</Client>,
16571642
);
1658-
assertConsoleErrorDev(
1659-
[
1660-
'Only plain objects can be passed to Client Components from Server Components. '+
1661-
'Objects with toJSON methods are not supported. '+
1662-
'Convert it manually to a simple value before passing it to props.\n'+
1663-
' <>Current date: {{toJSON: ...}}</>\n'+
1664-
' ^^^^^^^^^^^^^^^',
1665-
],
1666-
{withoutStack: true},
1667-
);
1643+
assertConsoleErrorDev([
1644+
'Only plain objects can be passed to Client Components from Server Components. '+
1645+
'Objects with toJSON methods are not supported. '+
1646+
'Convert it manually to a simple value before passing it to props.\n'+
1647+
' <>Current date: {{toJSON: ...}}</>\n'+
1648+
' ^^^^^^^^^^^^^^^',
1649+
]);
16681650

16691651
ReactNoopFlightClient.read(transport);
16701652
assertConsoleErrorDev([
@@ -1683,15 +1665,12 @@ describe('ReactFlight', () => {
16831665
}
16841666
constClient=clientReference(ClientImpl);
16851667
consttransport=ReactNoopFlightServer.render(<Clientvalue={Math}/>);
1686-
assertConsoleErrorDev(
1687-
[
1688-
'Only plain objects can be passed to Client Components from Server Components. '+
1689-
'Math objects are not supported.\n'+
1690-
' <... value={Math}>\n'+
1691-
' ^^^^^^',
1692-
],
1693-
{withoutStack: true},
1694-
);
1668+
assertConsoleErrorDev([
1669+
'Only plain objects can be passed to Client Components from Server Components. '+
1670+
'Math objects are not supported.\n'+
1671+
' <... value={Math}>\n'+
1672+
' ^^^^^^',
1673+
]);
16951674

16961675
ReactNoopFlightClient.read(transport);
16971676
assertConsoleErrorDev([
@@ -1712,15 +1691,12 @@ describe('ReactFlight', () => {
17121691
consttransport=ReactNoopFlightServer.render(
17131692
<Clientvalue={{[Symbol.iterator]: {}}}/>,
17141693
);
1715-
assertConsoleErrorDev(
1716-
[
1717-
'Only plain objects can be passed to Client Components from Server Components. '+
1718-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1719-
' <... value={{}}>\n'+
1720-
' ^^^^',
1721-
],
1722-
{withoutStack: true},
1723-
);
1694+
assertConsoleErrorDev([
1695+
'Only plain objects can be passed to Client Components from Server Components. '+
1696+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1697+
' <... value={{}}>\n'+
1698+
' ^^^^',
1699+
]);
17241700

17251701
ReactNoopFlightClient.read(transport);
17261702

@@ -1744,13 +1720,10 @@ describe('ReactFlight', () => {
17441720
ReactNoopFlightClient.read(transport);
17451721

17461722
assertConsoleErrorDev([
1747-
[
1748-
'Only plain objects can be passed to Client Components from Server Components. '+
1749-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1750-
' <... value={{}}>\n'+
1751-
' ^^^^',
1752-
{withoutStack: true},
1753-
],
1723+
'Only plain objects can be passed to Client Components from Server Components. '+
1724+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1725+
' <... value={{}}>\n'+
1726+
' ^^^^',
17541727
'Only plain objects can be passed to Client Components from Server Components. '+
17551728
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
17561729
' <... value={{}}>\n'+
@@ -1769,13 +1742,10 @@ describe('ReactFlight', () => {
17691742
);
17701743
ReactNoopFlightClient.read(transport);
17711744
assertConsoleErrorDev([
1772-
[
1773-
'Only plain objects can be passed to Client Components from Server Components. '+
1774-
'Math objects are not supported.\n'+
1775-
' [..., Math, <h1/>]\n'+
1776-
' ^^^^',
1777-
{withoutStack: true},
1778-
],
1745+
'Only plain objects can be passed to Client Components from Server Components. '+
1746+
'Math objects are not supported.\n'+
1747+
' [..., Math, <h1/>]\n'+
1748+
' ^^^^',
17791749
'Only plain objects can be passed to Client Components from Server Components. '+
17801750
'Math objects are not supported.\n'+
17811751
' [..., Math, <h1/>]\n'+

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); [tests] remove withoutStack from assertConsole helpers (#35498) · react/react@e66ef64 · GitHub
Skip to content

Commit e66ef64

Browse files
authored
[tests] remove withoutStack from assertConsole helpers (#35498)
Stacked on #35497 ----- Now that the assert helpers require a component stack, we don't need the `{withoutStack: true}` option.
1 parent 8c34556 commit e66ef64

43 files changed

Lines changed: 874 additions & 2055 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js‎

Lines changed: 12 additions & 643 deletions
Large diffs are not rendered by default.

‎packages/internal-test-utils/consoleMock.js‎

Lines changed: 3 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,11 @@ export function createLogAssertion(
290290
}
291291
}
292292

293-
constwithoutStack=options.withoutStack;
294-
295-
if(consoleMethod==='log'&&withoutStack!==undefined){
296-
throwFormattedError(
297-
`Do not pass withoutStack to assertConsoleLogDev, console.log does not have component stacks.`,
298-
);
299-
}elseif(withoutStack!==undefined&&withoutStack!==true){
300-
throwFormattedError(
301-
`The second argument must be {withoutStack: true}.`+
302-
`\n\nInstead received ${JSON.stringify(options)}.`,
303-
);
304-
}
305-
306293
constobservedLogs=clearObservedErrors();
307294
constreceivedLogs=[];
308295
constmissingExpectedLogs=Array.from(expectedMessages);
309296

310297
constunexpectedLogs=[];
311-
constunexpectedMissingComponentStack=[];
312-
constunexpectedIncludingComponentStack=[];
313298
constunexpectedMissingErrorStack=[];
314299
constunexpectedIncludingErrorStack=[];
315300
constlogsMismatchingFormat=[];
@@ -334,72 +319,12 @@ export function createLogAssertion(
334319
}
335320

336321
letexpectedMessage;
337-
letexpectedWithoutStack;
338322
constexpectedMessageOrArray=expectedMessages[index];
339-
if(
340-
expectedMessageOrArray!=null&&
341-
Array.isArray(expectedMessageOrArray)
342-
){
343-
// Should be in the local form assert([['log', {withoutStack: true}]])
344-
345-
// Some validations for common mistakes.
346-
if(expectedMessageOrArray.length===1){
347-
throwFormattedError(
348-
`Did you forget to remove the array around the log?`+
349-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2, but there's only one item in the array. If this is intentional, remove the extra array.`,
350-
);
351-
}elseif(expectedMessageOrArray.length!==2){
352-
throwFormattedError(
353-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
354-
`Instead received ${expectedMessageOrArray}.`,
355-
);
356-
}elseif(consoleMethod==='log'){
357-
// We don't expect any console.log calls to have a stack.
358-
throwFormattedError(
359-
`Do not pass withoutStack to assertConsoleLogDev logs, console.log does not have component stacks.`,
360-
);
361-
}
362-
363-
// Format is correct, check the values.
364-
constcurrentExpectedMessage=expectedMessageOrArray[0];
365-
constcurrentExpectedOptions=expectedMessageOrArray[1];
366-
if(
367-
typeofcurrentExpectedMessage!=='string'||
368-
typeofcurrentExpectedOptions!=='object'||
369-
currentExpectedOptions.withoutStack!==true
370-
){
371-
throwFormattedError(
372-
`Log entries that are arrays must be of the form [string, {withoutStack: true}]`+
373-
`\n\nInstead received [${typeofcurrentExpectedMessage}, ${JSON.stringify(
374-
currentExpectedOptions,
375-
)}].`,
376-
);
377-
}
378-
379-
expectedMessage=normalizeExpectedMessage(currentExpectedMessage);
380-
expectedWithoutStack=expectedMessageOrArray[1].withoutStack;
381-
}elseif(typeofexpectedMessageOrArray==='string'){
323+
if(typeofexpectedMessageOrArray==='string'){
382324
expectedMessage=normalizeExpectedMessage(expectedMessageOrArray);
383-
// withoutStack: inherit from global option - simplify when withoutStack is removed.
384-
if(consoleMethod==='log'){
385-
expectedWithoutStack=true;
386-
}else{
387-
expectedWithoutStack=withoutStack;
388-
}
389-
}elseif(
390-
typeofexpectedMessageOrArray==='object'&&
391-
expectedMessageOrArray!=null&&
392-
expectedMessageOrArray.withoutStack!=null
393-
){
394-
// Special case for common case of a wrong withoutStack value.
395-
throwFormattedError(
396-
`Did you forget to wrap a log with withoutStack in an array?`+
397-
`\n\nThe expected message for ${matcherName}() must be a string or an array of length 2.`+
398-
`\n\nInstead received ${JSON.stringify(expectedMessageOrArray)}.`,
399-
);
400325
}elseif(expectedMessageOrArray!=null){
401326
throwFormattedError(
402-
`The expected message for ${matcherName}() must be a string or an array of length 2. `+
327+
`The expected message for ${matcherName}() must be a string. `+
403328
`Instead received ${JSON.stringify(expectedMessageOrArray)}.`,
404329
);
405330
}
@@ -499,18 +424,6 @@ export function createLogAssertion(
499424
}
500425

501426
if(matchesExpectedMessage){
502-
// withoutStack: Check for unexpected/missing component stacks.
503-
// These checks can be simplified when withoutStack is removed.
504-
if(isLikelyAComponentStack(normalizedMessage)){
505-
if(expectedWithoutStack===true&&!hasErrorStack){
506-
// Only report unexpected component stack if it's not an error stack
507-
// (error stacks look like component stacks after normalization)
508-
unexpectedIncludingComponentStack.push(normalizedMessage);
509-
}
510-
}elseif(expectedWithoutStack!==true&&!expectsErrorStack){
511-
unexpectedMissingComponentStack.push(normalizedMessage);
512-
}
513-
514427
// Check for unexpected/missing error stacks
515428
if(hasErrorStack&&!expectsErrorStack){
516429
// Error stack is present but \n in <stack> was not in the expected message
@@ -538,12 +451,7 @@ export function createLogAssertion(
538451
functionprintDiff(){
539452
return`${diff(
540453
expectedMessages
541-
.map(messageOrTuple=>{
542-
constmessage=Array.isArray(messageOrTuple)
543-
? messageOrTuple[0]
544-
: messageOrTuple;
545-
returnmessage.replace('\n',' ');
546-
})
454+
.map(message=>message.replace('\n',' '))
547455
.join('\n'),
548456
receivedLogs.map(message=>message.replace('\n',' ')).join('\n'),
549457
{
@@ -582,36 +490,6 @@ export function createLogAssertion(
582490
);
583491
}
584492

585-
// Any logs that include a component stack but shouldn't.
586-
if(unexpectedIncludingComponentStack.length>0){
587-
throwFormattedError(
588-
`${unexpectedIncludingComponentStack
589-
.map(
590-
stack=>
591-
`Unexpected component stack for:\n ${printReceived(stack)}`,
592-
)
593-
.join(
594-
'\n\n',
595-
)}\n\nIf this ${logName()} should include a component stack, remove {withoutStack: true} from this ${logName()}.`+
596-
`\nIf all ${logName()}s should include the component stack, you may need to remove {withoutStack: true} from the ${matcherName} call.`,
597-
);
598-
}
599-
600-
// Any logs that are missing a component stack without withoutStack.
601-
if(unexpectedMissingComponentStack.length>0){
602-
throwFormattedError(
603-
`${unexpectedMissingComponentStack
604-
.map(
605-
stack=>
606-
`Missing component stack for:\n ${printReceived(stack)}`,
607-
)
608-
.join(
609-
'\n\n',
610-
)}\n\nIf this ${logName()} should omit a component stack, pass [log, {withoutStack: true}].`+
611-
`\nIf all ${logName()}s should omit the component stack, add {withoutStack: true} to the ${matcherName} call.`,
612-
);
613-
}
614-
615493
// Any logs that include an error stack trace but \n in <stack> wasn't expected.
616494
if(unexpectedIncludingErrorStack.length>0){
617495
throwFormattedError(

‎packages/react-client/src/__tests__/ReactFlight-test.js‎

Lines changed: 58 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,16 +1514,13 @@ describe('ReactFlight', () => {
15141514
},
15151515
};
15161516
consttransport=ReactNoopFlightServer.render(<inputvalue={obj}/>);
1517-
assertConsoleErrorDev(
1518-
[
1519-
'Only plain objects can be passed to Client Components from Server Components. '+
1520-
'Objects with toJSON methods are not supported. '+
1521-
'Convert it manually to a simple value before passing it to props.\n'+
1522-
' <input value={{toJSON: ...}}>\n'+
1523-
' ^^^^^^^^^^^^^^^',
1524-
],
1525-
{withoutStack: true},
1526-
);
1517+
assertConsoleErrorDev([
1518+
'Only plain objects can be passed to Client Components from Server Components. '+
1519+
'Objects with toJSON methods are not supported. '+
1520+
'Convert it manually to a simple value before passing it to props.\n'+
1521+
' <input value={{toJSON: ...}}>\n'+
1522+
' ^^^^^^^^^^^^^^^',
1523+
]);
15271524

15281525
ReactNoopFlightClient.read(transport);
15291526
assertConsoleErrorDev([
@@ -1545,14 +1542,11 @@ describe('ReactFlight', () => {
15451542
consttransport=ReactNoopFlightServer.render(
15461543
<div>Womp womp: {newMyError('spaghetti')}</div>,
15471544
);
1548-
assertConsoleErrorDev(
1549-
[
1550-
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1551-
' <div>Womp womp: {Error}</div>\n'+
1552-
' ^^^^^^^',
1553-
],
1554-
{withoutStack: true},
1555-
);
1545+
assertConsoleErrorDev([
1546+
'Error objects cannot be rendered as text children. Try formatting it using toString().\n'+
1547+
' <div>Womp womp: {Error}</div>\n'+
1548+
' ^^^^^^^',
1549+
]);
15561550

15571551
ReactNoopFlightClient.read(transport);
15581552
assertConsoleErrorDev([
@@ -1565,15 +1559,12 @@ describe('ReactFlight', () => {
15651559

15661560
it('should warn in DEV if a special object is passed to a host component',()=>{
15671561
consttransport=ReactNoopFlightServer.render(<inputvalue={Math}/>);
1568-
assertConsoleErrorDev(
1569-
[
1570-
'Only plain objects can be passed to Client Components from Server Components. '+
1571-
'Math objects are not supported.\n'+
1572-
' <input value={Math}>\n'+
1573-
' ^^^^^^',
1574-
],
1575-
{withoutStack: true},
1576-
);
1562+
assertConsoleErrorDev([
1563+
'Only plain objects can be passed to Client Components from Server Components. '+
1564+
'Math objects are not supported.\n'+
1565+
' <input value={Math}>\n'+
1566+
' ^^^^^^',
1567+
]);
15771568

15781569
ReactNoopFlightClient.read(transport);
15791570
assertConsoleErrorDev([
@@ -1589,15 +1580,12 @@ describe('ReactFlight', () => {
15891580
consttransport=ReactNoopFlightServer.render(
15901581
<inputvalue={{[Symbol.iterator]: {}}}/>,
15911582
);
1592-
assertConsoleErrorDev(
1593-
[
1594-
'Only plain objects can be passed to Client Components from Server Components. '+
1595-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1596-
' <input value={{}}>\n'+
1597-
' ^^^^',
1598-
],
1599-
{withoutStack: true},
1600-
);
1583+
assertConsoleErrorDev([
1584+
'Only plain objects can be passed to Client Components from Server Components. '+
1585+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1586+
' <input value={{}}>\n'+
1587+
' ^^^^',
1588+
]);
16011589

16021590
ReactNoopFlightClient.read(transport);
16031591
assertConsoleErrorDev([
@@ -1620,16 +1608,13 @@ describe('ReactFlight', () => {
16201608
}
16211609
constClient=clientReference(ClientImpl);
16221610
consttransport=ReactNoopFlightServer.render(<Clientvalue={obj}/>);
1623-
assertConsoleErrorDev(
1624-
[
1625-
'Only plain objects can be passed to Client Components from Server Components. '+
1626-
'Objects with toJSON methods are not supported. '+
1627-
'Convert it manually to a simple value before passing it to props.\n'+
1628-
' <... value={{toJSON: ...}}>\n'+
1629-
' ^^^^^^^^^^^^^^^',
1630-
],
1631-
{withoutStack: true},
1632-
);
1611+
assertConsoleErrorDev([
1612+
'Only plain objects can be passed to Client Components from Server Components. '+
1613+
'Objects with toJSON methods are not supported. '+
1614+
'Convert it manually to a simple value before passing it to props.\n'+
1615+
' <... value={{toJSON: ...}}>\n'+
1616+
' ^^^^^^^^^^^^^^^',
1617+
]);
16331618

16341619
ReactNoopFlightClient.read(transport);
16351620
assertConsoleErrorDev([
@@ -1655,16 +1640,13 @@ describe('ReactFlight', () => {
16551640
consttransport=ReactNoopFlightServer.render(
16561641
<Client>Current date: {obj}</Client>,
16571642
);
1658-
assertConsoleErrorDev(
1659-
[
1660-
'Only plain objects can be passed to Client Components from Server Components. '+
1661-
'Objects with toJSON methods are not supported. '+
1662-
'Convert it manually to a simple value before passing it to props.\n'+
1663-
' <>Current date: {{toJSON: ...}}</>\n'+
1664-
' ^^^^^^^^^^^^^^^',
1665-
],
1666-
{withoutStack: true},
1667-
);
1643+
assertConsoleErrorDev([
1644+
'Only plain objects can be passed to Client Components from Server Components. '+
1645+
'Objects with toJSON methods are not supported. '+
1646+
'Convert it manually to a simple value before passing it to props.\n'+
1647+
' <>Current date: {{toJSON: ...}}</>\n'+
1648+
' ^^^^^^^^^^^^^^^',
1649+
]);
16681650

16691651
ReactNoopFlightClient.read(transport);
16701652
assertConsoleErrorDev([
@@ -1683,15 +1665,12 @@ describe('ReactFlight', () => {
16831665
}
16841666
constClient=clientReference(ClientImpl);
16851667
consttransport=ReactNoopFlightServer.render(<Clientvalue={Math}/>);
1686-
assertConsoleErrorDev(
1687-
[
1688-
'Only plain objects can be passed to Client Components from Server Components. '+
1689-
'Math objects are not supported.\n'+
1690-
' <... value={Math}>\n'+
1691-
' ^^^^^^',
1692-
],
1693-
{withoutStack: true},
1694-
);
1668+
assertConsoleErrorDev([
1669+
'Only plain objects can be passed to Client Components from Server Components. '+
1670+
'Math objects are not supported.\n'+
1671+
' <... value={Math}>\n'+
1672+
' ^^^^^^',
1673+
]);
16951674

16961675
ReactNoopFlightClient.read(transport);
16971676
assertConsoleErrorDev([
@@ -1712,15 +1691,12 @@ describe('ReactFlight', () => {
17121691
consttransport=ReactNoopFlightServer.render(
17131692
<Clientvalue={{[Symbol.iterator]: {}}}/>,
17141693
);
1715-
assertConsoleErrorDev(
1716-
[
1717-
'Only plain objects can be passed to Client Components from Server Components. '+
1718-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1719-
' <... value={{}}>\n'+
1720-
' ^^^^',
1721-
],
1722-
{withoutStack: true},
1723-
);
1694+
assertConsoleErrorDev([
1695+
'Only plain objects can be passed to Client Components from Server Components. '+
1696+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1697+
' <... value={{}}>\n'+
1698+
' ^^^^',
1699+
]);
17241700

17251701
ReactNoopFlightClient.read(transport);
17261702

@@ -1744,13 +1720,10 @@ describe('ReactFlight', () => {
17441720
ReactNoopFlightClient.read(transport);
17451721

17461722
assertConsoleErrorDev([
1747-
[
1748-
'Only plain objects can be passed to Client Components from Server Components. '+
1749-
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1750-
' <... value={{}}>\n'+
1751-
' ^^^^',
1752-
{withoutStack: true},
1753-
],
1723+
'Only plain objects can be passed to Client Components from Server Components. '+
1724+
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
1725+
' <... value={{}}>\n'+
1726+
' ^^^^',
17541727
'Only plain objects can be passed to Client Components from Server Components. '+
17551728
'Objects with symbol properties like Symbol.iterator are not supported.\n'+
17561729
' <... value={{}}>\n'+
@@ -1769,13 +1742,10 @@ describe('ReactFlight', () => {
17691742
);
17701743
ReactNoopFlightClient.read(transport);
17711744
assertConsoleErrorDev([
1772-
[
1773-
'Only plain objects can be passed to Client Components from Server Components. '+
1774-
'Math objects are not supported.\n'+
1775-
' [..., Math, <h1/>]\n'+
1776-
' ^^^^',
1777-
{withoutStack: true},
1778-
],
1745+
'Only plain objects can be passed to Client Components from Server Components. '+
1746+
'Math objects are not supported.\n'+
1747+
' [..., Math, <h1/>]\n'+
1748+
' ^^^^',
17791749
'Only plain objects can be passed to Client Components from Server Components. '+
17801750
'Math objects are not supported.\n'+
17811751
' [..., Math, <h1/>]\n'+

0 commit comments

Comments
 (0)