Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 committed Oct 1, 2024
1 parent 63c6e35 commit eee7a8b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/utils/fetchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { buildReleaseNotesUrl } from "./envUtils";
* @throws An error if the fetch request fails
*/
export const fetchReleaseNotes = async (signal?: AbortSignal): Promise<string> => {
if (sessionStorage.getItem("releaseNotes")) {
return sessionStorage.getItem("releaseNotes");
const cachedNotes = sessionStorage.getItem("releaseNotes");
if (cachedNotes) {
return cachedNotes;
}

const url: string = buildReleaseNotesUrl();
Expand Down
13 changes: 13 additions & 0 deletions src/utils/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,17 @@ describe("Logger", () => {

expect(consoleErrorSpy).not.toHaveBeenCalled();
});

it.each<AppEnv["REACT_APP_DEV_TIER"]>(["stage", "prod"])(
"should not log on the upper tier '%s'",
(tier) => {
env.NODE_ENV = "development"; // Override 'test' to log the message

env.REACT_APP_DEV_TIER = tier;

Logger.error("A message that should not be visible");

expect(consoleErrorSpy).not.toHaveBeenCalled();
}
);
});
7 changes: 6 additions & 1 deletion src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ export type LogLevel = "error";
* @returns void
*/
const LoggingWrapper = (level: LogLevel, message: string, ...optionalParams: unknown[]): void => {
// Skip logging in a test environment.
// Skip logging in a testing context.
if (env?.NODE_ENV === "test") {
return;
}

// Skip logging on stage or production environments.
if (env?.REACT_APP_DEV_TIER === "prod" || env?.REACT_APP_DEV_TIER === "stage") {
return;
}

const timestamp = new Date().toISOString();
switch (level) {
case "error":
Expand Down

0 comments on commit eee7a8b

Please sign in to comment.