Skip to content

Commit be84c4f

Browse files
snitin315alexander-akait
authored andcommitted
test: refactor port tests to cleanup properly (#4914)
1 parent a2c09f5 commit be84c4f

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

test/e2e/port.test.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ describe("port", () => {
5656
`options.port should be >= 0 and < 65536`
5757
);
5858

59-
expect(errored.message).toMatch(errorMessageRegExp);
60-
61-
await server.stop();
59+
try {
60+
expect(errored.message).toMatch(errorMessageRegExp);
61+
} catch (error) {
62+
throw error;
63+
} finally {
64+
await server.stop();
65+
}
6266

6367
return;
6468
}
@@ -73,28 +77,32 @@ describe("port", () => {
7377

7478
const { page, browser } = await runBrowser();
7579

76-
const pageErrors = [];
77-
const consoleMessages = [];
78-
79-
page
80-
.on("console", (message) => {
81-
consoleMessages.push(message);
82-
})
83-
.on("pageerror", (error) => {
84-
pageErrors.push(error);
80+
try {
81+
const pageErrors = [];
82+
const consoleMessages = [];
83+
84+
page
85+
.on("console", (message) => {
86+
consoleMessages.push(message);
87+
})
88+
.on("pageerror", (error) => {
89+
pageErrors.push(error);
90+
});
91+
92+
await page.goto(`http://127.0.0.1:${address.port}/`, {
93+
waitUntil: "networkidle0",
8594
});
8695

87-
await page.goto(`http://127.0.0.1:${address.port}/`, {
88-
waitUntil: "networkidle0",
89-
});
90-
91-
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
92-
"console messages"
93-
);
94-
expect(pageErrors).toMatchSnapshot("page errors");
95-
96-
await browser.close();
97-
await server.stop();
96+
expect(
97+
consoleMessages.map((message) => message.text())
98+
).toMatchSnapshot("console messages");
99+
expect(pageErrors).toMatchSnapshot("page errors");
100+
} catch (error) {
101+
throw error;
102+
} finally {
103+
await browser.close();
104+
await server.stop();
105+
}
98106

99107
if (
100108
testedPort === "<not-specified>" ||

0 commit comments

Comments
 (0)