From ffa1c729fe05a9563dd75d9ef922adf7fda58c12 Mon Sep 17 00:00:00 2001 From: Marcos Passos Date: Sat, 19 Nov 2022 19:57:30 -0400 Subject: [PATCH] Improve preview debug logs (#138) --- src/preview.ts | 4 ++++ test/preview.test.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/preview.ts b/src/preview.ts index 01c169b8..f5d51228 100644 --- a/src/preview.ts +++ b/src/preview.ts @@ -58,6 +58,8 @@ export class PreviewPlugin implements Plugin { private updateToken(data: string): void { if (data === PREVIEW_EXIT) { + this.logger.debug('Exiting preview mode.'); + this.tokenStore.setToken(null); return; @@ -68,6 +70,8 @@ export class PreviewPlugin implements Plugin { const {exp} = token.getPayload(); if (exp !== undefined && exp <= Date.now() / 1000) { + this.logger.debug('Preview token expired.'); + token = null; } diff --git a/test/preview.test.ts b/test/preview.test.ts index 88ac3f86..d4128c1b 100644 --- a/test/preview.test.ts +++ b/test/preview.test.ts @@ -157,6 +157,8 @@ describe('A Preview plugin', () => { expect(configuration.tokenStore.getToken()).toBe(null); expect(document.body.children.length).toBe(0); + + expect(configuration.logger.debug).toHaveBeenCalledWith('Preview token expired.'); }); it('should remove the stored token when leaving the preview', () => { @@ -172,8 +174,7 @@ describe('A Preview plugin', () => { expect(window.location.href).toBe('http://localhost/'); - expect(configuration.logger.warn).not - .toHaveBeenCalled(); + expect(configuration.logger.debug).toHaveBeenCalledWith('Exiting preview mode.'); }); it('should log invalid token', () => {