From 4bf516aef3cc12741921186071840e5e4fc1286a Mon Sep 17 00:00:00 2001 From: Zachary Williams Date: Tue, 14 Feb 2023 09:42:37 -0600 Subject: [PATCH 1/5] fix(angular): mount component in [data-cy-root] --- npm/angular/src/mount.ts | 20 +++++++++++++++++++ .../angular/src/app/mount.cy.ts | 7 +++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/npm/angular/src/mount.ts b/npm/angular/src/mount.ts index a0be116911b2..be8c85294eea 100644 --- a/npm/angular/src/mount.ts +++ b/npm/angular/src/mount.ts @@ -14,6 +14,7 @@ import { getTestBed, TestModuleMetadata, TestBed, + TestComponentRenderer, } from '@angular/core/testing' import { BrowserDynamicTestingModule, @@ -21,6 +22,7 @@ import { } from '@angular/platform-browser-dynamic/testing' import { setupHooks, + getContainerEl, } from '@cypress/mount-utils' /** @@ -169,6 +171,22 @@ function bootstrapModule ( return testModuleMetaData } +@Injectable() +export class CypressTestComponentRenderer extends TestComponentRenderer { + override insertRootElement (rootElId: string) { + this.removeAllRootElements() + + const rootElement = getContainerEl() + + rootElement.setAttribute('id', rootElId) + document.body.appendChild(rootElement) + } + + override removeAllRootElements () { + getContainerEl().innerHTML = '' + } +} + /** * Initializes the TestBed * @@ -186,6 +204,8 @@ function initTestBed ( ...bootstrapModule(componentFixture, config), }) + getTestBed().overrideProvider(TestComponentRenderer, { useValue: new CypressTestComponentRenderer() }) + return componentFixture } diff --git a/system-tests/project-fixtures/angular/src/app/mount.cy.ts b/system-tests/project-fixtures/angular/src/app/mount.cy.ts index e507f6d25e4a..4b2dae2da823 100644 --- a/system-tests/project-fixtures/angular/src/app/mount.cy.ts +++ b/system-tests/project-fixtures/angular/src/app/mount.cy.ts @@ -441,12 +441,15 @@ describe('angular mount', () => { }) describe('teardown', () => { + const cyRootSelector = '[data-cy-root]' + beforeEach(() => { - cy.get('[id^=root]').should('not.exist') + cy.get(cyRootSelector).should('be.empty') }) it('should mount', () => { cy.mount(ButtonOutputComponent) + cy.get(cyRootSelector).should('not.be.empty') }) it('should remove previous mounted component', () => { @@ -456,7 +459,7 @@ describe('angular mount', () => { cy.contains('Render 2') cy.contains('Render 1').should('not.exist') - cy.get('[id^=root]').children().should('have.length', 1) + cy.get(cyRootSelector).children().should('have.length', 1) }) }) From a9f06719d260223b056b840bd736d0294898b419 Mon Sep 17 00:00:00 2001 From: Zachary Williams Date: Tue, 14 Feb 2023 10:33:59 -0600 Subject: [PATCH 2/5] fix e2e test --- .../cypress/e2e/runner/reporter-ct-mount-hover.cy.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/app/cypress/e2e/runner/reporter-ct-mount-hover.cy.ts b/packages/app/cypress/e2e/runner/reporter-ct-mount-hover.cy.ts index e48055f7e349..4c4190036b10 100644 --- a/packages/app/cypress/e2e/runner/reporter-ct-mount-hover.cy.ts +++ b/packages/app/cypress/e2e/runner/reporter-ct-mount-hover.cy.ts @@ -42,13 +42,9 @@ for (const { projectName, test } of PROJECTS) { cy.contains(`${test}`).click() cy.waitForSpecToFinish(undefined) cy.get('.command.command-name-mount > .command-wrapper').click().then(() => { - if (`${projectName}` === 'angular-14') { - cy.get('iframe.aut-iframe').its('0.contentDocument.body').children().should('have.length.at.least', 2) - } else { - cy.get('iframe.aut-iframe').its('0.contentDocument.body').then(cy.wrap).within(() => { - cy.get('[data-cy-root]').children().should('have.length.at.least', 1) - }) - } + cy.get('iframe.aut-iframe').its('0.contentDocument.body').then(cy.wrap).within(() => { + cy.get('[data-cy-root]').children().should('have.length.at.least', 1) + }) }) } }) From 306db99d2636004525ab98920b5da64f19840ec8 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Fri, 17 Feb 2023 14:20:40 +1000 Subject: [PATCH 3/5] add changelog entry --- cli/CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 4c2141b646f7..6ca3dc982d00 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,4 +1,15 @@ + +## 12.7.0 + +_Released 03/01/2023 (PENDING)_ + +**Features:** + +**Bugfixes:** + +- Ensure Angular components are mounted inside the correct element. Fixes [#24385] + ## 12.6.0 _Released 02/14/2023 (PENDING)_ From 2fb7845bed376e466d65e8b83a43cea81a1f27c2 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Fri, 17 Feb 2023 20:17:41 +1000 Subject: [PATCH 4/5] changelog [skip ci] --- cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 365e18c9b33d..3bba988f8543 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -8,7 +8,7 @@ _Released 03/1/2023 (PENDING)_ - Fixed an issue where cookies were being duplicated with the same hostname, but a prepended dot. Fixed an issue where cookies may not be expiring correctly. Fixes [#25174](https://github.com/cypress-io/cypress/issues/25174), [#25205](https://github.com/cypress-io/cypress/issues/25205) and [#25495](https://github.com/cypress-io/cypress/issues/25495). - Added missing TypeScript type definitions for the [`cy.reload()`](https://docs.cypress.io/api/commands/reload) command. Addressed in [#25779](https://github.com/cypress-io/cypress/pull/25779). -- Ensure Angular components are mounted inside the correct element. Fixes [#24385] +- Ensure Angular components are mounted inside the correct element. Fixes [#24385](https://github.com/cypress-io/cypress/issues/24385) - Fix a bug where files outside the project root in a monorepo are not correctly served when using Vite. Addressed in [#25801](https://github.com/cypress-io/cypress/pull/25801) **Misc:** From 6cb362c2d94da9845c2ece60f5525036ea536f99 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Fri, 17 Feb 2023 20:20:34 +1000 Subject: [PATCH 5/5] changelog --- cli/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 3bba988f8543..3e39c4342c6d 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,5 +1,4 @@ - ## 12.6.1 _Released 03/1/2023 (PENDING)_