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): generate jest tests sourcemaps #706

Merged
merged 3 commits into from
Oct 5, 2018

Conversation

jodarove
Copy link
Contributor

@jodarove jodarove commented Oct 4, 2018

Generate component sourcemaps in jest tests, which improve the coverage, and make the tests debuggable.

Does this PR introduce a breaking change?

  • Yes
  • No

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 2a3ce0f | Target commit: 00e3962

lwc-engine-benchmark

table-append-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table/append/1k duration 156.05 (±5.40 ms) 154.45 (±5.85 ms) -1.6ms (1.0%) 👌
table-clear-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table/clear/1k duration 12.50 (±0.70 ms) 12.20 (±0.70 ms) -0.3ms (2.4%) 👌
table-create-10k metric base(2a3ce0f) target(00e3962) trend
benchmark-table/create/10k duration 875.60 (±7.20 ms) 873.60 (±5.80 ms) -2.0ms (0.2%) 👌
table-create-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table/create/1k duration 109.40 (±2.15 ms) 109.85 (±2.00 ms) +0.4ms (0.4%) 👌
table-update-10th-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table/update-10th/1k duration 85.20 (±1.60 ms) 97.45 (±1.55 ms) +12.3ms (14.4%) 👎
tablecmp-append-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-component/append/1k duration 222.75 (±12.40 ms) 221.65 (±14.35 ms) -1.1ms (0.5%) 👌
tablecmp-clear-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-component/clear/1k duration 20.60 (±2.10 ms) 19.05 (±2.05 ms) -1.6ms (7.5%) 👍
tablecmp-create-10k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-component/create/10k duration 1612.20 (±10.10 ms) 1570.05 (±9.10 ms) -42.1ms (2.6%) 👍
tablecmp-create-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-component/create/1k duration 187.95 (±3.90 ms) 182.50 (±5.80 ms) -5.4ms (2.9%) 👍
tablecmp-update-10th-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-component/update-10th/1k duration 83.85 (±7.05 ms) 84.75 (±6.00 ms) +0.9ms (1.1%) 👌
wc-append-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-wc/append/1k duration 272.20 (±15.40 ms) 257.55 (±13.80 ms) -14.6ms (5.4%) 👍
wc-clear-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-wc/clear/1k duration 29.80 (±2.30 ms) 28.60 (±2.15 ms) -1.2ms (4.0%) 👍
wc-create-10k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-wc/create/10k duration 2067.10 (±12.50 ms) 2085.65 (±10.75 ms) +18.5ms (0.9%) 👎
wc-create-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-wc/create/1k duration 222.65 (±5.55 ms) 221.30 (±5.20 ms) -1.3ms (0.6%) 👌
wc-update-10th-1k metric base(2a3ce0f) target(00e3962) trend
benchmark-table-wc/update-10th/1k duration 85.50 (±6.80 ms) 82.70 (±5.40 ms) -2.8ms (3.3%) 👌

@CommanderQ
Copy link
Contributor

Thank you for this! 😄 🎆


const generated = babelCore.transform(code, BABEL_CONFIG);
if (isJsFile) {
config.inputSourceMap = map;
Copy link
Member

Choose a reason for hiding this comment

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

Why not always add the sourcemap as input?

@@ -30,15 +31,25 @@ const BABEL_CONFIG = {

module.exports = {
process(src, filePath) {
const isJsFile = path.extname(filePath) === '.js';
// generate sourcemaps only for js files, otherwise the coverage is affected with template code.
const config = Object.assign({}, BABEL_CONFIG, { sourceMaps: isJsFile ? 'inline' : false });
Copy link
Member

Choose a reason for hiding this comment

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

Move the config declaration after line 46 to avoid mutating it's value.

config.inputSourceMap = map;
}

const generated = babelCore.transform(code, config);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ill verify but makes sense.

@@ -30,15 +31,25 @@ const BABEL_CONFIG = {

module.exports = {
process(src, filePath) {
const isJsFile = path.extname(filePath) === '.js';
// generate sourcemaps only for js files, otherwise the coverage is affected with template code.
const config = Object.assign({}, BABEL_CONFIG, { sourceMaps: isJsFile ? 'inline' : false });
Copy link
Member

Choose a reason for hiding this comment

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

Why not always returning the sourcemap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cause that will include the template javascript generated code on the coverage. Since i dont think the template code should be included in the coverage, i disabled the map generation since it will add extra calculations for the template.
your thoughts @trevor-bliss?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@trevor-bliss after checking with @pmdartus, we are fine adding the sourcemaps for the .html and the .css as long as we only add coverage for .js files

Just one thing @pmdartus , the sourcemap file name for html and css should be different from the original, for example with .compiled appended, otherwise wont be debug-able in the IDE (cause it will show the original file content).

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree we should not include coverage for the html and css files if we include them.

It did feel weird to me from a test debugging standpoint to include the html though. In the example Jose demoed to me, if you set a breakpoint in a js function of your component, when you return from that function you are back in compiled html land. I can see this being useful to the lwc core team or someone debugging a template compiler issue, but the the internal rendering APIs feel cryptic and unnecessary to the average unit test debugger. I could be underestimating our customers willingness to understand and debug the internals though.

Thoughts @pmdartus @jodarove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually currently we need to add:

    coveragePathIgnorePatterns: [ '.html$', '.css$' ],

to the jest config in order to have a more accurate coverage number (if we dont want to include the generated code for the template/css in the coverage)

based on that, the remaining question is: while debugging, do we want to see the actual code that is being executed (the compiled code) or the template with no idea of what is being happening? from my dev standpoint mmm yeah what is executed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah after trying this out myself I think we should include the html and css and just exclude it from coverage.

moduleNamespace: 'x'
moduleNamespace: 'x',
outputConfig: {
sourcemap: isJsFile
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is just to tell the lwc-compiler to generate sourcemaps for this transformation (a map object). the both option is for the babel transform, if we want both (inline and a map object) which i dont see the need, but neither the harm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tracing back the both option in the babel-jest:
inline is still supported but has some performance issues: jestjs/jest#5177 (comment)
they support returning a map from the processor, and if that map is returned, they dont look to the inline one, that is why inline -> both in babel-jest.

Setting it to both on the babel config. nice catch @pmdartus!!

Generate component sourcemaps in jest tests.
@jodarove jodarove force-pushed the jodarove/sourcemap-jest-transformer branch from 00e3962 to 5e044af Compare October 5, 2018 00:51
to exclude .html and .css from being included in the jest coverage report.
@jodarove jodarove force-pushed the jodarove/sourcemap-jest-transformer branch from 5e044af to ea6a734 Compare October 5, 2018 00:57
@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 2a3ce0f | Target commit: 5e044af

lwc-engine-benchmark

table-append-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table/append/1k duration 156.05 (±5.40 ms) 154.10 (±5.85 ms) -1.9ms (1.2%) 👍
table-clear-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table/clear/1k duration 12.50 (±0.70 ms) 12.20 (±0.60 ms) -0.3ms (2.4%) 👌
table-create-10k metric base(2a3ce0f) target(5e044af) trend
benchmark-table/create/10k duration 875.60 (±7.20 ms) 875.10 (±4.90 ms) -0.5ms (0.1%) 👌
table-create-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table/create/1k duration 109.40 (±2.15 ms) 108.20 (±1.80 ms) -1.2ms (1.1%) 👌
table-update-10th-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table/update-10th/1k duration 85.20 (±1.60 ms) 84.15 (±1.70 ms) -1.0ms (1.2%) 👌
tablecmp-append-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-component/append/1k duration 222.75 (±12.40 ms) 220.40 (±13.90 ms) -2.4ms (1.1%) 👌
tablecmp-clear-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-component/clear/1k duration 20.60 (±2.10 ms) 18.80 (±1.90 ms) -1.8ms (8.7%) 👍
tablecmp-create-10k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-component/create/10k duration 1612.20 (±10.10 ms) 1548.60 (±8.20 ms) -63.6ms (3.9%) 👍
tablecmp-create-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-component/create/1k duration 187.95 (±3.90 ms) 180.15 (±4.25 ms) -7.8ms (4.2%) 👍
tablecmp-update-10th-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-component/update-10th/1k duration 83.85 (±7.05 ms) 81.10 (±5.75 ms) -2.8ms (3.3%) 👍
wc-append-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-wc/append/1k duration 272.20 (±15.40 ms) 263.90 (±14.60 ms) -8.3ms (3.0%) 👍
wc-clear-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-wc/clear/1k duration 29.80 (±2.30 ms) 28.40 (±2.40 ms) -1.4ms (4.7%) 👍
wc-create-10k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-wc/create/10k duration 2067.10 (±12.50 ms) 2059.55 (±14.25 ms) -7.6ms (0.4%) 👌
wc-create-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-wc/create/1k duration 222.65 (±5.55 ms) 218.35 (±4.50 ms) -4.3ms (1.9%) 👍
wc-update-10th-1k metric base(2a3ce0f) target(5e044af) trend
benchmark-table-wc/update-10th/1k duration 85.50 (±6.80 ms) 81.20 (±6.40 ms) -4.3ms (5.0%) 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 2a3ce0f | Target commit: ea6a734

lwc-engine-benchmark

table-append-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table/append/1k duration 156.05 (±5.40 ms) 155.00 (±6.60 ms) -1.1ms (0.7%) 👌
table-clear-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table/clear/1k duration 12.50 (±0.70 ms) 12.00 (±0.65 ms) -0.5ms (4.0%) 👌
table-create-10k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table/create/10k duration 875.60 (±7.20 ms) 873.65 (±5.25 ms) -2.0ms (0.2%) 👌
table-create-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table/create/1k duration 109.40 (±2.15 ms) 109.40 (±1.50 ms) 0.0ms (0.0%) 👌
table-update-10th-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table/update-10th/1k duration 85.20 (±1.60 ms) 97.85 (±5.10 ms) +12.6ms (14.8%) 👎
tablecmp-append-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-component/append/1k duration 222.75 (±12.40 ms) 227.80 (±7.05 ms) +5.1ms (2.3%) 👎
tablecmp-clear-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-component/clear/1k duration 20.60 (±2.10 ms) 20.05 (±2.15 ms) -0.6ms (2.7%) 👌
tablecmp-create-10k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-component/create/10k duration 1612.20 (±10.10 ms) 1591.95 (±10.40 ms) -20.3ms (1.3%) 👍
tablecmp-create-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-component/create/1k duration 187.95 (±3.90 ms) 182.15 (±5.00 ms) -5.8ms (3.1%) 👍
tablecmp-update-10th-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-component/update-10th/1k duration 83.85 (±7.05 ms) 83.40 (±5.20 ms) -0.4ms (0.5%) 👌
wc-append-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-wc/append/1k duration 272.20 (±15.40 ms) 271.15 (±11.40 ms) -1.1ms (0.4%) 👌
wc-clear-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-wc/clear/1k duration 29.80 (±2.30 ms) 27.90 (±2.50 ms) -1.9ms (6.4%) 👍
wc-create-10k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-wc/create/10k duration 2067.10 (±12.50 ms) 2066.25 (±9.25 ms) -0.9ms (0.0%) 👌
wc-create-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-wc/create/1k duration 222.65 (±5.55 ms) 217.90 (±5.30 ms) -4.8ms (2.1%) 👍
wc-update-10th-1k metric base(2a3ce0f) target(ea6a734) trend
benchmark-table-wc/update-10th/1k duration 85.50 (±6.80 ms) 81.75 (±4.45 ms) -3.8ms (4.4%) 👍

Copy link
Member

@pmdartus pmdartus left a comment

Choose a reason for hiding this comment

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

We are good to go, just have a small stylistic comment.


const generated = babelCore.transform(code, BABEL_CONFIG);
// if is not .js, we add the .compiled extension in the sourcemap
const filename = path.extname(filePath) === '.js' ? filePath : filePath + '.compiled';
Copy link
Member

Choose a reason for hiding this comment

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

I like this idea 👍


return generated.code;
return babelCore.transform(code, { ...BABEL_CONFIG, ...{ filename }, ...config });
Copy link
Member

Choose a reason for hiding this comment

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

You can further simply this code:

return babelCore.transform(code, { 
    ...BABEL_CONFIG, 
    ...config,
    filename,
});

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: b4b29a1 | Target commit: 0b2cd3d

lwc-engine-benchmark

table-append-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/append/1k duration 155.30 (±6.35 ms) 152.75 (±6.00 ms) -2.6ms (1.6%) 👍
table-clear-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/clear/1k duration 12.50 (±0.80 ms) 12.45 (±0.60 ms) -0.1ms (0.4%) 👌
table-create-10k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/create/10k duration 890.90 (±9.40 ms) 879.60 (±5.55 ms) -11.3ms (1.3%) 👍
table-create-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/create/1k duration 110.55 (±2.20 ms) 108.40 (±2.30 ms) -2.1ms (1.9%) 👍
table-update-10th-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/update-10th/1k duration 86.30 (±2.35 ms) 84.60 (±1.20 ms) -1.7ms (2.0%) 👍
tablecmp-append-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/append/1k duration 230.40 (±8.25 ms) 224.20 (±8.35 ms) -6.2ms (2.7%) 👍
tablecmp-clear-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/clear/1k duration 21.20 (±1.60 ms) 19.30 (±1.85 ms) -1.9ms (9.0%) 👍
tablecmp-create-10k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/create/10k duration 1587.70 (±10.25 ms) 1567.70 (±8.90 ms) -20.0ms (1.3%) 👍
tablecmp-create-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/create/1k duration 185.75 (±6.25 ms) 180.65 (±5.70 ms) -5.1ms (2.7%) 👍
tablecmp-update-10th-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/update-10th/1k duration 83.10 (±6.70 ms) 82.55 (±4.95 ms) -0.5ms (0.7%) 👌
wc-append-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/append/1k duration 274.80 (±14.45 ms) 264.35 (±17.40 ms) -10.4ms (3.8%) 👍
wc-clear-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/clear/1k duration 29.00 (±2.00 ms) 28.30 (±2.65 ms) -0.7ms (2.4%) 👌
wc-create-10k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/create/10k duration 2095.00 (±10.90 ms) 2051.00 (±11.80 ms) -44.0ms (2.1%) 👍
wc-create-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/create/1k duration 227.65 (±5.00 ms) 219.90 (±5.35 ms) -7.7ms (3.4%) 👍
wc-update-10th-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/update-10th/1k duration 84.85 (±6.35 ms) 84.65 (±5.70 ms) -0.2ms (0.2%) 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: b4b29a1 | Target commit: 0b2cd3d

lwc-engine-benchmark

table-append-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/append/1k duration 155.30 (±6.35 ms) 157.65 (±6.55 ms) +2.3ms (1.5%) 👌
table-clear-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/clear/1k duration 12.50 (±0.80 ms) 11.70 (±0.65 ms) -0.8ms (6.4%) 👍
table-create-10k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/create/10k duration 890.90 (±9.40 ms) 883.65 (±7.45 ms) -7.3ms (0.8%) 👍
table-create-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/create/1k duration 110.55 (±2.20 ms) 108.70 (±1.90 ms) -1.9ms (1.7%) 👍
table-update-10th-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table/update-10th/1k duration 86.30 (±2.35 ms) 94.60 (±4.55 ms) +8.3ms (9.6%) 👌
tablecmp-append-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/append/1k duration 230.40 (±8.25 ms) 223.95 (±11.35 ms) -6.5ms (2.8%) 👍
tablecmp-clear-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/clear/1k duration 21.20 (±1.60 ms) 19.25 (±2.05 ms) -2.0ms (9.2%) 👍
tablecmp-create-10k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/create/10k duration 1587.70 (±10.25 ms) 1603.85 (±9.90 ms) +16.1ms (1.0%) 👎
tablecmp-create-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/create/1k duration 185.75 (±6.25 ms) 184.05 (±5.40 ms) -1.7ms (0.9%) 👌
tablecmp-update-10th-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-component/update-10th/1k duration 83.10 (±6.70 ms) 80.45 (±4.25 ms) -2.6ms (3.2%) 👌
wc-append-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/append/1k duration 274.80 (±14.45 ms) 267.60 (±16.55 ms) -7.2ms (2.6%) 👌
wc-clear-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/clear/1k duration 29.00 (±2.00 ms) 28.10 (±3.15 ms) -0.9ms (3.1%) 👌
wc-create-10k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/create/10k duration 2095.00 (±10.90 ms) 2079.60 (±18.30 ms) -15.4ms (0.7%) 👍
wc-create-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/create/1k duration 227.65 (±5.00 ms) 223.30 (±5.75 ms) -4.3ms (1.9%) 👍
wc-update-10th-1k metric base(b4b29a1) target(0b2cd3d) trend
benchmark-table-wc/update-10th/1k duration 84.85 (±6.35 ms) 84.80 (±5.15 ms) -0.0ms (0.1%) 👌

@jodarove jodarove merged commit 2b3b28d into master Oct 5, 2018
@jodarove jodarove deleted the jodarove/sourcemap-jest-transformer branch October 5, 2018 14:14
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.

4 participants