MCPcopy
hub / github.com/facebook/react / consoleSpy

Function consoleSpy

fixtures/legacy-jsx-runtimes/setupTests.js:105–179  ·  view source on GitHub ↗
(format, ...args)

Source from the content-addressed store, hash-verified

103 (message.includes('\n in ') || message.includes('\n at '));
104
105 const consoleSpy = (format, ...args) => {
106 // Ignore uncaught errors reported by jsdom
107 // and React addendums because they're too noisy.
108 if (
109 !logAllErrors &&
110 consoleMethod === 'error' &&
111 shouldIgnoreConsoleError(format, args)
112 ) {
113 return;
114 }
115
116 const message = util.format(format, ...args);
117 const normalizedMessage = normalizeCodeLocInfo(message);
118
119 // Remember if the number of %s interpolations
120 // doesn't match the number of arguments.
121 // We'll fail the test if it happens.
122 let argIndex = 0;
123 format.replace(/%s/g, () => argIndex++);
124 if (argIndex !== args.length) {
125 lastWarningWithMismatchingFormat = {
126 format,
127 args,
128 expectedArgCount: argIndex,
129 };
130 }
131
132 // Protect against accidentally passing a component stack
133 // to warning() which already injects the component stack.
134 if (
135 args.length >= 2 &&
136 isLikelyAComponentStack(args[args.length - 1]) &&
137 isLikelyAComponentStack(args[args.length - 2])
138 ) {
139 lastWarningWithExtraComponentStack = {
140 format,
141 };
142 }
143
144 for (let index = 0; index < expectedMessages.length; index++) {
145 const expectedMessage = expectedMessages[index];
146 if (
147 normalizedMessage === expectedMessage ||
148 normalizedMessage.includes(expectedMessage)
149 ) {
150 if (isLikelyAComponentStack(normalizedMessage)) {
151 warningsWithComponentStack.push(normalizedMessage);
152 } else {
153 warningsWithoutComponentStack.push(normalizedMessage);
154 }
155 expectedMessages.splice(index, 1);
156 return;
157 }
158 }
159
160 let errorMessage;
161 if (expectedMessages.length === 0) {
162 errorMessage =

Callers

nothing calls this directly

Calls 4

shouldIgnoreConsoleErrorFunction · 0.85
normalizeCodeLocInfoFunction · 0.70
isLikelyAComponentStackFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected