Skip to content

Commit

Permalink
Bugfix: Jest test failures not surfaced in pipeline (#739)
Browse files Browse the repository at this point in the history
* Switched to using sfdx-lwc-jest for running Jest tests - using 'sf force lightning lwc test run' returns 0 exit code for failures :'(

* Fixed some failing Jest tests for logger LWC - these were previously failing due to some asserts being out of date due to the changes made in release v4.13.17, but weren't being reported by the pipeline
  • Loading branch information
jongpie authored Aug 22, 2024
1 parent 6664ed1 commit 17c6b7a
Show file tree
Hide file tree
Showing 9 changed files with 48,945 additions and 55,983 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.

## Unlocked Package - v4.14.1
## Unlocked Package - v4.14.2

[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oQPQAY)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oQPQAY)
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oQZQAY)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oQZQAY)
[![View Documentation](./images/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/)

`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015oQPQAY`
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015oQZQAY`

`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015oQPQAY`
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015oQZQAY`

---

Expand Down
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
'^lightning/empApi$': '<rootDir>/config/jest/mocks/lightning/empApi',
'^lightning/navigation$': '<rootDir>/config/jest/mocks/lightning/navigation'
},
modulePathIgnorePatterns: ['recipes']
modulePathIgnorePatterns: ['recipes'],
testPathIgnorePatterns: ['<rootDir>/temp/']
};
2 changes: 1 addition & 1 deletion nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
global with sharing class Logger {
// There's no reliable way to get the version number dynamically in Apex
@TestVisible
private static final String CURRENT_VERSION_NUMBER = 'v4.14.1';
private static final String CURRENT_VERSION_NUMBER = 'v4.14.2';
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createElement } from 'lwc';
import FORM_FACTOR from '@salesforce/client/formFactor';
import { LoggerStackTrace } from '../loggerStackTrace';
// Recommended approach
import { createLogger } from 'c/logger';
// Legacy approach
Expand Down Expand Up @@ -186,7 +187,7 @@ describe('logger lwc import tests', () => {
logEntryBuilder.setError(error);

expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual('JavaScript.TypeError');
});

Expand All @@ -211,7 +212,7 @@ describe('logger lwc import tests', () => {
logEntryBuilder.setError(error);

expect(logEntry.error.message).toEqual(error.body.message);
expect(logEntry.error.stack).toEqual(error.body.stackTrace);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual(error.body.exceptionType);
});

Expand Down Expand Up @@ -264,15 +265,15 @@ describe('logger lwc import tests', () => {

await flushPromises();
expect(logger.getBufferSize()).toEqual(0);
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual('JavaScript.TypeError');
expect(logEntry.loggingLevel).toEqual('ERROR');
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
expect(logEntry.timestamp).toBeTruthy();
});

it('still works for WARN logging level when disabled when using recommended import approach', async () => {
Expand All @@ -294,15 +295,15 @@ describe('logger lwc import tests', () => {

await flushPromises();
expect(logger.getBufferSize()).toEqual(0);
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual('JavaScript.TypeError');
expect(logEntry.loggingLevel).toEqual('WARN');
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
expect(logEntry.timestamp).toBeTruthy();
});

it('still works for INFO logging level when disabled when using recommended import approach', async () => {
Expand All @@ -324,15 +325,15 @@ describe('logger lwc import tests', () => {

await flushPromises();
expect(logger.getBufferSize()).toEqual(0);
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual('JavaScript.TypeError');
expect(logEntry.loggingLevel).toEqual('INFO');
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
expect(logEntry.timestamp).toBeTruthy();
});

it('still works for DEBUG logging level when disabled when using recommended import approach', async () => {
Expand All @@ -354,15 +355,15 @@ describe('logger lwc import tests', () => {

await flushPromises();
expect(logger.getBufferSize()).toEqual(0);
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual('JavaScript.TypeError');
expect(logEntry.loggingLevel).toEqual('DEBUG');
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
expect(logEntry.timestamp).toBeTruthy();
});

it('still works for FINE logging level when disabled when using recommended import approach', async () => {
Expand All @@ -384,15 +385,15 @@ describe('logger lwc import tests', () => {

await flushPromises();
expect(logger.getBufferSize()).toEqual(0);
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual('JavaScript.TypeError');
expect(logEntry.loggingLevel).toEqual('FINE');
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
expect(logEntry.timestamp).toBeTruthy();
});

it('still works for FINER logging level when disabled when using recommended import approach', async () => {
Expand All @@ -414,15 +415,15 @@ describe('logger lwc import tests', () => {

await flushPromises();
expect(logger.getBufferSize()).toEqual(0);
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual('JavaScript.TypeError');
expect(logEntry.loggingLevel).toEqual('FINER');
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
expect(logEntry.timestamp).toBeTruthy();
});

it('still works for FINEST logging level when disabled when using recommended import approach', async () => {
Expand All @@ -444,15 +445,15 @@ describe('logger lwc import tests', () => {

await flushPromises();
expect(logger.getBufferSize()).toEqual(0);
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual('JavaScript.TypeError');
expect(logEntry.loggingLevel).toEqual('FINEST');
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
expect(logEntry.timestamp).toBeTruthy();
});

it('flushes buffer when using recommended import approach', async () => {
Expand Down Expand Up @@ -668,7 +669,7 @@ describe('logger lwc legacy markup tests', () => {
logEntryBuilder.setError(error);

expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.error.type).toEqual('JavaScript.TypeError');
});

Expand All @@ -695,7 +696,7 @@ describe('logger lwc legacy markup tests', () => {
logEntryBuilder.setError(error);

expect(logEntry.error.message).toEqual(error.body.message);
expect(logEntry.error.stack).toEqual(error.body.stackTrace);
expect(logEntry.error.stackTrace).toEqual(error.body.stackTrace);
expect(logEntry.error.type).toEqual(error.body.exceptionType);
});

Expand Down Expand Up @@ -757,9 +758,9 @@ describe('logger lwc legacy markup tests', () => {
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
});
Expand Down Expand Up @@ -788,9 +789,9 @@ describe('logger lwc legacy markup tests', () => {
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
});
Expand Down Expand Up @@ -819,9 +820,9 @@ describe('logger lwc legacy markup tests', () => {
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
});
Expand Down Expand Up @@ -850,9 +851,9 @@ describe('logger lwc legacy markup tests', () => {
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
});
Expand Down Expand Up @@ -881,9 +882,9 @@ describe('logger lwc legacy markup tests', () => {
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
});
Expand Down Expand Up @@ -919,9 +920,9 @@ describe('logger lwc legacy markup tests', () => {
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
});
Expand Down Expand Up @@ -951,9 +952,9 @@ describe('logger lwc legacy markup tests', () => {
expect(logEntry.recordId).toEqual('some_record_Id');
expect(logEntry.record).toEqual({ Id: 'some_record_Id' });
expect(logEntry.error).toBeTruthy();
expect(logEntry.stack).toBeTruthy();
expect(logEntry.originStackTrace).toBeTruthy();
expect(logEntry.error.message).toEqual(error.message);
expect(logEntry.error.stack).toEqual(error.stack);
expect(logEntry.error.stackTrace).toBeTruthy();
expect(logEntry.timestamp).toBeTruthy();
expect(logEntry.tags).toEqual(['a tag', 'a second tag', 'a third tag']);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import FORM_FACTOR from '@salesforce/client/formFactor';
import { LoggerStackTrace } from './loggerStackTrace';

const CURRENT_VERSION_NUMBER = 'v4.14.1';
const CURRENT_VERSION_NUMBER = 'v4.14.2';

const LOGGING_LEVEL_EMOJIS = {
ERROR: '⛔',
Expand Down Expand Up @@ -132,7 +132,7 @@ const LogEntryBuilder = class {
this.#componentLogEntry.error = {};
if (error.body) {
this.#componentLogEntry.error.message = error.body.message;
this.#componentLogEntry.error.stack = error.body.stackTrace;
this.#componentLogEntry.error.stackTrace = error.body.stackTrace;
this.#componentLogEntry.error.type = error.body.exceptionType;
} else {
this.#componentLogEntry.error.message = error.message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ const LoggerService = class {
}

_newEntry(loggingLevel, message, originStackTraceError) {
const logEntryBuilder = newLogEntry(loggingLevel, this.#settings?.isConsoleLoggingEnabled);
originStackTraceError = originStackTraceError ?? new Error();
const logEntryBuilder = newLogEntry(loggingLevel, this.#settings?.isConsoleLoggingEnabled)
.parseStackTrace(originStackTraceError)
.setMessage(message)
.setScenario(this.#scenario);
if (this._meetsUserLoggingLevel(loggingLevel)) {
originStackTraceError = originStackTraceError ?? new Error();
logEntryBuilder.parseStackTrace(originStackTraceError).setMessage(message);
logEntryBuilder.setScenario(this.#scenario);
this.#componentLogEntries.push(logEntryBuilder.getComponentLogEntry());
}

Expand Down
Loading

0 comments on commit 17c6b7a

Please sign in to comment.