Skip to content

Commit

Permalink
fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Oct 31, 2023
1 parent 3968f71 commit d44252c
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 24 deletions.
11 changes: 4 additions & 7 deletions lib/build/framework/fastify/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
// @ts-nocheck
/// <reference types="node" />
export type { SessionRequest } from "./framework";
export declare const plugin: import("fastify").FastifyPluginCallback<
Record<never, never>,
import("fastify").RawServerDefault
>;
export declare const plugin: import("fastify").FastifyPluginCallback<Record<never, never>, import("http").Server>;
export declare const errorHandler: () => (
err: any,
req: import("fastify").FastifyRequest<
import("fastify/types/route").RouteGenericInterface,
import("fastify").RawServerDefault,
import("http").Server,
import("http").IncomingMessage
>,
res: import("fastify").FastifyReply<
import("fastify").RawServerDefault,
import("http").Server,
import("http").IncomingMessage,
import("http").ServerResponse<import("http").IncomingMessage>,
import("http").ServerResponse,
import("fastify/types/route").RouteGenericInterface,
unknown
>
Expand Down
2 changes: 1 addition & 1 deletion lib/build/framework/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export declare function setCookieForServerResponse(
expires: number,
path: string,
sameSite: "strict" | "lax" | "none"
): ServerResponse<IncomingMessage>;
): ServerResponse;
export declare function getCookieValueToSetInHeader(
prev: string | string[] | undefined,
val: string | string[],
Expand Down
4 changes: 3 additions & 1 deletion lib/build/logger.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 14 additions & 7 deletions lib/build/logger.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions lib/build/supertokens.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 53 additions & 4 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,6 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () {

{
logs = [];
debug.disable();
STExpress.init({
supertokens: {
connectionURI,
Expand All @@ -1238,14 +1237,12 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () {
debug: false,
});
logDebugMessage("test message - should not be logged");
assert(debug.enabled(SUPERTOKENS_DEBUG_NAMESPACE) === false);
assert(logs.length === 0);
resetAll();
}

{
logs = [];
debug.disable();
STExpress.init({
supertokens: {
connectionURI,
Expand All @@ -1258,7 +1255,59 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () {
recipeList: [Session.init({ getTokenTransferMethod: () => "cookie" })],
});
logDebugMessage("test message - should not be logged");
assert(debug.enabled(SUPERTOKENS_DEBUG_NAMESPACE) === false);
assert(logs.length === 0);
resetAll();
}
});

it("testing that the debug mode is set via env var", async function () {
let oldEnv = process.env;
const connectionURI = await startST();
let logs = []; // Used to capture the log strings
debug.log = function (...args) {
logs.push(args);
};

{
process.env = { ...oldEnv, DEBUG: "com.supertokens" };
let debugManual = require("debug/src/common");
debugManual(debug);
STExpress.init({
supertokens: {
connectionURI,
},
appInfo: {
apiDomain: "api.supertokens.io",
appName: "SuperTokens",
websiteDomain: "supertokens.io",
},
recipeList: [Session.init({ getTokenTransferMethod: () => "cookie" })],
});
logDebugMessage("test message successfully logged");
assert(logs.length > 0);
const logMessage = logs[logs.length - 1].find((log) => log.includes("test message successfully logged"));
assert(logMessage !== undefined);
resetAll(false);
}

process.env = { ...oldEnv };
let debugManual = require("debug/src/common");
debugManual(debug);

{
logs = [];
STExpress.init({
supertokens: {
connectionURI,
},
appInfo: {
apiDomain: "api.supertokens.io",
appName: "SuperTokens",
websiteDomain: "supertokens.io",
},
recipeList: [Session.init({ getTokenTransferMethod: () => "cookie" })],
});
logDebugMessage("test message - should not be logged");
assert(logs.length === 0);
resetAll();
}
Expand Down
6 changes: 5 additions & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ let { maxVersion } = require("../lib/build/utils");
const { default: OpenIDRecipe } = require("../lib/build/recipe/openid/recipe");
const { wrapRequest } = require("../framework/express");
const { join } = require("path");
let debug = require("debug");

const users = require("./users.json");
let assert = require("assert");
Expand Down Expand Up @@ -249,7 +250,7 @@ module.exports.stopST = async function (pid) {
throw new Error("error while stopping ST with PID: " + pid);
};

module.exports.resetAll = function () {
module.exports.resetAll = function (disableLogging = true) {
SuperTokens.reset();
AccountLinkingRecipe.reset();
SessionRecipe.reset();
Expand All @@ -267,6 +268,9 @@ module.exports.resetAll = function () {
DashboardRecipe.reset();
ProcessState.getInstance().reset();
MultitenancyRecipe.reset();
if (disableLogging) {
debug.disable();
}
};

module.exports.killAllST = async function () {
Expand Down

0 comments on commit d44252c

Please sign in to comment.