@@ -5,9 +5,6 @@ const path = require('path')
55
66let getMarkup
77let resourceLoader
8- // this value could be tweaked in order to let the resource
9- // retriever get every file and jsdom execute react
10- let timeToWaitForJsToExecute
118
129if ( process . env . E2E_FILE ) {
1310 const file = path . isAbsolute ( process . env . E2E_FILE )
@@ -21,8 +18,6 @@ if (process.env.E2E_FILE) {
2118 null ,
2219 fs . readFileSync ( path . join ( path . dirname ( file ) , resource . url . pathname ) , 'utf8' )
2320 )
24-
25- timeToWaitForJsToExecute = 0
2621} else if ( process . env . E2E_URL ) {
2722 getMarkup = ( ) => new Promise ( resolve => {
2823 http . get ( process . env . E2E_URL , ( res ) => {
@@ -32,11 +27,7 @@ if (process.env.E2E_FILE) {
3227 } )
3328 } )
3429
35- resourceLoader = ( resource , callback ) => {
36- return resource . defaultFetch ( callback )
37- }
38-
39- timeToWaitForJsToExecute = 100
30+ resourceLoader = ( resource , callback ) => resource . defaultFetch ( callback )
4031} else {
4132 it . only ( 'can run jsdom (at least one of "E2E_FILE" or "E2E_URL" environment variables must be provided)' , ( ) => {
4233 expect ( new Error ( 'This isn\'t the error you are looking for.' ) ) . toBeUndefined ( )
@@ -47,16 +38,16 @@ export default feature => new Promise(async resolve => {
4738 const markup = await getMarkup ( )
4839 const host = process . env . E2E_URL || 'http://localhost:3000'
4940 const doc = jsdom . jsdom ( markup , {
50- features : {
51- FetchExternalResources : [ 'script' , 'css' ] ,
52- ProcessExternalResources : [ 'script' ] ,
41+ features : {
42+ FetchExternalResources : [ 'script' , 'css' ] ,
43+ ProcessExternalResources : [ 'script' ] ,
5344 } ,
45+ created : ( _ , win ) => win . addEventListener ( 'ReactFeatureDidMount' , ( ) => resolve ( doc ) , true ) ,
46+ deferClose : true ,
5447 resourceLoader,
5548 url : `${ host } #${ feature } ` ,
5649 virtualConsole : jsdom . createVirtualConsole ( ) . sendTo ( console ) ,
5750 } )
5851
59- doc . defaultView . addEventListener ( 'load' , ( ) => {
60- setTimeout ( ( ) => resolve ( doc ) , timeToWaitForJsToExecute )
61- } , false )
52+ doc . close ( )
6253} )
0 commit comments