Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions examples/with-one-login-per-subdomain/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ SuperTokensNode.init({
recipeList: [EmailVerification.init({ mode: "OPTIONAL" }), EmailPassword.init(), Session.init()],
});

const TEST_APPLICATION_SERVER_BASE_URL = "http://example.com:3001";

describe("SuperTokens Example Basic tests", function () {
let browser;
let page;
Expand All @@ -67,6 +69,76 @@ describe("SuperTokens Example Basic tests", function () {
headless: true,
});
page = await browser.newPage();
page.on("console", (msg) => {
if (msg.text().startsWith("com.supertokens")) {
console.log(msg.text());
} else {
console.log(
`browserlog.console ${JSON.stringify({
t: new Date().toISOString(),
message: msg.text(),
pageurl: page.url(),
})}`
);
}
});

page.on("request", (req) => {
console.log(
`browserlog.network ${JSON.stringify({
t: new Date().toISOString(),
message: `Requested: ${req.method()} ${req.url()} (${req.postData()})`,
pageurl: page.url(),
})}`
);
});
page.on("requestfinished", async (req) => {
if (req.method() === "OPTION") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HTTP method should be OPTIONS (with an 'S' at the end) rather than OPTION. This typo will prevent the condition from matching actual OPTIONS requests, causing them to be processed when they should be skipped.

Suggested change
if (req.method() === "OPTION") {
if (req.method() === "OPTIONS") {

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

return;
}
const resp = await req.response();
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;
}
console.log(
`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();
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;
}
Comment on lines +120 to +128
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When handling failed requests, resp could be null or undefined, which would cause errors when calling resp.status() or resp.text(). Consider adding a null check before accessing response properties:

const resp = await req.response();
let respText;

if (!resp) {
    respText = 'No response available';
} else {
    try {
        respText = req.url().startsWith(TEST_APPLICATION_SERVER_BASE_URL)
            ? await resp.text()
            : "response omitted";
    } catch (e) {
        respText = "response loading failed " + e.message;
    }
}

This will prevent potential runtime errors when processing failed requests.

Suggested change
const resp = await req.response();
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;
}
const resp = await req.response();
let respText;
if (!resp) {
respText = 'No response available';
} else {
try {
respText = req.url().startsWith(TEST_APPLICATION_SERVER_BASE_URL)
? await resp.text()
: "response omitted";
} catch (e) {
respText = "response loading failed " + e.message;
}
}

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

try {
console.log(
`browserlog.network ${JSON.stringify({
t: new Date().toISOString(),
message: `Request failed: ${req.method()} ${req.url()}: ${resp.status()} ${respText}`,
pageurl: page.url(),
})}`
);
} catch (e) {
console.log(e);
}
});
return page;
});

after(async function () {
Expand Down
Loading