-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #518 by calling saveLog() as soon as createLogger() has finishe…
…d loading for pending log messages.
- Loading branch information
1 parent
4ede2fb
commit 0548fdd
Showing
6 changed files
with
153 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
nebula-logger/extra-tests/lwc/loggerDemo/__tests__/loggerDemo.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createElement } from 'lwc'; | ||
import LoggerDemo from 'c/loggerDemo'; | ||
|
||
import getSettings from '@salesforce/apex/ComponentLogger.getSettings'; | ||
|
||
const flushPromises = async () => { | ||
await new Promise(process.nextTick); | ||
}; | ||
|
||
const MOCK_GET_SETTINGS = { | ||
defaultSaveMethod: 'EVENT_BUS', | ||
isEnabled: true, | ||
isConsoleLoggingEnabled: true, | ||
supportedLoggingLevels: { FINEST: 2, FINER: 3, FINE: 4, DEBUG: 5, INFO: 6, WARN: 7, ERROR: 8 }, | ||
userLoggingLevel: { ordinal: 2, name: 'FINEST' } | ||
}; | ||
|
||
jest.mock( | ||
'@salesforce/apex/ComponentLogger.getSettings', | ||
() => { | ||
return { | ||
default: jest.fn() | ||
}; | ||
}, | ||
{ virtual: true } | ||
); | ||
|
||
describe('logger demo tests', () => { | ||
afterEach(() => { | ||
while (document.body.firstChild) { | ||
document.body.removeChild(document.body.firstChild); | ||
} | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('mounts and saves log correctly in one go', async () => { | ||
getSettings.mockResolvedValue({ ...MOCK_GET_SETTINGS }); | ||
const demo = createElement('c-logger-demo', { is: LoggerDemo }); | ||
document.body.appendChild(demo); | ||
|
||
await flushPromises(); | ||
|
||
expect(demo.logger?.getBufferSize()).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!-- | ||
//------------------------------------------------------------------------------------------------// | ||
// This file is part of the Nebula Logger project, released under the MIT License. // | ||
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // | ||
//------------------------------------------------------------------------------------------------// | ||
--> | ||
|
||
<template> | ||
<lightning-card title="Example"> | ||
<div> | ||
✅ This component demonstrates how to use Nebula Logger by using <code>import { createLogger } from 'c/logger';</code> in your component's | ||
JavaScript file. This approach was introduced in Nebula Logger v4.10.2, and is now the recommended approach. | ||
</div> | ||
</lightning-card> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//------------------------------------------------------------------------------------------------// | ||
// This file is part of the Nebula Logger project, released under the MIT License. // | ||
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // | ||
//------------------------------------------------------------------------------------------------// | ||
|
||
/* eslint-disable no-console */ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
import { createLogger } from 'c/logger'; | ||
|
||
export default class LoggerDemo extends LightningElement { | ||
@api | ||
logger; | ||
|
||
connectedCallback() { | ||
this.logger = createLogger(); | ||
console.log('>>> start of connectedCallback()'); | ||
try { | ||
throw new Error('A bad thing happened here'); | ||
} catch (error) { | ||
this.logger.error('>>> connectedCallback error: ' + JSON.stringify(error)); | ||
this.logger.saveLog().then(() => { | ||
console.log('done with async save'); | ||
}); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
nebula-logger/extra-tests/lwc/loggerDemo/loggerDemo.js-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>58.0</apiVersion> | ||
<isExposed>true</isExposed> | ||
<targets> | ||
<target>lightning__Tab</target> | ||
</targets> | ||
</LightningComponentBundle> |