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

Code before:
                '    at eval (eval at testFunction (eval at createFakeFunction (/Users/sebbie/repos/react/packages/react-client/src/ReactFlightClient.js:1948:19), <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' +
            ' 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.',
          digest: 'digest("This is an error")',
        },
      ]);
    }
  });

  it('should include server components in warning stacks', async () => {
    function Component() {
      // Trigger key warning
      return <div>{[<span />]}</div>;
    }
    const ClientComponent = clientReference(Component);

    function Indirection({children}) {
      return children;
    }

    function App() {
      // We use the ReactServer runtime here to get the Server owner.
      return ReactServer.createElement(
        Indirection,
        null,
        ReactServer.createElement(ClientComponent),

Review comment (bug):
Single assertions are why more helpful over multiple assertions if one of them fails. A clue for the failure reason may be in later assertions and there may not be an optimal ordering. Packing everything in a single `expect` gives you the full context on mismatch. 

There's obviously a limit depending on the kind of assertion. But this is not one of those in my opinion.

Code after:
          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',
                )
              : expect.stringContaining(
                  'Error: This is an error\n' +
                    '    at eval (eval at testFunction (inspected-page.html:29:11), <anonymous>:1:10)\n' +
                    '    at ServerComponentError (file://~/(some)(really)(exotic-directory)/ReactFlight-test.js:1166:19)\n' +
                    '    at file:///testing.js:42:3\n' +
                    '    at file:///testing.js:42:3',
                ),
            digest: 'a dev digest',
            environmentName: 'Server',
          },
        ],
        findSourceMapURLCalls: gate(flags => flags.enableOwnerStacks)
          ? [
              [__filename],