Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(hub): Convert Session class to object and functions #5054

Merged
merged 15 commits into from
May 11, 2022
Merged
Prev Previous commit
Next Next commit
do not sessionToJSON
  • Loading branch information
Lms24 committed May 11, 2022
commit 2c65f63d6a3ad027d8070c117d8cdd5fc03c492c
2 changes: 1 addition & 1 deletion packages/hub/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type { Carrier, Layer } from './hub';

export { addGlobalEventProcessor, Scope } from './scope';
export { updateSession, closeSession, sessionToJSON } from './session';
export { updateSession, closeSession } from './session';
export { SessionFlusher } from './sessionflusher';
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, makeMain, setHubOnCarrier } from './hub';
export {
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function closeSession(session: Session, status?: Exclude<SessionStatus, '
*
* @returns a JSON object of the passed session
*/
export function sessionToJSON(session: Session): SerializedSession {
function sessionToJSON(session: Session): SerializedSession {
return dropUndefinedKeys({
sid: `${session.sid}`,
init: session.init !== undefined ? session.init : true,
Expand Down
8 changes: 4 additions & 4 deletions packages/hub/test/session.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { SessionContext } from '@sentry/types';
import { timestampInSeconds } from '@sentry/utils';

import { closeSession, makeSession, sessionToJSON, updateSession } from '../src/session';
import { closeSession, makeSession, updateSession } from '../src/session';

describe('Session', () => {
it('initializes with the proper defaults', () => {
const newSession = makeSession();
const session = sessionToJSON(newSession);
const session = newSession.toJSON();

// Grab current year to check if we are converting from sec -> ms correctly
const currentYear = new Date(timestampInSeconds() * 1000).toISOString().slice(0, 4);
Expand Down Expand Up @@ -84,10 +84,10 @@ describe('Session', () => {
const DEFAULT_OUT = { duration: expect.any(Number), timestamp: expect.any(String) };

const session = makeSession();
const initSessionProps = sessionToJSON(session);
const initSessionProps = session.toJSON();

updateSession(session, test[1]);
const updatedSessionProps = sessionToJSON(session);
const updatedSessionProps = session.toJSON();

expect(updatedSessionProps).toEqual({ ...initSessionProps, ...DEFAULT_OUT, ...test[2] });
});
Expand Down