@@ -2,62 +2,42 @@ import fs from 'fs';
2
2
import path from 'path' ;
3
3
import net from 'net' ;
4
4
import http from 'http' ;
5
- import electronPath from 'electron' ;
6
- import { Application } from 'spectron' ;
5
+ import executablePath from 'electron' ;
6
+ import { _electron as electron } from 'playwright-core' ;
7
+ import waitForExpect from 'wait-for-expect' ;
7
8
import buildTestBundle , { bundlePath } from './buildTestBundle' ;
8
9
import createMockRNServer from './mockRNServer' ;
9
- import autoUpdateFeed from '../auto_update.json' ;
10
10
11
11
const delay = ( time ) => new Promise ( ( resolve ) => setTimeout ( resolve , time ) ) ;
12
12
13
13
// eslint-disable-next-line
14
14
jasmine . DEFAULT_TIMEOUT_INTERVAL = 6e4 ;
15
15
16
16
describe ( 'Application launch' , ( ) => {
17
- let app ;
17
+ let electronApp ;
18
+ let mainWindow ;
19
+ const logs = [ ] ;
18
20
19
21
beforeAll ( async ( ) => {
20
22
await buildTestBundle ( ) ;
21
- app = new Application ( {
22
- path : electronPath ,
23
- args : [ '--user-dir=__e2e__/tmp' , 'dist' ] ,
24
- env : {
25
- E2E_TEST : 1 ,
26
- PACKAGE : 'no' ,
27
- } ,
23
+ process . env . E2E_TEST = '1' ;
24
+ process . env . PACKAGE = 'no' ;
25
+ electronApp = await electron . launch ( {
26
+ executablePath,
27
+ args : [ '--user-dir=__e2e__/tmp' , './main.js' ] ,
28
+ cwd : path . join ( __dirname , '../dist' ) ,
28
29
} ) ;
29
- return app . start ( ) ;
30
+ mainWindow = await electronApp . firstWindow ( ) ;
31
+ mainWindow . on ( 'console' , ( msg ) => logs . push ( msg ) ) ;
32
+ await mainWindow . waitForLoadState ( ) ;
30
33
} ) ;
31
34
32
- afterAll ( ( ) => {
33
- if ( app && app . isRunning ( ) ) {
34
- return app . stop ( ) ;
35
- }
36
- } ) ;
37
-
38
- it ( `should be v${ process . env . npm_package_version } ` , async ( ) => {
39
- // Check the App version (dist/package.json) is same with package.json
40
- const { electron } = app ;
41
- const version = await electron . remote . app . getVersion ( ) ;
42
-
43
- // Check auto update feed is expected
44
- expect ( version ) . toBe ( process . env . npm_package_version ) ;
45
- expect ( autoUpdateFeed . url ) . toBe (
46
- `https://github.com/jhen0409/react-native-debugger/releases/download/v${ version } /rn-debugger-macos-universal.zip` ,
47
- ) ;
48
- expect ( autoUpdateFeed . name ) . toBe ( `v${ version } ` ) ;
49
- expect ( typeof autoUpdateFeed . notes ) . toBe ( 'string' ) ;
50
-
51
- console . log ( `\nAuto update notes:\n\n${ autoUpdateFeed . notes } \n` ) ;
35
+ afterAll ( async ( ) => {
36
+ await electronApp . close ( ) ;
52
37
} ) ;
53
38
54
39
it ( 'should show an initial window' , async ( ) => {
55
- const { client, browserWindow } = app ;
56
-
57
- await client . waitUntilWindowLoaded ( ) ;
58
- await delay ( 2000 ) ;
59
- const title = await browserWindow . getTitle ( ) ;
60
- expect ( title ) . toBe (
40
+ expect ( await mainWindow . title ( ) ) . toBe (
61
41
'React Native Debugger - Attempting reconnection (port 8081)' ,
62
42
) ;
63
43
} ) ;
@@ -75,35 +55,25 @@ describe('Application launch', () => {
75
55
let expected = false ;
76
56
while ( attempts > 0 && ! expected ) {
77
57
expected = fs . existsSync ( portFile ) ;
78
- await delay ( 100 ) ;
58
+ await delay ( 1000 ) ;
79
59
attempts -- ;
80
60
}
81
61
expect ( expected ) . toBe ( true ) ;
82
62
} ) ;
83
63
84
64
it ( "should contain Inspector monitor's component on Redux DevTools" , async ( ) => {
85
- const { client } = app ;
86
-
87
- const el = await client . $ ( '//div[contains(@class, "inspector-")]' ) ;
88
- const val = await el . getText ( ) ;
65
+ const val = await mainWindow . textContent ( '//div[contains(@class, "inspector-")]' ) ;
89
66
expect ( val ) . not . toBeNull ( ) ;
90
67
} ) ;
91
68
92
69
it ( 'should contain an empty actions list on Redux DevTools' , async ( ) => {
93
- const { client } = app ;
94
-
95
- const el = await client . $ ( '//div[contains(@class, "actionListRows-")]' ) ;
96
- const val = await el . getText ( ) ;
70
+ const val = await mainWindow . textContent ( '//div[contains(@class, "actionListRows-")]' ) ;
97
71
expect ( val ) . toBe ( '' ) ;
98
72
} ) ;
99
73
100
74
it ( 'should show waiting message on React DevTools' , async ( ) => {
101
- const { client } = app ;
102
- const el = await client . $ (
103
- '//h2[text()="Waiting for React to connect…"]' ,
104
- ) ;
105
- const exist = await el . isExisting ( ) ;
106
- expect ( exist ) . toBe ( true ) ;
75
+ const el = await mainWindow . locator ( '//h2[text()="Waiting for React to connect…"]' ) ;
76
+ expect ( await el . isVisible ( ) ) . toBe ( true ) ;
107
77
} ) ;
108
78
109
79
const customRNServerPort = 8098 ;
@@ -120,8 +90,7 @@ describe('Application launch', () => {
120
90
const url = await getURLFromConnection ( wss ) ;
121
91
expect ( url ) . toBe ( '/debugger-proxy?role=debugger&name=Chrome' ) ;
122
92
123
- const title = await app . browserWindow . getTitle ( ) ;
124
- expect ( title ) . toBe (
93
+ expect ( await mainWindow . title ( ) ) . toBe (
125
94
'React Native Debugger - Waiting for client connection (port 8081)' ,
126
95
) ;
127
96
server . close ( ) ;
@@ -154,10 +123,11 @@ describe('Application launch', () => {
154
123
const url = await getURLFromConnection ( wss ) ;
155
124
expect ( url ) . toBe ( '/debugger-proxy?role=debugger&name=Chrome' ) ;
156
125
157
- const title = await app . browserWindow . getTitle ( ) ;
158
- expect ( title ) . toBe (
159
- `React Native Debugger - Waiting for client connection (port ${ customRNServerPort } )` ,
160
- ) ;
126
+ await waitForExpect ( async ( ) => {
127
+ expect ( await mainWindow . title ( ) ) . toBe (
128
+ `React Native Debugger - Waiting for client connection (port ${ customRNServerPort } )` ,
129
+ ) ;
130
+ } ) ;
161
131
server . close ( ) ;
162
132
wss . close ( ) ;
163
133
} ) ;
@@ -213,8 +183,7 @@ describe('Application launch', () => {
213
183
) ;
214
184
} ) ;
215
185
} ) ;
216
- const title = await app . browserWindow . getTitle ( ) ;
217
- expect ( title ) . toBe (
186
+ expect ( await mainWindow . title ( ) ) . toBe (
218
187
`React Native Debugger - Connected (port ${ customRNServerPort } )` ,
219
188
) ;
220
189
} ) ;
@@ -232,26 +201,23 @@ describe('Application launch', () => {
232
201
} ) ;
233
202
234
203
it ( 'should have @@INIT action on Redux DevTools' , async ( ) => {
235
- const { client } = app ;
236
- const el = await client . $ ( '//div[contains(@class, "actionListRows-")]' ) ;
237
- const val = await el . getText ( ) ;
238
- expect ( val ) . toMatch ( / @ @ r e d u x \/ I N I T / ) ; // Last store is `RemoteDev store instance 1`
204
+ expect (
205
+ await mainWindow . textContent ( '//div[contains(@class, "actionListRows-")]' )
206
+ ) . toMatch ( / @ @ r e d u x \/ I N I T / ) ; // Last store is `RemoteDev store instance 1`
239
207
} ) ;
240
208
241
209
let currentInstance = 'Autoselect instances' ; // Default instance
242
210
const wait = ( ) => delay ( 750 ) ;
243
211
const selectInstance = async ( instance ) => {
244
- const { client } = app ;
245
- let el = await client . $ ( `//div[text()="${ currentInstance } "]` ) ;
246
- await el . click ( ) . then ( wait ) ;
212
+ await mainWindow . click ( `//div[text()="${ currentInstance } "]` ) ;
213
+ await wait ( ) ;
247
214
currentInstance = instance ;
248
- el = await client . $ ( `//div[text()="${ instance } "]` ) ;
249
- return el . click ( ) . then ( wait ) ;
215
+ await mainWindow . click ( `//div[text()="${ instance } "]` ) ;
216
+ await wait ( ) ;
250
217
} ;
251
218
const commit = async ( ) => {
252
- const { client } = app ;
253
- const el = await client . $ ( '//div[text()="Commit"]' ) ;
254
- await el . click ( ) . then ( delay ( 100 ) ) ;
219
+ await mainWindow . click ( '//div[text()="Commit"]' ) ;
220
+ await wait ( ) ;
255
221
} ;
256
222
257
223
const expectActions = {
@@ -298,11 +264,8 @@ describe('Application launch', () => {
298
264
} ;
299
265
300
266
const checkInstance = async ( name ) => {
301
- const { client } = app ;
302
-
303
267
await selectInstance ( name ) ;
304
- const el = await client . $ ( '//div[contains(@class, "actionListRows-")]' ) ;
305
- const val = await el . getText ( ) ;
268
+ const val = await mainWindow . textContent ( '//div[contains(@class, "actionListRows-")]' ) ;
306
269
runExpectActions ( name , val ) ;
307
270
await commit ( ) ;
308
271
} ;
@@ -322,30 +285,25 @@ describe('Application launch', () => {
322
285
} ) ;
323
286
324
287
it ( 'should have only specific logs in console of main window' , async ( ) => {
325
- const { client } = app ;
326
- const logs = await client . getRenderProcessLogs ( ) ;
327
288
// Print renderer process logs
328
289
logs . forEach ( ( log ) =>
329
290
console . log (
330
- `Message: ${ log . message } \nSource : ${ log . source } \nLevel: ${ log . level } ` ,
291
+ `Message: ${ log . text ( ) } \nType : ${ log . type ( ) } ` ,
331
292
) ,
332
293
) ;
333
- expect ( logs . length ) . toEqual ( 1 ) ;
334
- const [ formDataWarning ] = logs ;
335
- expect ( formDataWarning . source ) . toBe ( 'worker' ) ;
336
- expect ( formDataWarning . level ) . toBe ( 'WARNING' ) ;
294
+ expect ( logs . length ) . toEqual ( 3 ) ; // clear + clear + warning
295
+ const [ , , formDataWarning ] = logs ;
296
+ expect ( formDataWarning . type ( ) ) . toBe ( 'warning' ) ;
337
297
expect (
338
- formDataWarning . message . indexOf (
298
+ formDataWarning . text ( ) . indexOf (
339
299
"Detected you're enabled Network Inspect" ,
340
300
) > 0 ,
341
301
) . toBeTruthy ( ) ;
342
302
} ) ;
343
303
344
304
it ( 'should show apollo devtools panel' , async ( ) => {
345
305
expect (
346
- await app . webContents . executeJavaScript (
347
- 'window.__APOLLO_DEVTOOLS_SHOULD_DISPLAY_PANEL__'
348
- ) ,
306
+ await mainWindow . evaluate ( ( ) => window . __APOLLO_DEVTOOLS_SHOULD_DISPLAY_PANEL__ ) ,
349
307
) . toBeTruthy ( ) ;
350
308
} ) ;
351
309
} ) ;
0 commit comments