This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Lf/message server graceful error #267
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,41 @@ | ||
import { CompileService } from '@webruntime/api'; | ||
import path from 'path'; | ||
|
||
const APEX_LWC_MESSAGE_SERVICE_REGEX = /^(@salesforce\/messageChannel\/.*)/; | ||
|
||
function matchesLWCMessageServiceScopedModule(id: string) { | ||
return id && id.match(APEX_LWC_MESSAGE_SERVICE_REGEX); | ||
} | ||
|
||
/** | ||
* Rollup plugin to resolve @salesforce/messageChannel | ||
* | ||
*/ | ||
function plugin() { | ||
return { | ||
name: 'rollup-plugin-lwc-message-service', | ||
|
||
resolveId(id: string) { | ||
return matchesLWCMessageServiceScopedModule(id) ? id : null; | ||
}, | ||
load(id: any) { | ||
const idParts = matchesLWCMessageServiceScopedModule(id); | ||
if (idParts) { | ||
throw new Error( | ||
"You can't preview a component using Lightning Message Service. Test the component directly in the org" | ||
); | ||
} | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
export class LWCMessageService implements CompileService { | ||
LisandroFernandezSF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getPlugin() { | ||
return plugin(); | ||
} | ||
|
||
async initialize() {} | ||
|
||
shutdown() {} | ||
} |
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,61 @@ | ||
import { LWCMessageService } from '../LWCMessageService'; | ||
import { getLatestVersion } from '@webruntime/server/dist/commonjs/utils/utils'; | ||
import { PublicConfig } from '@webruntime/api'; | ||
|
||
jest.mock('@webruntime/server/dist/commonjs/utils/utils'); | ||
|
||
describe('LWCMessageService', () => { | ||
let config: PublicConfig; | ||
|
||
beforeEach(() => { | ||
(getLatestVersion as jest.Mock).mockReturnValue('158104e2eb'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('returns a rollup plugin', () => { | ||
const service = new LWCMessageService(); | ||
expect(service.getPlugin()).toBeTruthy(); | ||
}); | ||
|
||
describe('rollup plugin', () => { | ||
describe('resolveId', () => { | ||
it('should resolve paths with @salesforce/messageChannel', () => { | ||
const service = new LWCMessageService(); | ||
const plugin = service.getPlugin(); | ||
|
||
const resolved = plugin.resolveId( | ||
'@salesforce/messageChannel/SampleMessageChannel__c' | ||
); | ||
expect(resolved).toBe( | ||
'@salesforce/messageChannel/SampleMessageChannel__c' | ||
); | ||
}); | ||
}); | ||
|
||
describe('load', () => { | ||
it('should throw error for @salesforce/messageChannel imports', () => { | ||
(getLatestVersion as jest.Mock).mockReturnValue('158104e2eb'); | ||
|
||
const service = new LWCMessageService(); | ||
const plugin = service.getPlugin(); | ||
function loadApexContinuation() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this has nothing to do with apex continuations so let's change the name of this function |
||
plugin.load( | ||
'@salesforce/messageChannel/SampleMessageChannel__c' | ||
); | ||
} | ||
expect(loadApexContinuation).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
it('should return null instead of throwing error for other than @salesforce/messageChannel imports', () => { | ||
const service = new LWCMessageService(); | ||
const plugin = service.getPlugin(); | ||
const resolved = plugin.load('./lightningMessageService.html'); | ||
|
||
expect(resolved).toBeNull(); | ||
}); | ||
}); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
src/server/services/__tests__/__snapshots__/LWCMessageService.test.ts.snap
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`LWCMessageService rollup plugin load should throw error for @salesforce/messageChannel imports 1`] = `"You can't preview a component using Lightning Message Service. Test the component directly in the org"`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LisandroFernandezSF - the message looks good. Do you need me to look at anything else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No Emily, I think that was everything |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't the issue with network interfaces happening in this PR? I wasn't under the impression this current PR was experiencing issues with the tests. I'd be more curious to see if these changes have an effect on the other PR.
As a note, if we move forward with this change then tests will need to be added to machineId.test.ts. I'm hesitant to move forward with this change until we understand why your test scenario was failing though. There could be a different underlying issue that we need to address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed the issue with network interfaces is happening in both PRs.
Ok, I can dedicate more time to understand why the test scenario is failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you show me the test failure where this was happening on this PR too? Also, is it reproducible locally for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is not failing, the
yarn build
process is failing. It showsObject is possibly 'undefined'
for this line.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be related to this issue nodejs/node#30504
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the issue is at build time I think the current change might be enough. If it is happening at runtime then we'll just return
undefined
when runninggetMacAddress()
. Is there anything else I might be missing @sfsholden @LisandroFernandezSF ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, if this is happening at build time then I'm less concerned about adding in this change.