Skip to content

Commit

Permalink
test(e2e): make browser close before tests run (#2018)
Browse files Browse the repository at this point in the history
  • Loading branch information
knagaitsev authored and evilebottnawi committed Jun 13, 2019
1 parent 1ecc425 commit f611304
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 44 deletions.
24 changes: 12 additions & 12 deletions test/e2e/Client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ describe('reload', () => {
return bgColor;
})
.then((color) => {
expect(color).toEqual('rgb(0, 0, 255)');

page.setRequestInterception(true).then(() => {
page.on('request', (req) => {
if (
Expand All @@ -66,8 +64,6 @@ describe('reload', () => {
'body { background-color: rgb(255, 0, 0); }'
);
page.waitFor(10000).then(() => {
expect(refreshed).toBeFalsy();

page
.evaluate(() => {
const body = document.body;
Expand All @@ -77,8 +73,12 @@ describe('reload', () => {
return bgColor;
})
.then((color2) => {
expect(color2).toEqual('rgb(255, 0, 0)');
browser.close().then(done);
browser.close().then(() => {
expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toBeFalsy();
done();
});
});
});
});
Expand Down Expand Up @@ -126,8 +126,6 @@ describe('reload', () => {
return bgColor;
})
.then((color) => {
expect(color).toEqual('rgb(0, 0, 255)');

page.setRequestInterception(true).then(() => {
page.on('request', (req) => {
if (
Expand All @@ -144,8 +142,6 @@ describe('reload', () => {
'body { background-color: rgb(255, 0, 0); }'
);
page.waitFor(10000).then(() => {
expect(refreshed).toBeTruthy();

page
.evaluate(() => {
const body = document.body;
Expand All @@ -155,8 +151,12 @@ describe('reload', () => {
return bgColor;
})
.then((color2) => {
expect(color2).toEqual('rgb(255, 0, 0)');
browser.close().then(done);
browser.close().then(() => {
expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toBeTruthy();
done();
});
});
});
});
Expand Down
72 changes: 44 additions & 28 deletions test/e2e/ClientOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ describe('Client code', () => {
page
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
.then((requestObj) => {
expect(
requestObj.url().includes(`http://localhost:${port1}/sockjs-node`)
).toBeTruthy();
browser.close().then(done);
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://localhost:${port1}/sockjs-node`)
).toBeTruthy();
done();
});
});
page.goto(`http://localhost:${port2}/main`);
});
Expand Down Expand Up @@ -105,12 +109,14 @@ describe('Client complex inline script path', () => {
requestObj.url().match(/foo\/test\/bar/)
)
.then((requestObj) => {
expect(
requestObj
.url()
.includes(`http://myhost.test:${port2}/foo/test/bar/`)
).toBeTruthy();
browser.close().then(done);
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://myhost.test:${port2}/foo/test/bar/`)
).toBeTruthy();
done();
});
});
page.goto(`http://localhost:${port2}/main`);
});
Expand Down Expand Up @@ -143,12 +149,14 @@ describe('Client complex inline script path with sockPort', () => {
requestObj.url().match(/foo\/test\/bar/)
)
.then((requestObj) => {
expect(
requestObj
.url()
.includes(`http://localhost:${port3}/foo/test/bar`)
).toBeTruthy();
browser.close().then(done);
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://localhost:${port3}/foo/test/bar`)
).toBeTruthy();
done();
});
});

page.goto(`http://localhost:${port2}/main`);
Expand Down Expand Up @@ -182,10 +190,14 @@ describe('Client complex inline script path with sockPort, no sockPath', () => {
page
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
.then((requestObj) => {
expect(
requestObj.url().includes(`http://localhost:${port3}/sockjs-node`)
).toBeTruthy();
browser.close().then(done);
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://localhost:${port3}/sockjs-node`)
).toBeTruthy();
done();
});
});
page.goto(`http://localhost:${port2}/main`);
});
Expand Down Expand Up @@ -215,12 +227,14 @@ describe('Client complex inline script path with sockHost', () => {
page
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
.then((requestObj) => {
expect(
requestObj
.url()
.includes(`http://myhost.test:${port2}/sockjs-node`)
).toBeTruthy();
browser.close().then(done);
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://myhost.test:${port2}/sockjs-node`)
).toBeTruthy();
done();
});
});
page.goto(`http://localhost:${port2}/main`);
});
Expand Down Expand Up @@ -286,8 +300,10 @@ describe('Client console.log', () => {
res.push(_text);
});
setTimeout(() => {
expect(res).toMatchSnapshot();
browser.close().then(resolve);
browser.close().then(() => {
expect(res).toMatchSnapshot();
resolve();
});
}, 1000);
});
})
Expand Down
12 changes: 8 additions & 4 deletions test/e2e/ProvidePlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ describe('ProvidePlugin', () => {
return window.injectedClient === window.expectedClient;
})
.then((isCorrectClient) => {
expect(isCorrectClient).toBeTruthy();
browser.close().then(done);
browser.close().then(() => {
expect(isCorrectClient).toBeTruthy();
done();
});
});
});
page.goto(`http://localhost:${port}/main`);
Expand Down Expand Up @@ -65,8 +67,10 @@ describe('ProvidePlugin', () => {
return window.injectedClient === undefined;
})
.then((isCorrectClient) => {
expect(isCorrectClient).toBeTruthy();
browser.close().then(done);
browser.close().then(() => {
expect(isCorrectClient).toBeTruthy();
done();
});
});
});
page.goto(`http://localhost:${port}/main`);
Expand Down

0 comments on commit f611304

Please sign in to comment.