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

feat(jest-transformer): Add babel transform for new scoped imports #463

Merged
merged 8 commits into from
Jul 2, 2018

Conversation

trevor-bliss
Copy link
Contributor

Details

As part of the work to fold scoped module imports all under @salesforce, we need to update the Jest transformer to handle the new imports in a similar way that @label is handled so tests do not error on load. The transformation for the new imports follows the same pattern as @label, but may provide a different fallback value depending on the import type.

Does this PR introduce a breaking change?

  • Yes
  • No

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 8514676 | Target commit: e590a68

import { default as label } from '@salesforce/apex/FooController.fooMethod';
`, undefined, 'Invalid import from @salesforce/apex/FooController.fooMethod');

test('throws error if renamed multipel 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.

s/multipel/multiple/

} catch (e) {
objectApiName = {
objectApiName: "Opportunity",
fieldApiName: undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't provision fieldApiName on an object import

}
`);

const schemaObjectTemplate = babelTemplate(`
Copy link
Contributor

Choose a reason for hiding this comment

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

We need two templates:

  1. schemaObject that returns {objectApiName}
  2. schemaField that returns {objectApiName, fieldApiName}

[1] is used for import x from @salesforce/schema/<word>
[2] is used for import x from @salesforce/schema/<word>[.<word>]+

const resourcePath = importSource.substring(importIdentifier.length + 1);
const idx = resourcePath.indexOf('.');

if (idx === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic needs tweaking per comment above. It's also the place you can pivot the logic.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: e4df6b4 | Target commit: dd20284

lwc-engine-benchmark

table-append-1k metric base(e4df6b4) target(dd20284) trend
benchmark-table/append/1k duration 159.10 (± 5.60 ms) 155.30 (± 5.60 ms) 2.39% 👍
table-clear-1k metric base(e4df6b4) target(dd20284) trend
benchmark-table/clear/1k duration 12.40 (± 0.60 ms) 12.10 (± 0.60 ms) 2.42% 👌
table-create-10k metric base(e4df6b4) target(dd20284) trend
benchmark-table/create/10k duration 906.80 (± 8.70 ms) 913.00 (± 8.00 ms) -0.68% 👎
table-create-1k metric base(e4df6b4) target(dd20284) trend
benchmark-table/create/1k duration 104.40 (± 2.10 ms) 100.40 (± 1.80 ms) 3.83% 👍
table-update-10th-1k metric base(e4df6b4) target(dd20284) trend
benchmark-table/update-10th/1k duration 90.80 (± 4.80 ms) 85.90 (± 5.00 ms) 5.40% 👌
tablecmp-append-1k metric base(e4df6b4) target(dd20284) trend
benchmark-table-component/append/1k duration 233.90 (± 4.80 ms) 257.40 (± 4.50 ms) -10.05% 👎
tablecmp-clear-1k metric base(e4df6b4) target(dd20284) trend
benchmark-table/clear/1k duration 37.70 (± 1.80 ms) 37.40 (± 2.10 ms) 0.80% 👌
tablecmp-create-10k metric base(e4df6b4) target(dd20284) trend
benchmark-table-component/create/10k duration 1626.90 (± 11.60 ms) 1918.20 (± 10.00 ms) -17.91% 👎
tablecmp-create-1k metric base(e4df6b4) target(dd20284) trend
benchmark-table-component/create/1k duration 174.05 (± 3.95 ms) 197.80 (± 4.40 ms) -13.65% 👎
tablecmp-update-10th-1k metric base(e4df6b4) target(dd20284) trend
benchmark-table-component/update-10th/1k duration 78.10 (± 4.70 ms) 80.90 (± 5.40 ms) -3.59% 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: e4df6b4 | Target commit: a7630b1

lwc-engine-benchmark

table-append-1k metric base(e4df6b4) target(a7630b1) trend
benchmark-table/append/1k duration 159.10 (± 5.60 ms) 156.30 (± 5.20 ms) 1.76% 👌
table-clear-1k metric base(e4df6b4) target(a7630b1) trend
benchmark-table/clear/1k duration 12.40 (± 0.60 ms) 12.30 (± 0.50 ms) 0.81% 👌
table-create-10k metric base(e4df6b4) target(a7630b1) trend
benchmark-table/create/10k duration 906.80 (± 8.70 ms) 908.20 (± 13.40 ms) -0.15% 👎
table-create-1k metric base(e4df6b4) target(a7630b1) trend
benchmark-table/create/1k duration 104.40 (± 2.10 ms) 102.50 (± 2.10 ms) 1.82% 👍
table-update-10th-1k metric base(e4df6b4) target(a7630b1) trend
benchmark-table/update-10th/1k duration 90.80 (± 4.80 ms) 86.20 (± 5.50 ms) 5.07% 👌
tablecmp-append-1k metric base(e4df6b4) target(a7630b1) trend
benchmark-table-component/append/1k duration 233.90 (± 4.80 ms) 258.40 (± 4.50 ms) -10.47% 👎
tablecmp-clear-1k metric base(e4df6b4) target(a7630b1) trend
benchmark-table/clear/1k duration 37.70 (± 1.80 ms) 38.60 (± 1.40 ms) -2.39% 👌
tablecmp-create-10k metric base(e4df6b4) target(a7630b1) trend
benchmark-table-component/create/10k duration 1626.90 (± 11.60 ms) 1939.50 (± 15.80 ms) -19.21% 👎
tablecmp-create-1k metric base(e4df6b4) target(a7630b1) trend
benchmark-table-component/create/1k duration 174.05 (± 3.95 ms) 202.20 (± 4.20 ms) -16.17% 👎
tablecmp-update-10th-1k metric base(e4df6b4) target(a7630b1) trend
benchmark-table-component/update-10th/1k duration 78.10 (± 4.70 ms) 81.20 (± 4.50 ms) -3.97% 👌

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.

One nitpick on variable names otherwise is good to merge

@@ -18,7 +18,16 @@ const resolvedPromiseTemplate = babelTemplate(`
}
`);

const schemaObjectTemplate = babelTemplate(`
const schemaSObjectTemplate = babelTemplate(`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call these schemaObjectTemplate and schemaObjectAndFieldTemplate? In the future there will be other templates (eg field sets).

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: e4df6b4 | Target commit: 2573889

lwc-engine-benchmark

table-append-1k metric base(e4df6b4) target(2573889) trend
benchmark-table/append/1k duration 159.10 (± 5.60 ms) 155.80 (± 5.70 ms) 2.07% 👍
table-clear-1k metric base(e4df6b4) target(2573889) trend
benchmark-table/clear/1k duration 12.40 (± 0.60 ms) 11.90 (± 0.60 ms) 4.03% 👍
table-create-10k metric base(e4df6b4) target(2573889) trend
benchmark-table/create/10k duration 906.80 (± 8.70 ms) 911.20 (± 10.90 ms) -0.49% 👎
table-create-1k metric base(e4df6b4) target(2573889) trend
benchmark-table/create/1k duration 104.40 (± 2.10 ms) 101.10 (± 1.40 ms) 3.16% 👍
table-update-10th-1k metric base(e4df6b4) target(2573889) trend
benchmark-table/update-10th/1k duration 90.80 (± 4.80 ms) 91.00 (± 5.50 ms) -0.22% 👌
tablecmp-append-1k metric base(e4df6b4) target(2573889) trend
benchmark-table-component/append/1k duration 233.90 (± 4.80 ms) 258.50 (± 6.50 ms) -10.52% 👎
tablecmp-clear-1k metric base(e4df6b4) target(2573889) trend
benchmark-table/clear/1k duration 37.70 (± 1.80 ms) 37.10 (± 1.90 ms) 1.59% 👌
tablecmp-create-10k metric base(e4df6b4) target(2573889) trend
benchmark-table-component/create/10k duration 1626.90 (± 11.60 ms) 1924.70 (± 16.40 ms) -18.30% 👎
tablecmp-create-1k metric base(e4df6b4) target(2573889) trend
benchmark-table-component/create/1k duration 174.05 (± 3.95 ms) 199.10 (± 4.20 ms) -14.39% 👎
tablecmp-update-10th-1k metric base(e4df6b4) target(2573889) trend
benchmark-table-component/update-10th/1k duration 78.10 (± 4.70 ms) 78.50 (± 4.30 ms) -0.51% 👌

@trevor-bliss trevor-bliss merged commit 4893505 into master Jul 2, 2018
@trevor-bliss trevor-bliss deleted the tbliss/transformer-scoped-imports branch July 2, 2018 23:58
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.

3 participants