Repository: facebook/react
File: packages/react-client/src/__tests__/ReactFlight-test.js (JavaScript)

Code before:
        } else if (typeof x === 'object' && x !== null) {
          return `digest({})`;
        }
        return `digest(${String(x)})`;
      },
    });

    await act(() => {
      startTransition(() => {
        ReactNoop.render(
          ReactNoopFlightClient.read(transport, {findSourceMapURL}),
        );
      });
    });

    if (__DEV__) {
      expect({
        errors: errors.map(getErrorForJestMatcher),
        findSourceMapURLCalls: findSourceMapURL.mock.calls,
      }).toEqual({
        errors: [
          {
            message: 'This is an error',
            stack: expect.stringContaining(
              'Error: This is an error\n' +
                '    at eval (eval at testFunction (eval at createFakeFunction (**), <anonymous>:1:35)\n' +
                '    at ServerComponentError (file://~/(some)(really)(exotic-directory)/ReactFlight-test.js:1166:19)\n' +
                '    at (anonymous) (file:///testing.js:42:3)\n' +
                '    at (anonymous) (file:///testing.js:42:3)\n',
            ),
            digest: 'a dev digest',
            environmentName: 'Server',
          },
        ],
        findSourceMapURLCalls: expect.arrayContaining([
          // TODO: What should we request here? The outer (<anonymous>) or the inner (inspected-page.html)?
          ['inspected-page.html:29:11), <anonymous>'],
          ['file://~/(some)(really)(exotic-directory)/ReactFlight-test.js'],
          ['file:///testing.js'],
          ['file:///testing.js'],
        ]),
      });
    } else {
      expect(errors.map(getErrorForJestMatcher)).toEqual([
        {
          message:
            'An error occurred in the Server Components render. The specific message is omitted in production' +
            ' builds to avoid leaking sensitive details. A digest property is included on this error instance which' +
            ' may provide additional details about the nature of the error.',
          stack:
            'Error: An error occurred in the Server Components render. The specific message is omitted in production' +

Review comment (suggestion):
Not sure how `createFakeFunction` ends up here especially because the frame now has non-matching parens.

Code after:
      }
    }
    const ClientErrorBoundary = clientReference(MyErrorBoundary);

    function App() {
      return (
        <ClientErrorBoundary>
          <ServerComponent />
        </ClientErrorBoundary>
      );
    }

    const transport = ReactNoopFlightServer.render(<App />, {
      onError(x) {
        if (__DEV__) {
          return 'a dev digest';
        }
        if (x instanceof Error) {
          return `digest("${x.message}")`;
        } else if (Array.isArray(x)) {
          return `digest([])`;
        } else if (typeof x === 'object' && x !== null) {
          return `digest({})`;
        }
        return `digest(${String(x)})`;
      },
    });

    await act(() => {
      startTransition(() => {
        ReactNoop.render(
          ReactNoopFlightClient.read(transport, {findSourceMapURL}),
        );
      });
    });

    if (__DEV__) {
      expect({
        errors: errors.map(getErrorForJestMatcher),
        findSourceMapURLCalls: findSourceMapURL.mock.calls,
      }).toEqual({
        errors: [
          {
            message: 'This is an error',
            stack: gate(flags => flags.enableOwnerStacks)
              ? expect.stringContaining(
                  'Error: This is an error\n' +
                    '    at eval (eval at testFunction (eval at createFakeFunction (**), <anonymous>:1:35)\n' +
                    '    at ServerComponentError (file://~/(some)(really)(exotic-directory)/ReactFlight-test.js:1166:19)\n' +
                    '    at (anonymous) (file:///testing.js:42:3)\n' +
                    '    at (anonymous) (file:///testing.js:42:3)\n',