1010
1111'use strict' ;
1212
13+ let act ;
1314let React ;
1415let ReactNoopServer ;
1516
17+ function normalizeCodeLocInfo ( str ) {
18+ return (
19+ str &&
20+ str . replace ( / ^ + (?: a t | i n ) ( [ \S ] + ) [ ^ \n ] * / gm, function ( m , name ) {
21+ const dot = name . lastIndexOf ( '.' ) ;
22+ if ( dot !== - 1 ) {
23+ name = name . slice ( dot + 1 ) ;
24+ }
25+ return ' in ' + name + ( / \d / . test ( m ) ? ' (at **)' : '' ) ;
26+ } )
27+ ) ;
28+ }
29+
1630describe ( 'ReactServer' , ( ) => {
1731 beforeEach ( ( ) => {
1832 jest . resetModules ( ) ;
1933
34+ act = require ( 'internal-test-utils' ) . act ;
2035 React = require ( 'react' ) ;
2136 ReactNoopServer = require ( 'react-noop-renderer/server' ) ;
2237 } ) ;
@@ -32,4 +47,42 @@ describe('ReactServer', () => {
3247 const result = ReactNoopServer . render ( < div > hello world</ div > ) ;
3348 expect ( result . root ) . toEqual ( div ( 'hello world' ) ) ;
3449 } ) ;
50+
51+ it ( 'has Owner Stacks when aborted' , async ( ) => {
52+ function Component ( { promise} ) {
53+ React . use ( promise ) ;
54+ return < div > Hello, Dave!</ div > ;
55+ }
56+ function App ( { promise} ) {
57+ return < Component promise = { promise } /> ;
58+ }
59+
60+ let caughtError ;
61+ let componentStack ;
62+ let ownerStack ;
63+ const result = ReactNoopServer . render (
64+ < App promise = { new Promise ( ( ) => { } ) } /> ,
65+ {
66+ onError : ( error , errorInfo ) => {
67+ caughtError = error ;
68+ componentStack = errorInfo . componentStack ;
69+ ownerStack = __DEV__ ? React . captureOwnerStack ( ) : null ;
70+ } ,
71+ } ,
72+ ) ;
73+
74+ await act ( async ( ) => {
75+ result . abort ( ) ;
76+ } ) ;
77+ expect ( caughtError ) . toEqual (
78+ expect . objectContaining ( {
79+ message : 'The render was aborted by the server without a reason.' ,
80+ } ) ,
81+ ) ;
82+ expect ( normalizeCodeLocInfo ( componentStack ) ) . toEqual (
83+ '\n in Component (at **)' + '\n in App (at **)' ,
84+ ) ;
85+ // FIXME: Should have a stack.
86+ expect ( normalizeCodeLocInfo ( ownerStack ) ) . toEqual ( null ) ;
87+ } ) ;
3588} ) ;
0 commit comments