From 27e2ba167553b36673abec5a82881a5e0d8e2446 Mon Sep 17 00:00:00 2001 From: Rajdeep Chandra Date: Thu, 28 Mar 2024 16:44:16 +0530 Subject: [PATCH 1/6] test: added memory tests in packages --- .../accordion/test/accordion-memory.test.ts | 71 +++++++++++++++++++ .../action-bar/test/action-bar-memory.test.ts | 71 +++++++++++++++++++ .../test/action-group-memory.test.ts | 71 +++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 packages/accordion/test/accordion-memory.test.ts create mode 100644 packages/action-bar/test/action-bar-memory.test.ts create mode 100644 packages/action-group/test/action-group-memory.test.ts diff --git a/packages/accordion/test/accordion-memory.test.ts b/packages/accordion/test/accordion-memory.test.ts new file mode 100644 index 0000000000..ec44a323b1 --- /dev/null +++ b/packages/accordion/test/accordion-memory.test.ts @@ -0,0 +1,71 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { expect, fixture, nextFrame } from '@open-wc/testing'; +import { html, render } from '@spectrum-web-components/base'; +import { Default } from '../stories/accordion.stories.js'; +import { usedHeapMB } 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 ? 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(); + + expect( + afterMB.dom - beforeMB.dom, + `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); + expect( + afterMB.js - beforeMB.js, + `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); + }); +}); diff --git a/packages/action-bar/test/action-bar-memory.test.ts b/packages/action-bar/test/action-bar-memory.test.ts new file mode 100644 index 0000000000..c4815546a3 --- /dev/null +++ b/packages/action-bar/test/action-bar-memory.test.ts @@ -0,0 +1,71 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { expect, fixture, nextFrame } from '@open-wc/testing'; +import { html, render } from '@spectrum-web-components/base'; +import { Default } from '../stories/action-bar.stories.js'; +import { usedHeapMB } 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 ? 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(); + + expect( + afterMB.dom - beforeMB.dom, + `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); + expect( + afterMB.js - beforeMB.js, + `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); + }); +}); diff --git a/packages/action-group/test/action-group-memory.test.ts b/packages/action-group/test/action-group-memory.test.ts new file mode 100644 index 0000000000..7b62766d11 --- /dev/null +++ b/packages/action-group/test/action-group-memory.test.ts @@ -0,0 +1,71 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { expect, fixture, nextFrame } from '@open-wc/testing'; +import { html, render } from '@spectrum-web-components/base'; +import { Default } from '../stories/action-group.stories.js'; +import { usedHeapMB } 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 ? 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(); + + expect( + afterMB.dom - beforeMB.dom, + `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); + expect( + afterMB.js - beforeMB.js, + `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); + }); +}); From cd42607524de1c9eb7b56bda1943ade0da84134f Mon Sep 17 00:00:00 2001 From: Rajdeep Chandra Date: Thu, 28 Mar 2024 17:09:45 +0530 Subject: [PATCH 2/6] test: updated memory tests in packages --- packages/accordion/test/accordion-memory.test.ts | 10 ++-------- packages/action-bar/test/action-bar-memory.test.ts | 10 ++-------- packages/action-group/test/action-group-memory.test.ts | 10 ++-------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/packages/accordion/test/accordion-memory.test.ts b/packages/accordion/test/accordion-memory.test.ts index ec44a323b1..4e4bb82188 100644 --- a/packages/accordion/test/accordion-memory.test.ts +++ b/packages/accordion/test/accordion-memory.test.ts @@ -55,17 +55,11 @@ describe('Menu memory usage', () => { expect( afterMB.dom - beforeMB.dom, - `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}` + `DOM | before: ${beforeMB.dom}, after: ${afterMB.dom}` ).to.be.lte(0); expect( afterMB.js - beforeMB.js, - `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}` + `JS | before: ${beforeMB.js}, after: ${afterMB.js}` ).to.be.lte(0); }); }); diff --git a/packages/action-bar/test/action-bar-memory.test.ts b/packages/action-bar/test/action-bar-memory.test.ts index c4815546a3..2cd77bf690 100644 --- a/packages/action-bar/test/action-bar-memory.test.ts +++ b/packages/action-bar/test/action-bar-memory.test.ts @@ -55,17 +55,11 @@ describe('Menu memory usage', () => { expect( afterMB.dom - beforeMB.dom, - `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}` + `DOM | before: ${beforeMB.dom}, after: ${afterMB.dom}` ).to.be.lte(0); expect( afterMB.js - beforeMB.js, - `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}` + `JS | before: ${beforeMB.js}, after: ${afterMB.js}` ).to.be.lte(0); }); }); diff --git a/packages/action-group/test/action-group-memory.test.ts b/packages/action-group/test/action-group-memory.test.ts index 7b62766d11..cd9a10a0b7 100644 --- a/packages/action-group/test/action-group-memory.test.ts +++ b/packages/action-group/test/action-group-memory.test.ts @@ -55,17 +55,11 @@ describe('Menu memory usage', () => { expect( afterMB.dom - beforeMB.dom, - `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}` + `DOM | before: ${beforeMB.dom}, after: ${afterMB.dom}` ).to.be.lte(0); expect( afterMB.js - beforeMB.js, - `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}` + `JS | before: ${beforeMB.js}, after: ${afterMB.js}` ).to.be.lte(0); }); }); From 6f72dcbe27b53d2de67c55811097acb63b1a9e76 Mon Sep 17 00:00:00 2001 From: Rajdeep Chandra Date: Mon, 1 Apr 2024 16:46:11 +0530 Subject: [PATCH 3/6] chore: asbtracted the memory profiler as a testing helper --- .../accordion/test/accordion-memory.test.ts | 55 ++--------------- .../action-bar/test/action-bar-memory.test.ts | 55 ++--------------- .../test/action-group-memory.test.ts | 55 ++--------------- test/testing-helpers.ts | 59 ++++++++++++++++++- 4 files changed, 70 insertions(+), 154 deletions(-) diff --git a/packages/accordion/test/accordion-memory.test.ts b/packages/accordion/test/accordion-memory.test.ts index 4e4bb82188..46b02a9724 100644 --- a/packages/accordion/test/accordion-memory.test.ts +++ b/packages/accordion/test/accordion-memory.test.ts @@ -10,56 +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/accordion.stories.js'; -import { usedHeapMB } from '../../../test/testing-helpers.js'; +import { Accordion } from '@spectrum-web-components/accordion'; +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 ? 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(); - - expect( - afterMB.dom - beforeMB.dom, - `DOM | before: ${beforeMB.dom}, after: ${afterMB.dom}` - ).to.be.lte(0); - expect( - afterMB.js - beforeMB.js, - `JS | before: ${beforeMB.js}, after: ${afterMB.js}` - ).to.be.lte(0); - }); -}); +testForMemoryLeaks(async () => await fixture(Default())); diff --git a/packages/action-bar/test/action-bar-memory.test.ts b/packages/action-bar/test/action-bar-memory.test.ts index 2cd77bf690..5801f4c65a 100644 --- a/packages/action-bar/test/action-bar-memory.test.ts +++ b/packages/action-bar/test/action-bar-memory.test.ts @@ -10,56 +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/action-bar.stories.js'; -import { usedHeapMB } from '../../../test/testing-helpers.js'; +import { ActionBar } from '@spectrum-web-components/action-bar'; +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 ? 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(); - - expect( - afterMB.dom - beforeMB.dom, - `DOM | before: ${beforeMB.dom}, after: ${afterMB.dom}` - ).to.be.lte(0); - expect( - afterMB.js - beforeMB.js, - `JS | before: ${beforeMB.js}, after: ${afterMB.js}` - ).to.be.lte(0); - }); -}); +testForMemoryLeaks(async () => await fixture(Default())); diff --git a/packages/action-group/test/action-group-memory.test.ts b/packages/action-group/test/action-group-memory.test.ts index cd9a10a0b7..b0523e18e8 100644 --- a/packages/action-group/test/action-group-memory.test.ts +++ b/packages/action-group/test/action-group-memory.test.ts @@ -10,56 +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/action-group.stories.js'; -import { usedHeapMB } from '../../../test/testing-helpers.js'; +import { ActionGroup } from '@spectrum-web-components/action-group'; +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 ? 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(); - - expect( - afterMB.dom - beforeMB.dom, - `DOM | before: ${beforeMB.dom}, after: ${afterMB.dom}` - ).to.be.lte(0); - expect( - afterMB.js - beforeMB.js, - `JS | before: ${beforeMB.js}, after: ${afterMB.js}` - ).to.be.lte(0); - }); -}); +testForMemoryLeaks(async () => await fixture(Default({}))); diff --git a/test/testing-helpers.ts b/test/testing-helpers.ts index b1b0b664b4..c82d2683ab 100644 --- a/test/testing-helpers.ts +++ b/test/testing-helpers.ts @@ -16,7 +16,7 @@ import { nextFrame, fixture as owcFixture, } from '@open-wc/testing'; -import { html } from '@spectrum-web-components/base'; +import { html, render } from '@spectrum-web-components/base'; import { SinonStub, spy, stub } from 'sinon'; import type { HookFunction } from 'mocha'; import '@spectrum-web-components/theme/sp-theme.js'; @@ -53,6 +53,63 @@ export async function testForLitDevWarnings( }); } +export async function testForMemoryLeaks( + element: () => Promise +): Promise { + describe('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; + + // Call fixture with 'htmlString' as the additional argument + const el = await fixture( + html` +
+ ` + ); + + async function toggle( + forced: boolean | undefined = undefined + ): Promise { + active = forced != null ? forced : !active; + render(active ? element : 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.dom - beforeMB.dom, + `DOM | before: ${beforeMB.dom}, after: ${afterMB.dom}` + ).to.be.lte(0); + expect( + afterMB.js - beforeMB.js, + `JS | before: ${beforeMB.js}, after: ${afterMB.js}` + ).to.be.lte(0); + }); + }); +} + export function waitForPredicate( predicateFn: () => boolean | undefined, timeout: number = 250 From 407f3cabb6e3616dae216e6b6ec863ab2841d576 Mon Sep 17 00:00:00 2001 From: Rajdeep Chandra Date: Mon, 1 Apr 2024 17:39:53 +0530 Subject: [PATCH 4/6] chore: added memory tests for components --- .../test/action-menu-memory.test.ts | 18 ++++++++++++++++++ .../test/alert-dialog-memory.test.ts | 18 ++++++++++++++++++ packages/asset/test/asset-memory.test.ts | 18 ++++++++++++++++++ packages/avatar/test/avatar-memory.test.ts | 18 ++++++++++++++++++ packages/badge/test/badge-memory.test.ts | 18 ++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 packages/action-menu/test/action-menu-memory.test.ts create mode 100644 packages/alert-dialog/test/alert-dialog-memory.test.ts create mode 100644 packages/asset/test/asset-memory.test.ts create mode 100644 packages/avatar/test/avatar-memory.test.ts create mode 100644 packages/badge/test/badge-memory.test.ts diff --git a/packages/action-menu/test/action-menu-memory.test.ts b/packages/action-menu/test/action-menu-memory.test.ts new file mode 100644 index 0000000000..311c268c1d --- /dev/null +++ b/packages/action-menu/test/action-menu-memory.test.ts @@ -0,0 +1,18 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { fixture } from '@open-wc/testing'; +import { Default } from '../stories/action-menu.stories.js'; +import { ActionMenu } from '@spectrum-web-components/action-menu'; +import { testForMemoryLeaks } from '../../../test/testing-helpers.js'; + +testForMemoryLeaks(async () => await fixture(Default({}))); diff --git a/packages/alert-dialog/test/alert-dialog-memory.test.ts b/packages/alert-dialog/test/alert-dialog-memory.test.ts new file mode 100644 index 0000000000..1b2c78a820 --- /dev/null +++ b/packages/alert-dialog/test/alert-dialog-memory.test.ts @@ -0,0 +1,18 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { fixture } from '@open-wc/testing'; +import { confirmation } from '../stories/alert-dialog.stories.js'; +import { AlertDialog } from '@spectrum-web-components/alert-dialog'; +import { testForMemoryLeaks } from '../../../test/testing-helpers.js'; + +testForMemoryLeaks(async () => await fixture(confirmation())); diff --git a/packages/asset/test/asset-memory.test.ts b/packages/asset/test/asset-memory.test.ts new file mode 100644 index 0000000000..f673ea9a72 --- /dev/null +++ b/packages/asset/test/asset-memory.test.ts @@ -0,0 +1,18 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { fixture } from '@open-wc/testing'; +import { Default } from '../stories/asset.stories.js'; +import { Asset } from '@spectrum-web-components/asset'; +import { testForMemoryLeaks } from '../../../test/testing-helpers.js'; + +testForMemoryLeaks(async () => await fixture(Default())); diff --git a/packages/avatar/test/avatar-memory.test.ts b/packages/avatar/test/avatar-memory.test.ts new file mode 100644 index 0000000000..fcbeb72eda --- /dev/null +++ b/packages/avatar/test/avatar-memory.test.ts @@ -0,0 +1,18 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { fixture } from '@open-wc/testing'; +import { linked } from '../stories/avatar.stories.js'; +import { Avatar } from '@spectrum-web-components/avatar'; +import { testForMemoryLeaks } from '../../../test/testing-helpers.js'; + +testForMemoryLeaks(async () => await fixture(linked())); diff --git a/packages/badge/test/badge-memory.test.ts b/packages/badge/test/badge-memory.test.ts new file mode 100644 index 0000000000..ed5fea29f6 --- /dev/null +++ b/packages/badge/test/badge-memory.test.ts @@ -0,0 +1,18 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { fixture } from '@open-wc/testing'; +import { Default } from '../stories/badge.stories.js'; +import { Badge } from '@spectrum-web-components/badge'; +import { testForMemoryLeaks } from '../../../test/testing-helpers.js'; + +testForMemoryLeaks(async () => await fixture(Default())); From 20e31f4930a84bb14ca573f729d57938dcf2798f Mon Sep 17 00:00:00 2001 From: Rajdeep Chandra Date: Tue, 2 Apr 2024 13:41:32 +0530 Subject: [PATCH 5/6] chore: update grid and menu to use testing helper --- packages/menu/test/menu-memory.test.ts | 54 ++--------------------- tools/grid/test/grid-memory.test.ts | 59 ++------------------------ 2 files changed, 8 insertions(+), 105 deletions(-) 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())); From a8aa6f0e5c20c6057dae7f192653362cafcd69b1 Mon Sep 17 00:00:00 2001 From: Rajdeep Chandra Date: Tue, 2 Apr 2024 16:12:58 +0530 Subject: [PATCH 6/6] chore: added mem test for card, button and button group --- .../test/button-group-memory.test.ts | 18 ++++++++++++++++++ packages/button/test/button-memory.test.ts | 18 ++++++++++++++++++ packages/card/test/card-memory.test.ts | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 packages/button-group/test/button-group-memory.test.ts create mode 100644 packages/button/test/button-memory.test.ts create mode 100644 packages/card/test/card-memory.test.ts diff --git a/packages/button-group/test/button-group-memory.test.ts b/packages/button-group/test/button-group-memory.test.ts new file mode 100644 index 0000000000..bc476b65e9 --- /dev/null +++ b/packages/button-group/test/button-group-memory.test.ts @@ -0,0 +1,18 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { fixture } from '@open-wc/testing'; +import { buttons } from '../stories/button-group.stories.js'; +import { ButtonGroup } from '@spectrum-web-components/button-group'; +import { testForMemoryLeaks } from '../../../test/testing-helpers.js'; + +testForMemoryLeaks(async () => await fixture(buttons({}))); diff --git a/packages/button/test/button-memory.test.ts b/packages/button/test/button-memory.test.ts new file mode 100644 index 0000000000..07c7e375c3 --- /dev/null +++ b/packages/button/test/button-memory.test.ts @@ -0,0 +1,18 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { fixture } from '@open-wc/testing'; +import { Default } from '../stories/button-accent-fill.stories.js'; +import { Button } from '@spectrum-web-components/button'; +import { testForMemoryLeaks } from '../../../test/testing-helpers.js'; + +testForMemoryLeaks(async () => await fixture