Skip to content

Commit

Permalink
Improve preview debug logs (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos authored Nov 19, 2022
1 parent f467c0d commit ffa1c72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions test/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit ffa1c72

Please sign in to comment.