Home / Function/ runTestCommand() — react Function Reference

runTestCommand() — react Function Reference

Architecture documentation for the runTestCommand() function in runner.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  4b902db8_39ff_6c09_0a25_3a6bd51d0bf7["runTestCommand()"]
  1fd49604_fb16_2568_4971_9eca12fd6a73["runner.ts"]
  4b902db8_39ff_6c09_0a25_3a6bd51d0bf7 -->|defined in| 1fd49604_fb16_2568_4971_9eca12fd6a73
  7865a05e_4feb_a8ba_40fe_4675700de39b["makeWatchRunner()"]
  4b902db8_39ff_6c09_0a25_3a6bd51d0bf7 -->|calls| 7865a05e_4feb_a8ba_40fe_4675700de39b
  6f987440_694d_ff09_5b9e_6bb4093380cc["onChange()"]
  4b902db8_39ff_6c09_0a25_3a6bd51d0bf7 -->|calls| 6f987440_694d_ff09_5b9e_6bb4093380cc
  5e39198b_b086_5261_de7a_7fc49349ecb6["transformFixture()"]
  4b902db8_39ff_6c09_0a25_3a6bd51d0bf7 -->|calls| 5e39198b_b086_5261_de7a_7fc49349ecb6
  162e6a49_36d0_cdf1_de46_a40230bcfbc6["watchSrc()"]
  4b902db8_39ff_6c09_0a25_3a6bd51d0bf7 -->|calls| 162e6a49_36d0_cdf1_de46_a40230bcfbc6
  8b079862_93aa_0084_8b1a_0473b6ef4307["runFixtures()"]
  4b902db8_39ff_6c09_0a25_3a6bd51d0bf7 -->|calls| 8b079862_93aa_0084_8b1a_0473b6ef4307
  3231d288_7a22_d6ca_c3cc_bc226b0b74ef["update()"]
  4b902db8_39ff_6c09_0a25_3a6bd51d0bf7 -->|calls| 3231d288_7a22_d6ca_c3cc_bc226b0b74ef
  4cc3311f_4441_948f_0625_b0189227e270["report()"]
  4b902db8_39ff_6c09_0a25_3a6bd51d0bf7 -->|calls| 4cc3311f_4441_948f_0625_b0189227e270
  style 4b902db8_39ff_6c09_0a25_3a6bd51d0bf7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/snap/src/runner.ts lines 63–156

async function runTestCommand(opts: TestOptions): Promise<void> {
  const worker: Worker & typeof runnerWorker = new Worker(WORKER_PATH, {
    enableWorkerThreads: opts.workerThreads,
    numWorkers: NUM_WORKERS,
  }) as any;
  worker.getStderr().pipe(process.stderr);
  worker.getStdout().pipe(process.stdout);

  // Check if watch mode should be enabled
  const shouldWatch = opts.watch;

  if (shouldWatch) {
    makeWatchRunner(
      state => onChange(worker, state, opts.sync, opts.verbose),
      opts.debug,
      opts.pattern,
    );
    if (opts.pattern) {
      /**
       * Warm up wormers when in watch mode. Loading the Forget babel plugin
       * and all of its transitive dependencies takes 1-3s (per worker) on a M1.
       * As jest-worker dispatches tasks using a round-robin strategy, we can
       * avoid an additional 1-3s wait on the first num_workers runs by warming
       * up workers eagerly.
       */
      for (let i = 0; i < NUM_WORKERS - 1; i++) {
        worker.transformFixture(
          {
            fixturePath: 'tmp',
            snapshotPath: './tmp.expect.md',
            inputPath: './tmp.js',
            input: `
            function Foo(props) {
              return identity(props);
            }
            `,
            snapshot: null,
          },
          0,
          false,
          false,
        );
      }
    }
  } else {
    // Non-watch mode. For simplicity we re-use the same watchSrc() function.
    // After the first build completes run tests and exit
    const tsWatch: ts.WatchOfConfigFile<ts.SemanticDiagnosticsBuilderProgram> =
      watchSrc(
        () => {},
        async (isTypecheckSuccess: boolean) => {
          let isSuccess = false;
          if (!isTypecheckSuccess) {
            console.error(
              'Found typescript errors in Forget source code, skipping test fixtures.',
            );
          } else {
            try {
              execSync('yarn build', {cwd: BABEL_PLUGIN_ROOT});
              console.log('Built compiler successfully with tsup');

              // Determine which filter to use
              let testFilter: TestFilter | null = null;
              if (opts.pattern) {
                testFilter = {
                  paths: [opts.pattern],
                };
              }

              const results = await runFixtures(
                worker,
                testFilter,
                0,
                opts.debug,
                false, // no requireSingleFixture in non-watch mode
                opts.sync,
              );
              if (opts.update) {
                update(results);
                isSuccess = true;
              } else {

Domain

Subdomains

Frequently Asked Questions

What does runTestCommand() do?
runTestCommand() is a function in the react codebase, defined in compiler/packages/snap/src/runner.ts.
Where is runTestCommand() defined?
runTestCommand() is defined in compiler/packages/snap/src/runner.ts at line 63.
What does runTestCommand() call?
runTestCommand() calls 7 function(s): makeWatchRunner, onChange, report, runFixtures, transformFixture, update, watchSrc.

Analyze Your Own Codebase

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

Try Supermodel Free