Skip to content

Commit ba0a2fc

Browse files
committedJan 23, 2024
test: fix
1 parent b087461 commit ba0a2fc

File tree

3 files changed

+50
-33
lines changed

3 files changed

+50
-33
lines changed
 

‎test/e2e/api.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ describe("API", () => {
257257

258258
await server.start();
259259

260-
const secondPage = await browser.newPage();
260+
const secondPage = await runBrowser.runPage(browser);
261+
261262
try {
262263
const secondPageErrors = [];
263264
const secondConsoleMessages = [];

‎test/e2e/static-public-path.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,6 @@ describe("static.publicPath option", () => {
672672
});
673673

674674
it("should handle HEAD request", async () => {
675-
await page.setRequestInterception(true);
676-
677675
page
678676
.on("console", (message) => {
679677
consoleMessages.push(message);
@@ -682,6 +680,8 @@ describe("static.publicPath option", () => {
682680
pageErrors.push(error);
683681
})
684682
.on("request", (interceptedRequest) => {
683+
if (interceptedRequest.isInterceptResolutionHandled()) return;
684+
685685
interceptedRequest.continue({ method: "HEAD" });
686686
});
687687

‎test/helpers/run-browser.js

+46-30
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ const { puppeteerArgs } = require("./puppeteer-constants");
1414
* @returns {Promise<RunBrowserResult>}
1515
*/
1616
function runBrowser(config) {
17-
const options = {
18-
viewport: {
19-
width: 500,
20-
height: 500,
21-
},
22-
userAgent: "",
23-
...config,
24-
};
25-
2617
return new Promise((resolve, reject) => {
2718
/**
2819
* @type {import('puppeteer').Page}
@@ -44,35 +35,60 @@ function runBrowser(config) {
4435
.then((launchedBrowser) => {
4536
browser = launchedBrowser;
4637

47-
return browser.newPage();
38+
return runPage(launchedBrowser, config);
4839
})
4940
.then((newPage) => {
5041
page = newPage;
51-
page.emulate(options);
52-
53-
return page.setRequestInterception(true);
54-
})
55-
.then(() => {
56-
page.on("request", (interceptedRequest) => {
57-
if (interceptedRequest.isInterceptResolutionHandled()) return;
58-
if (interceptedRequest.url().includes("favicon.ico")) {
59-
interceptedRequest.respond({
60-
status: 200,
61-
contentType: "image/png",
62-
body: "Empty",
63-
});
64-
} else {
65-
interceptedRequest.continue(
66-
interceptedRequest.continueRequestOverrides(),
67-
10,
68-
);
69-
}
70-
});
7142

7243
resolve({ page, browser });
7344
})
7445
.catch(reject);
7546
});
7647
}
7748

49+
function runPage(browser, config) {
50+
/**
51+
* @type {import('puppeteer').Page}
52+
*/
53+
let page;
54+
55+
const options = {
56+
viewport: {
57+
width: 500,
58+
height: 500,
59+
},
60+
userAgent: "",
61+
...config,
62+
};
63+
64+
return Promise.resolve()
65+
.then(() => browser.newPage())
66+
.then((newPage) => {
67+
page = newPage;
68+
page.emulate(options);
69+
70+
return page.setRequestInterception(true);
71+
})
72+
.then(() => {
73+
page.on("request", (interceptedRequest) => {
74+
if (interceptedRequest.isInterceptResolutionHandled()) return;
75+
if (interceptedRequest.url().includes("favicon.ico")) {
76+
interceptedRequest.respond({
77+
status: 200,
78+
contentType: "image/png",
79+
body: "Empty",
80+
});
81+
} else {
82+
interceptedRequest.continue(
83+
interceptedRequest.continueRequestOverrides(),
84+
10,
85+
);
86+
}
87+
});
88+
89+
return page;
90+
});
91+
}
92+
7893
module.exports = runBrowser;
94+
module.exports.runPage = runPage;

0 commit comments

Comments
 (0)
Please sign in to comment.