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

test: Migrate jest to use projects feature #322

Merged
merged 26 commits into from May 31, 2018
Merged

Conversation

pmdartus
Copy link
Member

@pmdartus pmdartus commented May 21, 2018

Details

This PR changes the way jest is configured in the mono-repo, to leverage the projects feature properly. This would allow us to have a different jest config for each project.

Changes:

  • Remove component registry in the engine
  • Fix tests that are using root instead of template
  • Fix tests with duplicate component names

The test running will also print the package name next to the test 💃

screen shot 2018-05-21 at 8 41 41 am


In upcoming a PR I want to get rid of all the remaining warnings by introducing a custom matcher that will trap the warnings and the errors (#94, #104). All the unexpected console log, warn and error should make the test fail. Doing this would greatly improve quality and the consistency of the warnings the engine surfaces.

Does this PR introduce a breaking change?

  • Yes
  • No

// This method is internal to the engine and should only be used for testing purposes!
// The component registry need to get flushed between each test to avoid having the
// engine warning about multiple class registration with the same tag name.
export function flushComponentRegistry() {
Copy link
Member Author

Choose a reason for hiding this comment

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

@davidturissini Here is the newly added method that we discussed on last Friday.

Copy link
Contributor

Choose a reason for hiding this comment

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

let's chat about this. We should discuss if we really need a registry for now or not. Also, if this method is supposed to stay, it should throw if it is ever invoked outside of test mode. Let's add the if condition here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's remove the registry.

@davidturissini
Copy link
Contributor

So, we were using this feature a while back (projects) and it was very buggy. Has this become more stable? I recall there being many caching issues with this.

@pmdartus
Copy link
Member Author

I didn't had any issue. I would be interested if you can pull this branch and give a try at it.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 948fbb9 | Target commit: a985dd8

lwc-engine-benchmark

table-append-1k metric base(948fbb9) target(a985dd8) trend
benchmark-table/append/1k duration 142.80 (± 3.90 ms) 142.50 (± 3.00 ms) 0.21% 👌
table-clear-1k metric base(948fbb9) target(a985dd8) trend
benchmark-table/clear/1k duration 11.80 (± 0.60 ms) 11.50 (± 0.50 ms) 2.54% 👍
table-create-10k metric base(948fbb9) target(a985dd8) trend
benchmark-table/create/10k duration 838.70 (± 8.00 ms) 844.20 (± 7.10 ms) -0.66% 👎
table-create-1k metric base(948fbb9) target(a985dd8) trend
benchmark-table/create/1k duration 101.00 (± 2.30 ms) 99.80 (± 1.90 ms) 1.19% 👌
table-update-10th-1k metric base(948fbb9) target(a985dd8) trend
benchmark-table/update-10th/1k duration 87.70 (± 4.50 ms) 86.30 (± 4.80 ms) 1.60% 👌
tablecmp-append-1k metric base(948fbb9) target(a985dd8) trend
benchmark-table-component/append/1k duration 242.10 (± 4.90 ms) 239.40 (± 5.50 ms) 1.12% 👌
tablecmp-clear-1k metric base(948fbb9) target(a985dd8) trend
benchmark-table/clear/1k duration 30.80 (± 1.10 ms) 31.30 (± 1.10 ms) -1.62% 👌
tablecmp-create-10k metric base(948fbb9) target(a985dd8) trend
benchmark-table-component/create/10k duration 1680.80 (± 12.20 ms) 1741.30 (± 8.80 ms) -3.60% 👎
tablecmp-create-1k metric base(948fbb9) target(a985dd8) trend
benchmark-table-component/create/1k duration 186.70 (± 4.30 ms) 190.00 (± 3.40 ms) -1.77% 👎
tablecmp-update-10th-1k metric base(948fbb9) target(a985dd8) trend
benchmark-table-component/update-10th/1k duration 73.30 (± 4.50 ms) 73.80 (± 4.60 ms) -0.68% 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 948fbb9 | Target commit: 851eb6f

lwc-engine-benchmark

table-append-1k metric base(948fbb9) target(851eb6f) trend
benchmark-table/append/1k duration 142.80 (± 3.90 ms) 144.75 (± 3.15 ms) -1.37% 👌
table-clear-1k metric base(948fbb9) target(851eb6f) trend
benchmark-table/clear/1k duration 11.80 (± 0.60 ms) 11.60 (± 0.50 ms) 1.69% 👌
table-create-10k metric base(948fbb9) target(851eb6f) trend
benchmark-table/create/10k duration 838.70 (± 8.00 ms) 837.40 (± 5.00 ms) 0.16% 👌
table-create-1k metric base(948fbb9) target(851eb6f) trend
benchmark-table/create/1k duration 101.00 (± 2.30 ms) 100.90 (± 2.30 ms) 0.10% 👌
table-update-10th-1k metric base(948fbb9) target(851eb6f) trend
benchmark-table/update-10th/1k duration 87.70 (± 4.50 ms) 87.60 (± 5.10 ms) 0.11% 👌
tablecmp-append-1k metric base(948fbb9) target(851eb6f) trend
benchmark-table-component/append/1k duration 242.10 (± 4.90 ms) 202.40 (± 6.90 ms) 16.40% 👍
tablecmp-clear-1k metric base(948fbb9) target(851eb6f) trend
benchmark-table/clear/1k duration 30.80 (± 1.10 ms) 31.30 (± 1.00 ms) -1.62% 👌
tablecmp-create-10k metric base(948fbb9) target(851eb6f) trend
benchmark-table-component/create/10k duration 1680.80 (± 12.20 ms) 1684.60 (± 7.20 ms) -0.23% 👎
tablecmp-create-1k metric base(948fbb9) target(851eb6f) trend
benchmark-table-component/create/1k duration 186.70 (± 4.30 ms) 187.60 (± 3.40 ms) -0.48% 👌
tablecmp-update-10th-1k metric base(948fbb9) target(851eb6f) trend
benchmark-table-component/update-10th/1k duration 73.30 (± 4.50 ms) 73.10 (± 3.90 ms) 0.27% 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: ba321e0 | Target commit: 7e7d3ac

lwc-engine-benchmark

table-append-1k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table/append/1k duration 145.05 (± 3.45 ms) 146.90 (± 4.90 ms) -1.28% 👌
table-clear-1k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table/clear/1k duration 11.40 (± 0.50 ms) 11.20 (± 0.40 ms) 1.75% 👌
table-create-10k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table/create/10k duration 851.10 (± 12.10 ms) 840.10 (± 5.80 ms) 1.29% 👍
table-create-1k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table/create/1k duration 100.00 (± 2.30 ms) 101.40 (± 1.30 ms) -1.40% 👎
table-update-10th-1k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table/update-10th/1k duration 86.60 (± 5.00 ms) 92.50 (± 5.85 ms) -6.81% 👌
tablecmp-append-1k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table-component/append/1k duration 258.10 (± 5.60 ms) 259.00 (± 5.50 ms) -0.35% 👌
tablecmp-clear-1k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table/clear/1k duration 34.50 (± 1.70 ms) 34.30 (± 2.10 ms) 0.58% 👌
tablecmp-create-10k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table-component/create/10k duration 1712.40 (± 13.20 ms) 1716.40 (± 16.20 ms) -0.23% 👌
tablecmp-create-1k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table-component/create/1k duration 194.15 (± 3.90 ms) 195.70 (± 4.60 ms) -0.80% 👌
tablecmp-update-10th-1k metric base(ba321e0) target(7e7d3ac) trend
benchmark-table-component/update-10th/1k duration 74.10 (± 4.00 ms) 74.60 (± 3.90 ms) -0.67% 👌

@@ -0,0 +1,16 @@
const path = require('path');
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 7402138 | Target commit: bfe25cf

lwc-engine-benchmark

table-append-1k metric base(7402138) target(bfe25cf) trend
benchmark-table/append/1k duration 146.00 (± 4.20 ms) 145.90 (± 3.80 ms) 0.07% 👌
table-clear-1k metric base(7402138) target(bfe25cf) trend
benchmark-table/clear/1k duration 11.30 (± 0.45 ms) 11.50 (± 0.50 ms) -1.77% 👌
table-create-10k metric base(7402138) target(bfe25cf) trend
benchmark-table/create/10k duration 851.90 (± 3.50 ms) 846.80 (± 5.40 ms) 0.60% 👍
table-create-1k metric base(7402138) target(bfe25cf) trend
benchmark-table/create/1k duration 101.45 (± 1.30 ms) 101.20 (± 2.20 ms) 0.25% 👌
table-update-10th-1k metric base(7402138) target(bfe25cf) trend
benchmark-table/update-10th/1k duration 87.40 (± 4.70 ms) 92.40 (± 5.40 ms) -5.72% 👌
tablecmp-append-1k metric base(7402138) target(bfe25cf) trend
benchmark-table-component/append/1k duration 258.90 (± 5.40 ms) 264.80 (± 4.50 ms) -2.28% 👎
tablecmp-clear-1k metric base(7402138) target(bfe25cf) trend
benchmark-table/clear/1k duration 35.35 (± 1.65 ms) 35.50 (± 1.60 ms) -0.42% 👌
tablecmp-create-10k metric base(7402138) target(bfe25cf) trend
benchmark-table-component/create/10k duration 1747.60 (± 13.10 ms) 1710.90 (± 18.20 ms) 2.10% 👍
tablecmp-create-1k metric base(7402138) target(bfe25cf) trend
benchmark-table-component/create/1k duration 198.50 (± 4.30 ms) 196.70 (± 5.00 ms) 0.91% 👌
tablecmp-update-10th-1k metric base(7402138) target(bfe25cf) trend
benchmark-table-component/update-10th/1k duration 75.80 (± 4.00 ms) 75.50 (± 3.90 ms) 0.40% 👌

@@ -76,7 +76,7 @@ describe('error boundary component', () => {
return html;
}
}
const boundaryHostElm = createElement('x-boundary', {is: BoundryHost});
const boundaryHostElm = createElement('x-parent', {is: BoundryHost});
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you changing this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it not to conflict with line 70, one of the children of x-boundary is also a x-boundary but with a different class. The engine logs a warning because of this.

@@ -7,27 +7,28 @@ import { VNode } from "../../3rdparty/snabbdom/types";
import { Component } from "../component";
import { unwrap } from "../main";
import { querySelector } from "../dom";
import { callbackify } from "util";
Copy link
Contributor

Choose a reason for hiding this comment

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

hate when we have util package, it messes up with our regular autoimports if they match the same exported name :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch. I will remove this, it was inserted by VSCode!

Copy link
Contributor

@caridy caridy left a comment

Choose a reason for hiding this comment

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

let's chat about this.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: a928325 | Target commit: 3a1b277

lwc-engine-benchmark

table-append-1k metric base(a928325) target(3a1b277) trend
benchmark-table/append/1k duration 145.10 (± 2.60 ms) 150.10 (± 6.40 ms) -3.45% 👎
table-clear-1k metric base(a928325) target(3a1b277) trend
benchmark-table/clear/1k duration 11.60 (± 0.35 ms) 11.30 (± 0.50 ms) 2.59% 👌
table-create-10k metric base(a928325) target(3a1b277) trend
benchmark-table/create/10k duration 851.00 (± 3.90 ms) 872.50 (± 9.00 ms) -2.53% 👎
table-create-1k metric base(a928325) target(3a1b277) trend
benchmark-table/create/1k duration 102.10 (± 2.00 ms) 102.10 (± 2.20 ms) 0.00% 👌
table-update-10th-1k metric base(a928325) target(3a1b277) trend
benchmark-table/update-10th/1k duration 87.70 (± 4.50 ms) 92.70 (± 4.70 ms) -5.70% 👎
tablecmp-append-1k metric base(a928325) target(3a1b277) trend
benchmark-table-component/append/1k duration 263.00 (± 3.85 ms) 261.10 (± 5.20 ms) 0.72% 👌
tablecmp-clear-1k metric base(a928325) target(3a1b277) trend
benchmark-table/clear/1k duration 34.40 (± 2.20 ms) 35.60 (± 2.50 ms) -3.49% 👌
tablecmp-create-10k metric base(a928325) target(3a1b277) trend
benchmark-table-component/create/10k duration 1695.60 (± 13.90 ms) 1719.70 (± 24.80 ms) -1.42% 👎
tablecmp-create-1k metric base(a928325) target(3a1b277) trend
benchmark-table-component/create/1k duration 198.80 (± 3.40 ms) 200.90 (± 3.25 ms) -1.06% 👌
tablecmp-update-10th-1k metric base(a928325) target(3a1b277) trend
benchmark-table-component/update-10th/1k duration 74.10 (± 3.20 ms) 78.00 (± 3.60 ms) -5.26% 👎

@@ -85,7 +84,8 @@ const hook: Hooks = {
renderVM(vm);
},
create(oldVNode: VNode, vnode: VNode) {
createVM(vnode.sel as string, vnode.elm as HTMLElement, vnode.data.slotset);
const { slotset, ctor } = vnode.data;
Copy link
Contributor

Choose a reason for hiding this comment

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

this branch seems to be out of sync with master.

const Ctor = getCtorByTagName(sel);
const { forceTagName } = Ctor as ComponentConstructor;

const Ctor = options.is;
Copy link
Contributor

Choose a reason for hiding this comment

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

again, this is very out of sync with master! Here is you have to untangle Ctor, and them get the forceTagName from it.

Copy link
Contributor

@caridy caridy left a comment

Choose a reason for hiding this comment

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

you need to rebase master, which is very different from what you have in this PR

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 14f8e8b | Target commit: a9921a2

lwc-engine-benchmark

table-append-1k metric base(14f8e8b) target(a9921a2) trend
benchmark-table/append/1k duration 141.15 (± 3.25 ms) 142.90 (± 3.90 ms) -1.24% 👌
table-clear-1k metric base(14f8e8b) target(a9921a2) trend
benchmark-table/clear/1k duration 11.65 (± 0.70 ms) 11.30 (± 0.40 ms) 3.00% 👌
table-create-10k metric base(14f8e8b) target(a9921a2) trend
benchmark-table/create/10k duration 835.70 (± 4.60 ms) 837.10 (± 6.70 ms) -0.17% 👎
table-create-1k metric base(14f8e8b) target(a9921a2) trend
benchmark-table/create/1k duration 100.20 (± 1.60 ms) 100.90 (± 1.60 ms) -0.70% 👌
table-update-10th-1k metric base(14f8e8b) target(a9921a2) trend
benchmark-table/update-10th/1k duration 85.60 (± 5.20 ms) 86.90 (± 6.10 ms) -1.52% 👌
tablecmp-append-1k metric base(14f8e8b) target(a9921a2) trend
benchmark-table-component/append/1k duration 256.70 (± 4.40 ms) 256.20 (± 4.40 ms) 0.19% 👌
tablecmp-clear-1k metric base(14f8e8b) target(a9921a2) trend
benchmark-table/clear/1k duration 34.80 (± 1.70 ms) 36.10 (± 1.30 ms) -3.74% 👎
tablecmp-create-10k metric base(14f8e8b) target(a9921a2) trend
benchmark-table-component/create/10k duration 1677.70 (± 7.90 ms) 1684.30 (± 8.10 ms) -0.39% 👎
tablecmp-create-1k metric base(14f8e8b) target(a9921a2) trend
benchmark-table-component/create/1k duration 198.20 (± 3.20 ms) 194.20 (± 4.00 ms) 2.02% 👍
tablecmp-update-10th-1k metric base(14f8e8b) target(a9921a2) trend
benchmark-table-component/update-10th/1k duration 75.30 (± 4.70 ms) 74.80 (± 4.30 ms) 0.66% 👌

@pmdartus
Copy link
Member Author

Rebased with the latest master.

@@ -91,25 +90,26 @@ export function createElement(sel: string, options: any = {}): HTMLElement {
if (!isObject(options) || isNull(options)) {
throw new TypeError();
}
const { is } = (options as any);

const { is: Ctor } = (options as any);
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to do the circular check here too, otherwise you can't extract the tagName. In the old code, check that we first register it, then we extract it from the registry (which is already resolved if it is circular)

Copy link
Contributor

@caridy caridy left a comment

Choose a reason for hiding this comment

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

Small issue for circular dependencies on root elements with forceTagName defined. I don't think we have tests for this, but this will fail for it.

Copy link
Member Author

@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.

@caridy I updated the PR to handle __circular__ refs. I move the logic in utils.ts and refactor all the usage in the codebase to use this helper method.

@@ -91,7 +91,9 @@ export function createElement(sel: string, options: any = {}): HTMLElement {
throw new TypeError();
}

const { is: Ctor } = (options as any);
let { is: Ctor } = (options as any);
Ctor = resolveCircularModuleDependency(Ctor);
Copy link
Contributor

Choose a reason for hiding this comment

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

nip: single liner: const Ctor = resolveCircularModuleDependency(options.is)

Copy link
Contributor

@caridy caridy left a comment

Choose a reason for hiding this comment

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

LGTM, small nip.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 2790bc6 | Target commit: 7c31f72

lwc-engine-benchmark

table-append-1k metric base(2790bc6) target(7c31f72) trend
benchmark-table/append/1k duration 151.00 (± 6.40 ms) 145.00 (± 4.00 ms) 3.97% 👌
table-clear-1k metric base(2790bc6) target(7c31f72) trend
benchmark-table/clear/1k duration 11.20 (± 0.40 ms) 11.40 (± 0.40 ms) -1.79% 👌
table-create-10k metric base(2790bc6) target(7c31f72) trend
benchmark-table/create/10k duration 835.90 (± 9.10 ms) 850.10 (± 7.20 ms) -1.70% 👎
table-create-1k metric base(2790bc6) target(7c31f72) trend
benchmark-table/create/1k duration 100.10 (± 1.30 ms) 101.90 (± 2.10 ms) -1.80% 👎
table-update-10th-1k metric base(2790bc6) target(7c31f72) trend
benchmark-table/update-10th/1k duration 91.00 (± 5.30 ms) 91.10 (± 5.00 ms) -0.11% 👌
tablecmp-append-1k metric base(2790bc6) target(7c31f72) trend
benchmark-table-component/append/1k duration 251.60 (± 4.30 ms) 255.60 (± 5.20 ms) -1.59% 👎
tablecmp-clear-1k metric base(2790bc6) target(7c31f72) trend
benchmark-table/clear/1k duration 34.80 (± 1.70 ms) 36.40 (± 1.40 ms) -4.60% 👎
tablecmp-create-10k metric base(2790bc6) target(7c31f72) trend
benchmark-table-component/create/10k duration 1665.80 (± 11.00 ms) 1719.30 (± 8.60 ms) -3.21% 👎
tablecmp-create-1k metric base(2790bc6) target(7c31f72) trend
benchmark-table-component/create/1k duration 194.90 (± 3.90 ms) 199.50 (± 3.80 ms) -2.36% 👎
tablecmp-update-10th-1k metric base(2790bc6) target(7c31f72) trend
benchmark-table-component/update-10th/1k duration 76.50 (± 4.30 ms) 72.60 (± 3.90 ms) 5.10% 👍

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 2790bc6 | Target commit: c90ef6c

lwc-engine-benchmark

table-append-1k metric base(2790bc6) target(c90ef6c) trend
benchmark-table/append/1k duration 151.00 (± 6.40 ms) 145.10 (± 3.70 ms) 3.91% 👌
table-clear-1k metric base(2790bc6) target(c90ef6c) trend
benchmark-table/clear/1k duration 11.20 (± 0.40 ms) 11.70 (± 0.50 ms) -4.46% 👎
table-create-10k metric base(2790bc6) target(c90ef6c) trend
benchmark-table/create/10k duration 835.90 (± 9.10 ms) 835.20 (± 6.50 ms) 0.08% 👌
table-create-1k metric base(2790bc6) target(c90ef6c) trend
benchmark-table/create/1k duration 100.10 (± 1.30 ms) 102.90 (± 1.80 ms) -2.80% 👎
table-update-10th-1k metric base(2790bc6) target(c90ef6c) trend
benchmark-table/update-10th/1k duration 91.00 (± 5.30 ms) 89.00 (± 5.80 ms) 2.20% 👌
tablecmp-append-1k metric base(2790bc6) target(c90ef6c) trend
benchmark-table-component/append/1k duration 251.60 (± 4.30 ms) 255.30 (± 5.40 ms) -1.47% 👎
tablecmp-clear-1k metric base(2790bc6) target(c90ef6c) trend
benchmark-table/clear/1k duration 34.80 (± 1.70 ms) 36.50 (± 1.60 ms) -4.89% 👎
tablecmp-create-10k metric base(2790bc6) target(c90ef6c) trend
benchmark-table-component/create/10k duration 1665.80 (± 11.00 ms) 1687.10 (± 9.10 ms) -1.28% 👎
tablecmp-create-1k metric base(2790bc6) target(c90ef6c) trend
benchmark-table-component/create/1k duration 194.90 (± 3.90 ms) 197.20 (± 3.30 ms) -1.18% 👎
tablecmp-update-10th-1k metric base(2790bc6) target(c90ef6c) trend
benchmark-table-component/update-10th/1k duration 76.50 (± 4.30 ms) 73.30 (± 3.60 ms) 4.18% 👍

@pmdartus pmdartus merged commit f44d252 into master May 31, 2018
@pmdartus pmdartus deleted the pmdartus/jest-restructure branch May 31, 2018 16:19
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.

None yet

4 participants