Skip to content

Commit

Permalink
feat: Add debug logs (#118)
Browse files Browse the repository at this point in the history
* Add logger

* Add option to enable logging

* Add debug logs for fetch

* Add debug logs for remaining fetch helpers

* Add debug logs to frontToken

* Add debug logs to utils

* Add logging to AntiCSRF

* Add debug logs to recipeImplementation

* Add debug logs to axios

* Update build files

* Update changelog

* Update version

* Review fixes

* Fix typo in logs

* Update build files

* Add test for logger

* Update size limit

* Move unreleased changes to latest release in Changelog
  • Loading branch information
prateek3255 authored Jan 3, 2024
1 parent 7d32ca1 commit bac45ad
Show file tree
Hide file tree
Showing 24 changed files with 547 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

## [4.1.0] - 2024-01-03

- Added debug logs to the SDK
- Update contributing Prerequisites
- Remove unused ESLint and Prettier config files from TestingApp

Expand Down
62 changes: 62 additions & 0 deletions TestingApp/test/logger.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
const tough = require("tough-cookie");
import SuperTokens from "supertokens-react-native";
import { disableLogging } from "supertokens-react-native/lib/build/logger";
// jest does not call setupFiles properly with the new react-native init, so doing it this way instead
import "./setup";

process.env.TEST_MODE = "testing";

describe("Logger test", () => {
const consoleSpy = jest.spyOn(console, "log");

beforeEach(() => {
disableLogging();
let nodeFetch = require("node-fetch").default;
const fetch = require("fetch-cookie")(nodeFetch, new tough.CookieJar());
global.fetch = fetch;
});

afterEach(() => {
jest.clearAllMocks();
});

it("should log to console when debug logging is enabled", async () => {
SuperTokens.init({
apiDomain: "http://localhost:3000",
enableDebugLogs: true
});

expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("init: called"));
});

it("should not log to console when debug logging is disabled", async () => {
SuperTokens.init({
apiDomain: "http://localhost:3000",
enableDebugLogs: false
});

expect(consoleSpy).not.toHaveBeenCalledWith(expect.stringContaining("init: called"));
});

it("should not log to console when no argument is passed for enableDebugLogs", async () => {
SuperTokens.init({
apiDomain: "http://localhost:3000"
});

expect(consoleSpy).not.toHaveBeenCalledWith(expect.stringContaining("init: called"));
});
});
14 changes: 14 additions & 0 deletions lib/build/antiCsrf.js

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

Loading

0 comments on commit bac45ad

Please sign in to comment.