Skip to content

Commit

Permalink
test: improve request logging in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Sep 30, 2024
1 parent f34e0c2 commit dda8292
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
38 changes: 25 additions & 13 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,27 +798,39 @@ export async function setupBrowser() {
);
});
page.on("requestfinished", async (req) => {
if (req.method() === "OPTION") {
return;
}
const resp = await req.response();
let respText;
try {
const resp = await req.response();
const respText = req.url().startsWith(TEST_APPLICATION_SERVER_BASE_URL)
respText = req.url().startsWith(TEST_APPLICATION_SERVER_BASE_URL)
? await resp.text()
: "response omitted";
addLog(
`browserlog.network ${JSON.stringify({
t: new Date().toISOString(),
message: `Request done: ${req.method()} ${req.url()}: ${resp.status()} ${respText}`,
pageurl: page.url(),
})}`
);
} catch (e) {
console.log("requestfinished err", req.url(), e);
respText = "response loading failed " + e.message;
}
addLog(
`browserlog.network ${JSON.stringify({
t: new Date().toISOString(),
message: `Request done: ${req.method()} ${req.url()}: ${resp.status()} ${respText}`,
pageurl: page.url(),
})}`
);
});
page.on("requestfailed", async (req) => {
if (req.method() === "OPTION") {
return;
}
const resp = await req.response();
const respText = req.url().startsWith(TEST_APPLICATION_SERVER_BASE_URL)
? await resp.text()
: "response omitted";
let respText;
try {
respText = req.url().startsWith(TEST_APPLICATION_SERVER_BASE_URL)
? await resp.text()
: "response omitted";
} catch (e) {
respText = "response loading failed " + e.message;
}
addLog(
`browserlog.network ${JSON.stringify({
t: new Date().toISOString(),
Expand Down
2 changes: 1 addition & 1 deletion test/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ let axios = require("axios").default;
module.exports.executeCommand = async function (cmd) {
return new Promise((resolve, reject) => {
exec(cmd, (err, stdout, stderr) => {
console.log(err, stderr, stdout);
if (err) {
console.log({ err });
reject(err);
return;
}
Expand Down

0 comments on commit dda8292

Please sign in to comment.