|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | 'use strict'; |
11 | | -import {replaceScriptsAndMove, mergeOptions} from '../test-utils/FizzTestUtils'; |
| 11 | +import { |
| 12 | + replaceScriptsAndMove, |
| 13 | + mergeOptions, |
| 14 | + stripExternalRuntimeInString, |
| 15 | + stripExternalRuntimeInNodes, |
| 16 | +} from '../test-utils/FizzTestUtils'; |
12 | 17 |
|
13 | 18 | let JSDOM; |
14 | 19 | let Stream; |
@@ -577,7 +582,12 @@ describe('ReactDOMFizzServer', () => { |
577 | 582 | // Because there is no content inside the Suspense boundary that could've |
578 | 583 | // been written, we expect to not see any additional partial data flushed |
579 | 584 | // yet. |
580 | | - expect(container.childNodes.length).toBe(1); |
| 585 | + expect( |
| 586 | + stripExternalRuntimeInNodes( |
| 587 | + container.childNodes, |
| 588 | + renderOptions.unstable_externalRuntimeSrc, |
| 589 | + ).length, |
| 590 | + ).toBe(1); |
581 | 591 | await act(async () => { |
582 | 592 | resolveElement({default: <Text text="Hello" />}); |
583 | 593 | }); |
@@ -3471,21 +3481,19 @@ describe('ReactDOMFizzServer', () => { |
3471 | 3481 | </body> |
3472 | 3482 | </html>, |
3473 | 3483 | ); |
3474 | | - const expectedScripts = [ |
| 3484 | + expect( |
| 3485 | + stripExternalRuntimeInNodes( |
| 3486 | + document.getElementsByTagName('script'), |
| 3487 | + renderOptions.unstable_externalRuntimeSrc, |
| 3488 | + ).map(n => n.outerHTML), |
| 3489 | + ).toEqual([ |
3475 | 3490 | '<script src="foo" async=""></script>', |
3476 | 3491 | '<script src="bar" async=""></script>', |
3477 | 3492 | '<script src="baz" integrity="qux" async=""></script>', |
3478 | 3493 | '<script type="module" src="quux" async=""></script>', |
3479 | 3494 | '<script type="module" src="corge" async=""></script>', |
3480 | 3495 | '<script type="module" src="grault" integrity="garply" async=""></script>', |
3481 | | - ]; |
3482 | | - let actualScripts = Array.from(document.getElementsByTagName('script')).map( |
3483 | | - n => n.outerHTML, |
3484 | | - ); |
3485 | | - if (gate(flags => flags.enableFizzExternalRuntime)) { |
3486 | | - actualScripts = actualScripts.slice(1); |
3487 | | - } |
3488 | | - expect(actualScripts).toEqual(expectedScripts); |
| 3496 | + ]); |
3489 | 3497 | }); |
3490 | 3498 |
|
3491 | 3499 | describe('bootstrapScriptContent escaping', () => { |
@@ -4494,10 +4502,12 @@ describe('ReactDOMFizzServer', () => { |
4494 | 4502 | const {pipe} = renderToPipeableStream(<App name="Foo" />); |
4495 | 4503 | pipe(writable); |
4496 | 4504 | }); |
4497 | | - |
4498 | | - expect(container.innerHTML).toEqual( |
4499 | | - '<div>hello<b>world, <!-- -->Foo</b>!</div>', |
4500 | | - ); |
| 4505 | + expect( |
| 4506 | + stripExternalRuntimeInString( |
| 4507 | + container.innerHTML, |
| 4508 | + renderOptions.unstable_externalRuntimeSrc, |
| 4509 | + ), |
| 4510 | + ).toEqual('<div>hello<b>world, <!-- -->Foo</b>!</div>'); |
4501 | 4511 | const errors = []; |
4502 | 4512 | ReactDOMClient.hydrateRoot(container, <App name="Foo" />, { |
4503 | 4513 | onRecoverableError(error) { |
@@ -4542,13 +4552,14 @@ describe('ReactDOMFizzServer', () => { |
4542 | 4552 | expect(container.firstElementChild.outerHTML).toEqual( |
4543 | 4553 | '<div id="app-div">hello<b>world, Foo</b>!</div>', |
4544 | 4554 | ); |
4545 | | - // there are extra script / data nodes at the end of container |
4546 | | - if (gate(flags => flags.enableFizzExternalRuntime)) { |
4547 | | - // extra script node inserted for the external runtime |
4548 | | - expect(container.childNodes.length).toBe(6); |
4549 | | - } else { |
4550 | | - expect(container.childNodes.length).toBe(5); |
4551 | | - } |
| 4555 | + // there are extra script nodes at the end of container |
| 4556 | + expect( |
| 4557 | + stripExternalRuntimeInNodes( |
| 4558 | + container.childNodes, |
| 4559 | + renderOptions.unstable_externalRuntimeSrc, |
| 4560 | + ).length, |
| 4561 | + ).toBe(5); |
| 4562 | + |
4552 | 4563 | const div = container.childNodes[1]; |
4553 | 4564 | expect(div.childNodes.length).toBe(3); |
4554 | 4565 | const b = div.childNodes[1]; |
@@ -4851,8 +4862,12 @@ describe('ReactDOMFizzServer', () => { |
4851 | 4862 | pipe(writable); |
4852 | 4863 | }); |
4853 | 4864 |
|
4854 | | - // strip inserted external runtime |
4855 | | - expect(container.innerHTML).toEqual( |
| 4865 | + expect( |
| 4866 | + stripExternalRuntimeInString( |
| 4867 | + container.innerHTML, |
| 4868 | + renderOptions.unstable_externalRuntimeSrc, |
| 4869 | + ), |
| 4870 | + ).toEqual( |
4856 | 4871 | '<div><!--$-->hello<!-- -->world<!-- --><!--/$--><!--$-->world<!-- --><!--/$--><!--$-->hello<!-- -->world<!-- --><br><!--/$--><!--$-->world<!-- --><br><!--/$--></div>', |
4857 | 4872 | ); |
4858 | 4873 |
|
|
0 commit comments