Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-transformer): update @salesforce/apex transform #924

Merged
merged 9 commits into from
Jan 8, 2019

Conversation

trevor-bliss
Copy link
Contributor

Details

The @salesforce/apex module import is different from the other salesforce scoped module imports for two reasons:

  1. It supports named imports, e.g. import { refreshApex, getSObjectValue } from '@salesforce/apex';
  2. The import of an Apex method must have object equality between the component under test and test case if it's used as an @wire adapter id.

Changes in the PR are to support both cases. Additionally, there is some minor cleanup to the existing transforms logic.

Does this PR introduce a breaking change?

  • Yes
  • No

@trevor-bliss trevor-bliss requested a review from kevinv11n January 7, 2019 22:12
});

describe('example-apex', () => {
it('default import is resolved Promise', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests the default import eventually resolves, not that it's already resolved.

})
});

it('can import and call multiple default Apex imports', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests that a second Apex import can be called (given the context of the first test above), not that multiple Apex imports can be called.


test('throws error if renamed default imports', `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you want this or the test below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them because we allow named imports for @salesforce/apex now. I guess we could add special logic to see if the import is renaming the default, but I'm not sure how valuable that would be.

* shared.
*/
const resolvedPromiseTemplate = babelTemplate(`
global.MOCK_NAME = global.MOCK_NAME || function() { return Promise.resolve(); };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do this global assignment inside the catch on line 24 since it's only used in that code path? That avoids polluting the global var and evaluation when it's not required.

packages/@lwc/jest-transformer/src/transforms/utils.js Outdated Show resolved Hide resolved
packages/@lwc/jest-transformer/src/transforms/utils.js Outdated Show resolved Hide resolved
packages/@lwc/jest-transformer/src/transforms/utils.js Outdated Show resolved Hide resolved
@kevinv11n kevinv11n changed the title fix(jest-transformer): update @slesforce/apex transform fix(jest-transformer): update @salesforce/apex transform Jan 8, 2019
Copy link
Contributor

@kevinv11n kevinv11n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor issues

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 6e2817f | Target commit: 48ee8cf

@trevor-bliss trevor-bliss merged commit a3d6af5 into master Jan 8, 2019
@trevor-bliss trevor-bliss deleted the tbliss/apex-transformer branch January 8, 2019 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants