Skip to content

Commit f611304

Browse files
knagaitsevevilebottnawi
authored andcommitted
test(e2e): make browser close before tests run (#2018)
1 parent 1ecc425 commit f611304

File tree

3 files changed

+64
-44
lines changed

3 files changed

+64
-44
lines changed

test/e2e/Client.test.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ describe('reload', () => {
4848
return bgColor;
4949
})
5050
.then((color) => {
51-
expect(color).toEqual('rgb(0, 0, 255)');
52-
5351
page.setRequestInterception(true).then(() => {
5452
page.on('request', (req) => {
5553
if (
@@ -66,8 +64,6 @@ describe('reload', () => {
6664
'body { background-color: rgb(255, 0, 0); }'
6765
);
6866
page.waitFor(10000).then(() => {
69-
expect(refreshed).toBeFalsy();
70-
7167
page
7268
.evaluate(() => {
7369
const body = document.body;
@@ -77,8 +73,12 @@ describe('reload', () => {
7773
return bgColor;
7874
})
7975
.then((color2) => {
80-
expect(color2).toEqual('rgb(255, 0, 0)');
81-
browser.close().then(done);
76+
browser.close().then(() => {
77+
expect(color).toEqual('rgb(0, 0, 255)');
78+
expect(color2).toEqual('rgb(255, 0, 0)');
79+
expect(refreshed).toBeFalsy();
80+
done();
81+
});
8282
});
8383
});
8484
});
@@ -126,8 +126,6 @@ describe('reload', () => {
126126
return bgColor;
127127
})
128128
.then((color) => {
129-
expect(color).toEqual('rgb(0, 0, 255)');
130-
131129
page.setRequestInterception(true).then(() => {
132130
page.on('request', (req) => {
133131
if (
@@ -144,8 +142,6 @@ describe('reload', () => {
144142
'body { background-color: rgb(255, 0, 0); }'
145143
);
146144
page.waitFor(10000).then(() => {
147-
expect(refreshed).toBeTruthy();
148-
149145
page
150146
.evaluate(() => {
151147
const body = document.body;
@@ -155,8 +151,12 @@ describe('reload', () => {
155151
return bgColor;
156152
})
157153
.then((color2) => {
158-
expect(color2).toEqual('rgb(255, 0, 0)');
159-
browser.close().then(done);
154+
browser.close().then(() => {
155+
expect(color).toEqual('rgb(0, 0, 255)');
156+
expect(color2).toEqual('rgb(255, 0, 0)');
157+
expect(refreshed).toBeTruthy();
158+
done();
159+
});
160160
});
161161
});
162162
});

test/e2e/ClientOptions.test.js

+44-28
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ describe('Client code', () => {
6969
page
7070
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
7171
.then((requestObj) => {
72-
expect(
73-
requestObj.url().includes(`http://localhost:${port1}/sockjs-node`)
74-
).toBeTruthy();
75-
browser.close().then(done);
72+
browser.close().then(() => {
73+
expect(
74+
requestObj
75+
.url()
76+
.includes(`http://localhost:${port1}/sockjs-node`)
77+
).toBeTruthy();
78+
done();
79+
});
7680
});
7781
page.goto(`http://localhost:${port2}/main`);
7882
});
@@ -105,12 +109,14 @@ describe('Client complex inline script path', () => {
105109
requestObj.url().match(/foo\/test\/bar/)
106110
)
107111
.then((requestObj) => {
108-
expect(
109-
requestObj
110-
.url()
111-
.includes(`http://myhost.test:${port2}/foo/test/bar/`)
112-
).toBeTruthy();
113-
browser.close().then(done);
112+
browser.close().then(() => {
113+
expect(
114+
requestObj
115+
.url()
116+
.includes(`http://myhost.test:${port2}/foo/test/bar/`)
117+
).toBeTruthy();
118+
done();
119+
});
114120
});
115121
page.goto(`http://localhost:${port2}/main`);
116122
});
@@ -143,12 +149,14 @@ describe('Client complex inline script path with sockPort', () => {
143149
requestObj.url().match(/foo\/test\/bar/)
144150
)
145151
.then((requestObj) => {
146-
expect(
147-
requestObj
148-
.url()
149-
.includes(`http://localhost:${port3}/foo/test/bar`)
150-
).toBeTruthy();
151-
browser.close().then(done);
152+
browser.close().then(() => {
153+
expect(
154+
requestObj
155+
.url()
156+
.includes(`http://localhost:${port3}/foo/test/bar`)
157+
).toBeTruthy();
158+
done();
159+
});
152160
});
153161

154162
page.goto(`http://localhost:${port2}/main`);
@@ -182,10 +190,14 @@ describe('Client complex inline script path with sockPort, no sockPath', () => {
182190
page
183191
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
184192
.then((requestObj) => {
185-
expect(
186-
requestObj.url().includes(`http://localhost:${port3}/sockjs-node`)
187-
).toBeTruthy();
188-
browser.close().then(done);
193+
browser.close().then(() => {
194+
expect(
195+
requestObj
196+
.url()
197+
.includes(`http://localhost:${port3}/sockjs-node`)
198+
).toBeTruthy();
199+
done();
200+
});
189201
});
190202
page.goto(`http://localhost:${port2}/main`);
191203
});
@@ -215,12 +227,14 @@ describe('Client complex inline script path with sockHost', () => {
215227
page
216228
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
217229
.then((requestObj) => {
218-
expect(
219-
requestObj
220-
.url()
221-
.includes(`http://myhost.test:${port2}/sockjs-node`)
222-
).toBeTruthy();
223-
browser.close().then(done);
230+
browser.close().then(() => {
231+
expect(
232+
requestObj
233+
.url()
234+
.includes(`http://myhost.test:${port2}/sockjs-node`)
235+
).toBeTruthy();
236+
done();
237+
});
224238
});
225239
page.goto(`http://localhost:${port2}/main`);
226240
});
@@ -286,8 +300,10 @@ describe('Client console.log', () => {
286300
res.push(_text);
287301
});
288302
setTimeout(() => {
289-
expect(res).toMatchSnapshot();
290-
browser.close().then(resolve);
303+
browser.close().then(() => {
304+
expect(res).toMatchSnapshot();
305+
resolve();
306+
});
291307
}, 1000);
292308
});
293309
})

test/e2e/ProvidePlugin.test.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ describe('ProvidePlugin', () => {
3030
return window.injectedClient === window.expectedClient;
3131
})
3232
.then((isCorrectClient) => {
33-
expect(isCorrectClient).toBeTruthy();
34-
browser.close().then(done);
33+
browser.close().then(() => {
34+
expect(isCorrectClient).toBeTruthy();
35+
done();
36+
});
3537
});
3638
});
3739
page.goto(`http://localhost:${port}/main`);
@@ -65,8 +67,10 @@ describe('ProvidePlugin', () => {
6567
return window.injectedClient === undefined;
6668
})
6769
.then((isCorrectClient) => {
68-
expect(isCorrectClient).toBeTruthy();
69-
browser.close().then(done);
70+
browser.close().then(() => {
71+
expect(isCorrectClient).toBeTruthy();
72+
done();
73+
});
7074
});
7175
});
7276
page.goto(`http://localhost:${port}/main`);

0 commit comments

Comments
 (0)