@@ -891,6 +891,40 @@ describe('production', () => {
891
891
const index = await fs . readFile ( indexHtml , 'utf8' ) ;
892
892
expect ( index ) . toMatch ( / # h e l l o w o r l d / ) ;
893
893
} ) ;
894
+
895
+ // Whether or not to run the test to fetch external resources depends on whether or not a Node.js version 18 later
896
+ const isNodeVersionUnder18 = Number ( process . version . split ( '.' ) [ 0 ] . slice ( 1 ) ) < 18 ;
897
+ // Even if you are using Node.js v18 or higher, you will get the error `globalThis.fetch is undefined` here, so get the version from process.version
898
+ // if (globalThis.fetch === undefined)
899
+ if ( isNodeVersionUnder18 ) {
900
+ it . skip ( 'skip should support fetching resources from external links during prerender on Node.js v18 later' , ( ) => { } ) ;
901
+ it ( 'should not support fetching resources from external links during prerender on Node.js < v18' , async ( ) => {
902
+ await loadFixture ( 'prerender-external-resource-fetch' , env ) ;
903
+ instance = await runWmr ( env . tmp . path , 'build' , '--prerender' ) ;
904
+ const code = await instance . done ;
905
+
906
+ await withLog ( instance . output , async ( ) => {
907
+ expect ( code ) . toBe ( 1 ) ;
908
+ expect ( instance . output . join ( '\n' ) ) . toMatch (
909
+ / f e t c h i s n o t d e f i n e d i n N o d e .j s v e r s i o n u n d e r 1 7 , p l e a s e u p g r a d e t o N o d e .j s v e r s i o n 1 8 l a t e r /
910
+ ) ;
911
+ } ) ;
912
+ } ) ;
913
+ } else {
914
+ it . skip ( 'skip should not support fetching resources from external links during prerender on Node.js < v18' , ( ) => { } ) ;
915
+ it ( 'should support fetching resources from external links during prerender on Node.js v18 later' , async ( ) => {
916
+ await loadFixture ( 'prerender-external-resource-fetch' , env ) ;
917
+ instance = await runWmr ( env . tmp . path , 'build' , '--prerender' ) ;
918
+ const code = await instance . done ;
919
+
920
+ // when workflow of wmr runtime uses Node.js 18
921
+ // Until then check locally.
922
+ expect ( code ) . toBe ( 0 ) ;
923
+ const indexHtml = path . join ( env . tmp . path , 'dist' , 'index.html' ) ;
924
+ const index = await fs . readFile ( indexHtml , 'utf8' ) ;
925
+ expect ( index ) . toMatch ( / P r e a c t / ) ;
926
+ } ) ;
927
+ }
894
928
} ) ;
895
929
896
930
describe ( 'Code Splitting' , ( ) => {
0 commit comments