diff --git a/packages/menu/test/menu-memory.test.ts b/packages/menu/test/menu-memory.test.ts index 596d6b36f1..ea42723bc4 100644 --- a/packages/menu/test/menu-memory.test.ts +++ b/packages/menu/test/menu-memory.test.ts @@ -10,55 +10,9 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -import { expect, fixture, nextFrame } from '@open-wc/testing'; -import { html, render } from '@spectrum-web-components/base'; +import { fixture } from '@open-wc/testing'; import { singleSelect } from '../stories/menu.stories.js'; -import { usedHeapMB } from '../../../test/testing-helpers.js'; +import { Menu } from '@spectrum-web-components/menu'; +import { testForMemoryLeaks } from '../../../test/testing-helpers.js'; -describe('Menu memory usage', () => { - it('releases references on disconnect', async function () { - if (!window.gc || !('measureUserAgentSpecificMemory' in performance)) - this.skip(); - - this.timeout(10000); - - const iterations = 50; - let active = false; - - const el = await fixture( - html` -
- ` - ); - - async function toggle( - forced: boolean | undefined = undefined - ): Promise { - active = forced != null ? forced : !active; - render(active ? singleSelect() : html``, el); - await nextFrame(); - await nextFrame(); - } - - // "shake things out" to get a good first reading - for (let i = 0; i < 5; i++) { - await toggle(); - } - await toggle(false); - const beforeMB = await usedHeapMB(); - - for (let i = 0; i < iterations; i++) { - await toggle(); - } - await toggle(false); - const afterMB = await usedHeapMB(); - - expect( - afterMB.total - beforeMB.total, - `Total | before: ${beforeMB.total}, after: ${afterMB.total} -DOM | before: ${beforeMB.dom}, after: ${afterMB.dom} -JS | before: ${beforeMB.js}, after: ${afterMB.js} -Shared | before: ${beforeMB.shared}, after: ${afterMB.shared}` - ).to.be.lte(0); - }); -}); +testForMemoryLeaks(async () => await fixture(singleSelect())); diff --git a/tools/grid/test/grid-memory.test.ts b/tools/grid/test/grid-memory.test.ts index b9935272e0..243a3a5ea5 100644 --- a/tools/grid/test/grid-memory.test.ts +++ b/tools/grid/test/grid-memory.test.ts @@ -10,60 +10,9 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -import { expect, fixture, nextFrame } from '@open-wc/testing'; -import { html, render } from '@spectrum-web-components/base'; +import { fixture } from '@open-wc/testing'; import { Default } from '../stories/grid.stories.js'; -import { usedHeapMB } from '../../../test/testing-helpers.js'; +import { Grid } from '@spectrum-web-components/grid'; +import { testForMemoryLeaks } from '../../../test/testing-helpers.js'; -describe('Grid memory usage', () => { - it('releases references on disconnect', async function () { - if (!window.gc || !('measureUserAgentSpecificMemory' in performance)) - this.skip(); - - this.timeout(10000); - - const iterations = 50; - let active = false; - - const el = await fixture( - html` -
- ` - ); - - async function toggle( - forced: boolean | undefined = undefined - ): Promise { - active = forced != null ? forced : !active; - render(active ? Default() : html``, el); - await nextFrame(); - await nextFrame(); - } - - // "shake things out" to get a good first reading - for (let i = 0; i < 5; i++) { - await toggle(); - } - await toggle(false); - const beforeMB = await usedHeapMB(); - - for (let i = 0; i < iterations; i++) { - await toggle(); - } - await toggle(false); - const afterMB = await usedHeapMB(); - - /** - * An actually leak here shapes up to be more than 10MB per test, - * we could be more linient later, if needed, but the test currently - * shows less heap after the test cycle. - */ - expect( - afterMB.total - beforeMB.total, - `Total | before: ${beforeMB.total}, after: ${afterMB.total} -DOM | before: ${beforeMB.dom}, after: ${afterMB.dom} -JS | before: ${beforeMB.js}, after: ${afterMB.js} -Shared | before: ${beforeMB.shared}, after: ${afterMB.shared}` - ).to.be.lte(0); - }); -}); +testForMemoryLeaks(async () => await fixture(Default()));