@@ -10,19 +10,19 @@ describe('SSRExecutorManager', () => {
10
10
11
11
manager . getOrCreate ( 'xxx' ) ;
12
12
13
- expect ( manager . nextHydrationChunk ( ) ) . toBeUndefined ( ) ;
13
+ expect ( manager . nextHydrationChunk ( ) ) . toBe ( '' ) ;
14
14
} ) ;
15
15
16
- test ( 'returns a hydration chunk' , async ( ) => {
16
+ test ( 'returns the hydration chunk for a single executor ' , async ( ) => {
17
17
const manager = new SSRExecutorManager ( ) ;
18
18
19
19
const executor = manager . getOrCreate ( 'xxx' ) ;
20
20
21
- expect ( manager . nextHydrationChunk ( ) ) . toBeUndefined ( ) ;
21
+ expect ( manager . nextHydrationChunk ( ) ) . toBe ( '' ) ;
22
22
23
23
const promise = executor . execute ( ( ) => 111 ) ;
24
24
25
- expect ( manager . nextHydrationChunk ( ) ) . toBeUndefined ( ) ;
25
+ expect ( manager . nextHydrationChunk ( ) ) . toBe ( '' ) ;
26
26
27
27
await promise ;
28
28
@@ -31,6 +31,27 @@ describe('SSRExecutorManager', () => {
31
31
) ;
32
32
} ) ;
33
33
34
+ test ( 'returns the hydration chunk for multiple executors' , async ( ) => {
35
+ const manager = new SSRExecutorManager ( ) ;
36
+
37
+ const executor1 = manager . getOrCreate ( 'xxx' ) ;
38
+ const executor2 = manager . getOrCreate ( 'yyy' ) ;
39
+
40
+ expect ( manager . nextHydrationChunk ( ) ) . toBe ( '' ) ;
41
+
42
+ const promise1 = executor1 . execute ( ( ) => 111 ) ;
43
+ const promise2 = executor2 . execute ( ( ) => 222 ) ;
44
+
45
+ expect ( manager . nextHydrationChunk ( ) ) . toBe ( '' ) ;
46
+
47
+ await promise1 ;
48
+ await promise2 ;
49
+
50
+ expect ( manager . nextHydrationChunk ( ) ) . toBe (
51
+ '<script>(window.__REACT_EXECUTOR_SSR_STATE__=window.__REACT_EXECUTOR_SSR_STATE__||[]).push("{\\"key\\":\\"xxx\\",\\"isFulfilled\\":true,\\"value\\":111,\\"annotations\\":{},\\"settledAt\\":50,\\"invalidatedAt\\":0}","{\\"key\\":\\"yyy\\",\\"isFulfilled\\":true,\\"value\\":222,\\"annotations\\":{},\\"settledAt\\":50,\\"invalidatedAt\\":0}");var e=document.currentScript;e&&e.parentNode.removeChild(e)</script>'
52
+ ) ;
53
+ } ) ;
54
+
34
55
test ( 'returns only changed executor states in consequent hydration chunks' , async ( ) => {
35
56
const manager = new SSRExecutorManager ( ) ;
36
57
@@ -43,7 +64,7 @@ describe('SSRExecutorManager', () => {
43
64
44
65
const promise = executor2 . execute ( ( ) => 222 ) ;
45
66
46
- expect ( manager . nextHydrationChunk ( ) ) . toBeUndefined ( ) ;
67
+ expect ( manager . nextHydrationChunk ( ) ) . toBe ( '' ) ;
47
68
48
69
await promise ;
49
70
@@ -60,7 +81,7 @@ describe('SSRExecutorManager', () => {
60
81
. execute ( ( ) => Promise . reject ( 'expected' ) )
61
82
. catch ( noop ) ;
62
83
63
- expect ( manager . nextHydrationChunk ( ) ) . toBeUndefined ( ) ;
84
+ expect ( manager . nextHydrationChunk ( ) ) . toBe ( '' ) ;
64
85
} ) ;
65
86
66
87
test ( 'respects executorFilter option' , async ( ) => {
@@ -78,7 +99,7 @@ describe('SSRExecutorManager', () => {
78
99
) ;
79
100
} ) ;
80
101
81
- test ( 'respects executorFilter option' , async ( ) => {
102
+ test ( 'respects stateStringifier option' , async ( ) => {
82
103
const stateStringifierMock = jest . fn ( JSON . stringify ) ;
83
104
84
105
const manager = new SSRExecutorManager ( {
0 commit comments