Skip to content

Commit

Permalink
test: improve
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jan 23, 2024
1 parent 017dd9d commit b087461
Show file tree
Hide file tree
Showing 8 changed files with 409 additions and 88 deletions.
13 changes: 11 additions & 2 deletions test/e2e/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const webpack = require("webpack");
const Server = require("../../lib/Server");
const config = require("../fixtures/client-config/webpack.config");
const runBrowser = require("../helpers/run-browser");
const sessionSubscribe = require("../helpers/session-subscribe");
const port = require("../ports-map").api;

describe("API", () => {
Expand Down Expand Up @@ -697,12 +698,20 @@ describe("API", () => {
});

const webSocketRequests = [];
const client = page._client;
const session = await page.target().createCDPSession();

client.on("Network.webSocketCreated", (test) => {
session.on("Network.webSocketCreated", (test) => {
webSocketRequests.push(test);
});

await session.send("Target.setAutoAttach", {
autoAttach: true,
flatten: true,
waitForDebuggerOnStart: true,
});

sessionSubscribe(session);

const response = await page.goto(`http://127.0.0.1:${port}/`, {
waitUntil: "networkidle0",
});
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/built-in-routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ describe("Built in routes", () => {
});

it("should handles HEAD request to sockjs bundle", async () => {
await page.setRequestInterception(true);

page
.on("console", (message) => {
consoleMessages.push(message);
Expand All @@ -73,7 +71,9 @@ describe("Built in routes", () => {
pageErrors.push(error);
})
.on("request", (interceptedRequest) => {
interceptedRequest.continue({ method: "HEAD" });
if (interceptedRequest.isInterceptResolutionHandled()) return;

interceptedRequest.continue({ method: "HEAD" }, 10);
});

const response = await page.goto(
Expand Down Expand Up @@ -155,8 +155,6 @@ describe("Built in routes", () => {
});

it("should handle HEAD request to directory index", async () => {
await page.setRequestInterception(true);

page
.on("console", (message) => {
consoleMessages.push(message);
Expand All @@ -165,6 +163,8 @@ describe("Built in routes", () => {
pageErrors.push(error);
})
.on("request", (interceptedRequest) => {
if (interceptedRequest.isInterceptResolutionHandled()) return;

interceptedRequest.continue({ method: "HEAD" });
});

Expand Down Expand Up @@ -215,8 +215,6 @@ describe("Built in routes", () => {
});

it("should handle HEAD request to magic async chunk", async () => {
await page.setRequestInterception(true);

page
.on("console", (message) => {
consoleMessages.push(message);
Expand All @@ -225,6 +223,8 @@ describe("Built in routes", () => {
pageErrors.push(error);
})
.on("request", (interceptedRequest) => {
if (interceptedRequest.isInterceptResolutionHandled()) return;

interceptedRequest.continue({ method: "HEAD" });
});

Expand Down
37 changes: 31 additions & 6 deletions test/e2e/ipc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const httpProxy = require("http-proxy");
const Server = require("../../lib/Server");
const config = require("../fixtures/client-config/webpack.config");
const runBrowser = require("../helpers/run-browser");
const sessionSubscribe = require("../helpers/session-subscribe");
const port1 = require("../ports-map").ipc;

const webSocketServers = ["ws", "sockjs"];
Expand Down Expand Up @@ -72,11 +73,19 @@ describe("web socket server URL", () => {
const webSocketRequests = [];

if (webSocketServer === "ws") {
const client = page._client;
const session = await page.target().createCDPSession();

client.on("Network.webSocketCreated", (test) => {
session.on("Network.webSocketCreated", (test) => {
webSocketRequests.push(test);
});

await session.send("Target.setAutoAttach", {
autoAttach: true,
flatten: true,
waitForDebuggerOnStart: true,
});

sessionSubscribe(session);
} else {
page.on("request", (request) => {
if (/\/ws\//.test(request.url())) {
Expand Down Expand Up @@ -168,11 +177,19 @@ describe("web socket server URL", () => {
const webSocketRequests = [];

if (webSocketServer === "ws") {
const client = page._client;
const session = await page.target().createCDPSession();

client.on("Network.webSocketCreated", (test) => {
session.on("Network.webSocketCreated", (test) => {
webSocketRequests.push(test);
});

await session.send("Target.setAutoAttach", {
autoAttach: true,
flatten: true,
waitForDebuggerOnStart: true,
});

sessionSubscribe(session);
} else {
page.on("request", (request) => {
if (/\/ws\//.test(request.url())) {
Expand Down Expand Up @@ -279,11 +296,19 @@ describe("web socket server URL", () => {
const webSocketRequests = [];

if (webSocketServer === "ws") {
const client = page._client;
const session = await page.target().createCDPSession();

client.on("Network.webSocketCreated", (test) => {
session.on("Network.webSocketCreated", (test) => {
webSocketRequests.push(test);
});

await session.send("Target.setAutoAttach", {
autoAttach: true,
flatten: true,
waitForDebuggerOnStart: true,
});

sessionSubscribe(session);
} else {
page.on("request", (request) => {
if (/\/ws\//.test(request.url())) {
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/progress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ describe("progress", () => {
.on("console", (message) => {
consoleMessages.push(message);
})
.on("request", (requestObj) => {
if (/\.hot-update\.(json|js)$/.test(requestObj.url())) {
.on("request", (interceptedRequest) => {
if (interceptedRequest.isInterceptResolutionHandled()) return;

if (/\.hot-update\.(json|js)$/.test(interceptedRequest.url())) {
doHotUpdate = true;
}
});
Expand Down
Loading

0 comments on commit b087461

Please sign in to comment.