@@ -27,7 +27,7 @@ export const appNameToMock =
27
27
28
28
export const launchApp = async ( ) => {
29
29
process . env . CI = 'e2e'
30
- process . env . MOCK_DOWNLOAD_URL = `http://127.0.0.1:8080 /download/kosium`
30
+ process . env . MOCK_DOWNLOAD_URL = `http://127.0.0.1:8081 /download/kosium`
31
31
process . env . APP_NAME_TO_MOCK = appNameToMock
32
32
if ( process . env . TEST_PACKAGED === 'true' ) {
33
33
console . log ( 'Testing packaged build' )
@@ -53,26 +53,26 @@ export const launchApp = async () => {
53
53
}
54
54
55
55
// this pipes the main process std out to test std out
56
- electronApp
57
- . process ( )
58
- . stdout ?. on ( 'data' , ( data ) => console . log ( `main process stdout: ${ data } ` ) )
59
- electronApp
60
- . process ( )
61
- . stderr ?. on ( 'data' , ( error ) => console . log ( `main process stderr: ${ error } ` ) )
62
-
63
- electronApp . on ( 'window' , async ( page ) => {
64
- const filename = page . url ( ) ?. split ( '/' ) . pop ( )
65
- console . log ( `Window opened: ${ filename } page url ${ page . url ( ) } ` )
66
-
67
- // capture errors
68
- page . on ( 'pageerror' , ( error ) => {
69
- console . error ( error )
70
- } )
71
- // capture console messages
72
- page . on ( 'console' , ( msg ) => {
73
- console . log ( msg . text ( ) )
74
- } )
75
- } )
56
+ // electronApp
57
+ // .process()
58
+ // .stdout?.on('data', (data) => console.log(`main process stdout: ${data}`))
59
+ // electronApp
60
+ // .process()
61
+ // .stderr?.on('data', (error) => console.log(`main process stderr: ${error}`))
62
+
63
+ // electronApp.on('window', async (page) => {
64
+ // const filename = page.url()?.split('/').pop()
65
+ // console.log(`Window opened: ${filename} page url ${page.url()}`)
66
+
67
+ // // capture errors
68
+ // page.on('pageerror', (error) => {
69
+ // console.error(error)
70
+ // })
71
+ // // capture console messages
72
+ // page.on('console', (msg) => {
73
+ // console.log(msg.text())
74
+ // })
75
+ // })
76
76
77
77
const hpPagePromise = new Promise < Page > ( ( res , rej ) => {
78
78
async function getPageTitle ( page_i : Page ) {
@@ -88,6 +88,10 @@ export const launchApp = async () => {
88
88
return false
89
89
}
90
90
91
+ /**
92
+ * @dev Note that this will throw the following error on the electronApp.close function call
93
+ * Error during electronApp.waitForEvent(window): Error: electronApplication.waitForEvent: Target page, context or browser has been closed
94
+ */
91
95
electronApp
92
96
. waitForEvent ( 'window' , {
93
97
predicate : async ( page_i : Page ) => {
@@ -97,7 +101,6 @@ export const launchApp = async () => {
97
101
} )
98
102
. catch ( ( err ) => {
99
103
console . log ( `Error during electronApp.waitForEvent(window): ${ err } ` )
100
- rej ( err )
101
104
} )
102
105
103
106
for ( const windowPage of electronApp . windows ( ) ) {
@@ -115,13 +118,32 @@ export const launchApp = async () => {
115
118
console . log ( 'Electron app is ready for testing!' )
116
119
}
117
120
121
+ async function launchMockBackend ( ) {
122
+ try {
123
+ const mockBackend = await import ( '@hyperplay/mock-backend' )
124
+ await mockBackend . connectedPromise
125
+ } catch ( err ) {
126
+ console . error ( `Error launching mock backend for e2e test setup ${ err } ` )
127
+ }
128
+ }
129
+
118
130
export default function setup ( timeout = 120000 ) : void {
131
+ test . beforeAll ( async ( ) => {
132
+ await launchMockBackend ( )
133
+ } )
134
+
119
135
test . beforeEach ( async ( ) => {
120
136
test . setTimeout ( timeout )
121
137
await launchApp ( )
122
138
} )
123
139
124
140
test . afterEach ( async ( ) => {
125
- await electronApp . close ( )
141
+ try {
142
+ await electronApp ?. close ( )
143
+ } catch ( err ) {
144
+ console . error (
145
+ `Error while closing electron app in after each hook ${ err } `
146
+ )
147
+ }
126
148
} )
127
149
}
0 commit comments