-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(synthetic-shadow): add more tests/benchmarks (#4187)
- Loading branch information
1 parent
6a1b9b3
commit bd7bc7f
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
packages/@lwc/integration-karma/test/synthetic-shadow/shadow-token/index.spec.js
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,87 @@ | ||
import { IS_SYNTHETIC_SHADOW_LOADED } from 'test-utils'; | ||
|
||
// From @lwc/shared/src/keys.ts | ||
const KEY__SHADOW_RESOLVER = '$shadowResolver$'; | ||
const KEY__SHADOW_STATIC = '$shadowStaticNode$'; | ||
|
||
if (IS_SYNTHETIC_SHADOW_LOADED) { | ||
describe('sets shadow resolver correctly on static trees', () => { | ||
const fragments = [ | ||
'<div></div>', | ||
'<div>hello</div>', | ||
'<div><!-- foo --></div>', | ||
'<section><div></div><div></div></section>', | ||
'<section><div>hello</div><div></div></section>', | ||
'<section><div></div><div>hello</div></section>', | ||
'<section><div>hello</div><div>hello</div></section>', | ||
'<section><div><!-- foo --></div><div></div></section>', | ||
'<section><div></div><div><!-- foo --></div></section>', | ||
'<section><div><!-- foo --></div><div><!-- foo --></div></section>', | ||
'<section><div>hello</div><div><!-- foo --></div></section>', | ||
]; | ||
|
||
const scenarios = [ | ||
{}, | ||
{ | ||
withParent: true, | ||
}, | ||
{ | ||
withParent: true, | ||
withRightSibling: true, | ||
}, | ||
{ | ||
withParent: true, | ||
withLeftSibling: true, | ||
}, | ||
{ | ||
withParent: true, | ||
withLeftSibling: true, | ||
withRightSibling: true, | ||
}, | ||
]; | ||
|
||
fragments.forEach((fragment) => { | ||
scenarios.forEach(({ withParent, withRightSibling, withLeftSibling }) => { | ||
describe(`${withParent ? 'with parent' : 'without parent'}${ | ||
withLeftSibling ? ' and left sibling' : '' | ||
}${withRightSibling ? ' and right sibling' : ''}`, () => { | ||
it(fragment, () => { | ||
const parent = document.createElement('div'); | ||
parent.innerHTML = fragment; | ||
const root = parent.firstChild; | ||
|
||
if (!withParent) { | ||
parent.removeChild(root); | ||
} | ||
const leftSibling = document.createElement('div'); | ||
if (withLeftSibling) { | ||
parent.insertBefore(leftSibling, root); | ||
} | ||
const rightSibling = document.createElement('div'); | ||
if (withRightSibling) { | ||
parent.appendChild(rightSibling); | ||
} | ||
|
||
const resolver = () => {}; | ||
root[KEY__SHADOW_RESOLVER] = resolver; | ||
root[KEY__SHADOW_STATIC] = true; | ||
|
||
// ensure the shadow resolver is set on all nodes in the tree | ||
const expectShadowResolver = (node) => { | ||
expect(node[KEY__SHADOW_RESOLVER]).toBe(resolver); | ||
for (const childNode of Array.from(node.childNodes)) { | ||
expectShadowResolver(childNode); | ||
} | ||
}; | ||
expectShadowResolver(root); | ||
|
||
// ensure we don't traverse up past the root | ||
for (const node of [parent, leftSibling, rightSibling]) { | ||
expect(node[KEY__SHADOW_RESOLVER]).toBeUndefined(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
31 changes: 31 additions & 0 deletions
31
...chmarks/src/__benchmarks__/engine-dom/benchmark-table-ss/ss-table-create-10k.benchmark.js
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,31 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import '@lwc/synthetic-shadow'; | ||
import { createElement } from '@lwc/engine-dom'; | ||
|
||
import Table from '@lwc/perf-benchmarks-components/dist/dom/benchmark/table/table.js'; | ||
import Store from '@lwc/perf-benchmarks-components/dist/dom/benchmark/store/store.js'; | ||
import { insertComponent, destroyComponent } from '../../../utils/utils.js'; | ||
|
||
benchmark(`dom/table/synthetic-shadow/create/10k`, () => { | ||
let tableElement; | ||
|
||
before(() => { | ||
tableElement = createElement('benchmark-table', { is: Table }); | ||
return insertComponent(tableElement); | ||
}); | ||
|
||
run(() => { | ||
const store = new Store(); | ||
store.runLots(); | ||
tableElement.rows = store.data; | ||
}); | ||
|
||
after(() => { | ||
destroyComponent(tableElement); | ||
}); | ||
}); |