Home / File/ consoleMock.js — react Source File

consoleMock.js — react Source File

Architecture documentation for consoleMock.js, a javascript file in the react codebase. 2 imports, 2 dependents.

File javascript BabelCompiler Entrypoint 2 imports 2 dependents 14 functions

Entity Profile

Dependency Diagram

graph LR
  9565063b_3ea2_9cbf_86d6_3ee1e66bf4cc["consoleMock.js"]
  438ec5cd_e09b_6193_06b7_3753a896b547["jest-diff"]
  9565063b_3ea2_9cbf_86d6_3ee1e66bf4cc --> 438ec5cd_e09b_6193_06b7_3753a896b547
  b0ee042d_38c8_f357_7215_19b816e75888["jest-matcher-utils"]
  9565063b_3ea2_9cbf_86d6_3ee1e66bf4cc --> b0ee042d_38c8_f357_7215_19b816e75888
  29c464eb_52d1_465c_432a_544e82213726["ReactInternalTestUtils.js"]
  29c464eb_52d1_465c_432a_544e82213726 --> 9565063b_3ea2_9cbf_86d6_3ee1e66bf4cc
  0aa66ba3_905d_182f_1981_1f2301583b90["internalAct.js"]
  0aa66ba3_905d_182f_1981_1f2301583b90 --> 9565063b_3ea2_9cbf_86d6_3ee1e66bf4cc
  style 9565063b_3ea2_9cbf_86d6_3ee1e66bf4cc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

/* eslint-disable react-internal/no-production-logging */

const chalk = require('chalk');
const util = require('util');
const shouldIgnoreConsoleError = require('./shouldIgnoreConsoleError');
const shouldIgnoreConsoleWarn = require('./shouldIgnoreConsoleWarn');
import {diff} from 'jest-diff';
import {printReceived} from 'jest-matcher-utils';

// Annoying: need to store the log array on the global or it would
// change reference whenever you call jest.resetModules after patch.
const loggedErrors = (global.__loggedErrors = global.__loggedErrors || []);
const loggedWarns = (global.__loggedWarns = global.__loggedWarns || []);
const loggedLogs = (global.__loggedLogs = global.__loggedLogs || []);

const patchConsoleMethod = (methodName, logged) => {
  const newMethod = function (format, ...args) {
    // Ignore uncaught errors reported by jsdom
    // and React addendums because they're too noisy.
    if (shouldIgnoreConsoleError(format, args)) {
      return;
    }

    // Ignore certain React warnings causing test failures
    if (methodName === 'warn' && shouldIgnoreConsoleWarn(format)) {
      return;
    }

    // Append Component Stacks. Simulates a framework or DevTools appending them.
    if (
      typeof format === 'string' &&
      (methodName === 'error' || methodName === 'warn')
    ) {
      const React = require('react');

      // Ideally we could remove this check, but we have some tests like
      // useSyncExternalStoreShared-test that tests against React 17,
      // which doesn't have the captureOwnerStack method.
      if (React.captureOwnerStack) {
        const stack = React.captureOwnerStack();
        if (stack) {
          format += '%s';
          args.push(stack);
        }
      }
    }

    logged.push([format, ...args]);
  };

  console[methodName] = newMethod;

  return newMethod;
// ... (500 more lines)

Domain

Subdomains

Dependencies

  • jest-diff
  • jest-matcher-utils

Frequently Asked Questions

What does consoleMock.js do?
consoleMock.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Entrypoint subdomain.
What functions are defined in consoleMock.js?
consoleMock.js defines 14 function(s): assertConsoleLogsCleared, clearErrors, clearLogs, clearWarnings, createLogAssertion, expandEnvironmentPlaceholders, isLikelyAComponentStack, isLikelyAnErrorStackTrace, normalizeCodeLocInfo, normalizeComponentStack, and 4 more.
What does consoleMock.js depend on?
consoleMock.js imports 2 module(s): jest-diff, jest-matcher-utils.
What files import consoleMock.js?
consoleMock.js is imported by 2 file(s): ReactInternalTestUtils.js, internalAct.js.
Where is consoleMock.js in the architecture?
consoleMock.js is located at packages/internal-test-utils/consoleMock.js (domain: BabelCompiler, subdomain: Entrypoint, directory: packages/internal-test-utils).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free