@@ -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 ) => {
@@ -35,8 +30,6 @@ if (process.env.E2E_FILE) {
3530 resourceLoader = ( resource , callback ) => {
3631 return resource . defaultFetch ( callback )
3732 }
38-
39- timeToWaitForJsToExecute = 100
4033} else {
4134 it . only ( 'can run jsdom (at least one of "E2E_FILE" or "E2E_URL" environment variables must be provided)' , ( ) => {
4235 expect ( new Error ( 'This isn\'t the error you are looking for.' ) ) . toBeUndefined ( )
@@ -47,16 +40,24 @@ export default feature => new Promise(async resolve => {
4740 const markup = await getMarkup ( )
4841 const host = process . env . E2E_URL || 'http://localhost:3000'
4942 const doc = jsdom . jsdom ( markup , {
50- features : {
51- FetchExternalResources : [ 'script' , 'css' ] ,
52- ProcessExternalResources : [ 'script' ] ,
43+ features : {
44+ FetchExternalResources : [ 'script' , 'css' ] ,
45+ ProcessExternalResources : [ 'script' ] ,
5346 } ,
5447 resourceLoader,
5548 url : `${ host } #${ feature } ` ,
5649 virtualConsole : jsdom . createVirtualConsole ( ) . sendTo ( console ) ,
5750 } )
5851
5952 doc . defaultView . addEventListener ( 'load' , ( ) => {
60- setTimeout ( ( ) => resolve ( doc ) , timeToWaitForJsToExecute )
53+ let tries = 0
54+ const check = ( ) => {
55+ if ( ++ tries > 50 || doc . querySelector ( '[id^="feature"]' ) != null ) {
56+ resolve ( doc )
57+ } else {
58+ setTimeout ( check , 10 )
59+ }
60+ }
61+ check ( )
6162 } , false )
6263} )
0 commit comments