@@ -8,9 +8,10 @@ import waitForExpect from 'wait-for-expect'
88import buildTestBundle , { bundlePath } from './buildTestBundle'
99import createMockRNServer from './mockRNServer'
1010
11- const delay = ( time ) => new Promise ( ( resolve ) => {
12- setTimeout ( resolve , time )
13- } )
11+ const delay = ( time ) =>
12+ new Promise ( ( resolve ) => {
13+ setTimeout ( resolve , time )
14+ } )
1415
1516jest . setTimeout ( 6e4 )
1617
@@ -21,7 +22,6 @@ describe('Application launch', () => {
2122
2223 beforeAll ( async ( ) => {
2324 await buildTestBundle ( )
24- process . env . E2E_TEST = '1'
2525 process . env . PACKAGE = 'no'
2626 electronApp = await electron . launch ( {
2727 executablePath,
@@ -33,6 +33,24 @@ describe('Application launch', () => {
3333 await mainWindow . waitForLoadState ( )
3434 } )
3535
36+ afterEach ( async ( ) => {
37+ const state = expect . getState ( )
38+ await mainWindow . screenshot ( {
39+ path : `./artifacts/${ state . currentTestName } .png` ,
40+ } )
41+ const devtoolsWindow = electronApp . windows ( ) [ 2 ]
42+ if ( devtoolsWindow ) {
43+ try {
44+ await delay ( 100 )
45+ await devtoolsWindow . screenshot ( {
46+ path : `./artifacts/devtools:${ state . currentTestName } .png` ,
47+ } )
48+ } catch ( e ) {
49+ console . error ( e )
50+ }
51+ }
52+ } )
53+
3654 afterAll ( async ( ) => {
3755 await electronApp . close ( )
3856 } )
@@ -79,11 +97,12 @@ describe('Application launch', () => {
7997 } )
8098
8199 const customRNServerPort = 8098
82- const getURLFromConnection = ( server ) => new Promise ( ( resolve ) => {
83- server . on ( 'connection' , ( socket , req ) => {
84- resolve ( req . url )
100+ const getURLFromConnection = ( server ) =>
101+ new Promise ( ( resolve ) => {
102+ server . on ( 'connection' , ( socket , req ) => {
103+ resolve ( req . url )
104+ } )
85105 } )
86- } )
87106
88107 it ( 'should connect to fake RN server' , async ( ) => {
89108 const { wss, server } = createMockRNServer ( )
@@ -139,15 +158,16 @@ describe('Application launch', () => {
139158 } )
140159
141160 describe ( 'Import fake script after' , ( ) => {
142- const getOneRequestHeaders = ( port ) => new Promise ( ( resolve ) => {
143- const server = http . createServer ( ( req , res ) => {
144- res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } )
145- res . end ( '' )
146- resolve ( req . headers )
147- server . close ( )
161+ const getOneRequestHeaders = ( port ) =>
162+ new Promise ( ( resolve ) => {
163+ const server = http . createServer ( ( req , res ) => {
164+ res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } )
165+ res . end ( '' )
166+ resolve ( req . headers )
167+ server . close ( )
168+ } )
169+ server . listen ( port )
148170 } )
149- server . listen ( port )
150- } )
151171
152172 let headersPromise
153173 let server
@@ -263,10 +283,11 @@ describe('Application launch', () => {
263283 } ,
264284 }
265285
266- const eachAsync = ( entries , fn ) => entries . reduce (
267- ( promise , entry , index ) => promise . then ( ( ) => fn ( entry , index ) ) ,
268- Promise . resolve ( ) ,
269- )
286+ const eachAsync = ( entries , fn ) =>
287+ entries . reduce (
288+ ( promise , entry , index ) => promise . then ( ( ) => fn ( entry , index ) ) ,
289+ Promise . resolve ( ) ,
290+ )
270291
271292 const runExpectActions = async ( name ) => {
272293 const { expt, notExpt } = expectActions [ name ]
@@ -310,7 +331,9 @@ describe('Application launch', () => {
310331
311332 it ( 'should have only specific logs in console of main window' , async ( ) => {
312333 // Print renderer process logs
313- logs . forEach ( ( log ) => console . log ( `Message: ${ log . text ( ) } \nType: ${ log . type ( ) } ` ) )
334+ logs . forEach ( ( log ) =>
335+ console . log ( `Message: ${ log . text ( ) } \nType: ${ log . type ( ) } ` ) ,
336+ )
314337 expect ( logs . length ) . toEqual ( 3 ) // clear + clear + warning
315338 const [ , , formDataWarning ] = logs
316339 expect ( formDataWarning . type ( ) ) . toBe ( 'warning' )
@@ -322,9 +345,14 @@ describe('Application launch', () => {
322345 } )
323346
324347 it ( 'should show apollo devtools panel' , async ( ) => {
348+ const devtoolsWindow = electronApp . windows ( ) [ 2 ]
325349 expect (
326- await mainWindow . evaluate (
327- ( ) => window . __APOLLO_DEVTOOLS_SHOULD_DISPLAY_PANEL__ ,
350+ await devtoolsWindow . evaluate ( ( ) =>
351+ // eslint-disable-next-line no-undef
352+ Object . keys ( UI . panels ) . some (
353+ ( key ) =>
354+ key . startsWith ( 'chrome-extension://' ) && key . endsWith ( 'Apollo' ) ,
355+ ) ,
328356 ) ,
329357 ) . toBeTruthy ( )
330358 } )
0 commit comments