diff --git a/npm/angular/CHANGELOG.md b/npm/angular/CHANGELOG.md index 497d78066094..f81c22d0854c 100644 --- a/npm/angular/CHANGELOG.md +++ b/npm/angular/CHANGELOG.md @@ -1,3 +1,23 @@ +# [@cypress/angular-v2.0.1](https://github.com/cypress-io/cypress/compare/@cypress/angular-v2.0.0...@cypress/angular-v2.0.1) (2022-11-08) + + +### Bug Fixes + +* make component derived info not throw ([#24571](https://github.com/cypress-io/cypress/issues/24571)) ([838dd4f](https://github.com/cypress-io/cypress/commit/838dd4fa2e0ec56633d0af2faf10a47d190b5594)) + +# [@cypress/angular-v2.0.0](https://github.com/cypress-io/cypress/compare/@cypress/angular-v1.1.2...@cypress/angular-v2.0.0) (2022-11-07) + + +### Bug Fixes + +* possibility to override global services in Angular component tests ([#24394](https://github.com/cypress-io/cypress/issues/24394)) ([54d2853](https://github.com/cypress-io/cypress/commit/54d285321723450920e0f1d50374c4bd0590e72a)) +* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54)) + + +### BREAKING CHANGES + +* remove last mounted component upon subsequent mount calls of mount + # [@cypress/angular-v1.1.2](https://github.com/cypress-io/cypress/compare/@cypress/angular-v1.1.1...@cypress/angular-v1.1.2) (2022-10-11) diff --git a/npm/angular/src/mount.ts b/npm/angular/src/mount.ts index d45757ab721d..4ea70537f858 100644 --- a/npm/angular/src/mount.ts +++ b/npm/angular/src/mount.ts @@ -156,7 +156,7 @@ function bootstrapModule ( }) // check if the component is a standalone component - if ((component as any).ɵcmp.standalone) { + if ((component as any).ɵcmp?.standalone) { testModuleMetaData.imports.push(component) } else { testModuleMetaData.declarations.push(component) diff --git a/npm/mount-utils/CHANGELOG.md b/npm/mount-utils/CHANGELOG.md index 4dab067c7bb4..97153754cebd 100644 --- a/npm/mount-utils/CHANGELOG.md +++ b/npm/mount-utils/CHANGELOG.md @@ -1,3 +1,17 @@ +# [@cypress/mount-utils-v3.0.0](https://github.com/cypress-io/cypress/compare/@cypress/mount-utils-v2.1.0...@cypress/mount-utils-v3.0.0) (2022-11-07) + + +### Bug Fixes + +* remove dependence on @cypress/ types ([#24415](https://github.com/cypress-io/cypress/issues/24415)) ([58e0ab9](https://github.com/cypress-io/cypress/commit/58e0ab91604618ea6f75932622f7e66e419270e6)) +* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54)) +* remove some CT functions and props ([#24419](https://github.com/cypress-io/cypress/issues/24419)) ([294985f](https://github.com/cypress-io/cypress/commit/294985f8b3e0fa00ed66d25f88c8814603766074)) + + +### BREAKING CHANGES + +* remove last mounted component upon subsequent mount calls of mount + # [@cypress/mount-utils-v2.1.0](https://github.com/cypress-io/cypress/compare/@cypress/mount-utils-v2.0.1...@cypress/mount-utils-v2.1.0) (2022-08-30) diff --git a/npm/react/CHANGELOG.md b/npm/react/CHANGELOG.md index 817d0c090e39..eb4ff6d9e418 100644 --- a/npm/react/CHANGELOG.md +++ b/npm/react/CHANGELOG.md @@ -1,3 +1,23 @@ +# [@cypress/react-v7.0.1](https://github.com/cypress-io/cypress/compare/@cypress/react-v7.0.0...@cypress/react-v7.0.1) (2022-11-08) + + +### Bug Fixes + +* make component derived info not throw ([#24571](https://github.com/cypress-io/cypress/issues/24571)) ([838dd4f](https://github.com/cypress-io/cypress/commit/838dd4fa2e0ec56633d0af2faf10a47d190b5594)) + +# [@cypress/react-v7.0.0](https://github.com/cypress-io/cypress/compare/@cypress/react-v6.2.1...@cypress/react-v7.0.0) (2022-11-07) + + +### Bug Fixes + +* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54)) +* remove some CT functions and props ([#24419](https://github.com/cypress-io/cypress/issues/24419)) ([294985f](https://github.com/cypress-io/cypress/commit/294985f8b3e0fa00ed66d25f88c8814603766074)) + + +### BREAKING CHANGES + +* remove last mounted component upon subsequent mount calls of mount + # [@cypress/react-v6.2.1](https://github.com/cypress-io/cypress/compare/@cypress/react-v6.2.0...@cypress/react-v6.2.1) (2022-11-01) diff --git a/npm/react/src/createMount.ts b/npm/react/src/createMount.ts index 3f4f1dea6e0c..6e87da8e68e7 100644 --- a/npm/react/src/createMount.ts +++ b/npm/react/src/createMount.ts @@ -40,12 +40,6 @@ export const makeMountFn = ( mountCleanup = internalMountOptions.cleanup - // Get the display name property via the component constructor - // @ts-ignore FIXME - const componentName = getDisplayName(jsx.type) - - const jsxComponentName = `<${componentName} ... />` - return cy .then(() => { const reactDomToUse = internalMountOptions.reactDom @@ -99,6 +93,12 @@ export const makeMountFn = ( .wait(0, { log: false }) .then(() => { if (options.log !== false) { + // Get the display name property via the component constructor + // @ts-ignore FIXME + const componentName = getDisplayName(jsx) + + const jsxComponentName = `<${componentName} ... />` + Cypress.log({ name: type, type: 'parent', @@ -108,7 +108,7 @@ export const makeMountFn = ( consoleProps: () => { return { // @ts-ignore protect the use of jsx functional components use ReactNode - props: jsx.props, + props: jsx?.props, description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component', home: 'https://github.com/cypress-io/cypress', } diff --git a/npm/react/src/getDisplayName.ts b/npm/react/src/getDisplayName.ts index 4d455cf3615c..6a18faf40e3d 100644 --- a/npm/react/src/getDisplayName.ts +++ b/npm/react/src/getDisplayName.ts @@ -1,6 +1,6 @@ -type JSX = Function & { displayName: string } +import type { ReactNode } from 'react' -const cachedDisplayNames: WeakMap = new WeakMap() +type JSX = Function & { displayName: string } /** * Gets the display name of the component when possible. @@ -9,13 +9,13 @@ const cachedDisplayNames: WeakMap = new WeakMap() * @link https://github.com/facebook/react-devtools/blob/master/backend/getDisplayName.js */ export default function getDisplayName ( - type: JSX, + node: ReactNode, fallbackName: string = 'Unknown', ): string { - const nameFromCache = cachedDisplayNames.get(type) + const type: JSX | undefined = (node as any)?.type - if (nameFromCache != null) { - return nameFromCache + if (!type) { + return fallbackName } let displayName: string | null = null @@ -49,11 +49,5 @@ export default function getDisplayName ( } } - try { - cachedDisplayNames.set(type, displayName) - } catch (e) { - // do nothing - } - return displayName } diff --git a/npm/react18/CHANGELOG.md b/npm/react18/CHANGELOG.md index 33113627f9aa..4e67cf7e2407 100644 --- a/npm/react18/CHANGELOG.md +++ b/npm/react18/CHANGELOG.md @@ -1,3 +1,16 @@ +# [@cypress/react18-v2.0.0](https://github.com/cypress-io/cypress/compare/@cypress/react18-v1.1.1...@cypress/react18-v2.0.0) (2022-11-07) + + +### Bug Fixes + +* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54)) +* remove some CT functions and props ([#24419](https://github.com/cypress-io/cypress/issues/24419)) ([294985f](https://github.com/cypress-io/cypress/commit/294985f8b3e0fa00ed66d25f88c8814603766074)) + + +### BREAKING CHANGES + +* remove last mounted component upon subsequent mount calls of mount + # [@cypress/react18-v1.1.1](https://github.com/cypress-io/cypress/compare/@cypress/react18-v1.1.0...@cypress/react18-v1.1.1) (2022-10-13) diff --git a/npm/svelte/CHANGELOG.md b/npm/svelte/CHANGELOG.md index f87e981d5753..783bdaf600f9 100644 --- a/npm/svelte/CHANGELOG.md +++ b/npm/svelte/CHANGELOG.md @@ -1,3 +1,16 @@ +# [@cypress/svelte-v2.0.0](https://github.com/cypress-io/cypress/compare/@cypress/svelte-v1.0.2...@cypress/svelte-v2.0.0) (2022-11-07) + + +### Bug Fixes + +* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54)) +* remove some CT functions and props ([#24419](https://github.com/cypress-io/cypress/issues/24419)) ([294985f](https://github.com/cypress-io/cypress/commit/294985f8b3e0fa00ed66d25f88c8814603766074)) + + +### BREAKING CHANGES + +* remove last mounted component upon subsequent mount calls of mount + # [@cypress/svelte-v1.0.2](https://github.com/cypress-io/cypress/compare/@cypress/svelte-v1.0.1...@cypress/svelte-v1.0.2) (2022-11-01) diff --git a/npm/vite-dev-server/CHANGELOG.md b/npm/vite-dev-server/CHANGELOG.md index 4e617a88406b..6fcb11e650f6 100644 --- a/npm/vite-dev-server/CHANGELOG.md +++ b/npm/vite-dev-server/CHANGELOG.md @@ -1,3 +1,15 @@ +# [@cypress/vite-dev-server-v4.0.0](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v3.4.0...@cypress/vite-dev-server-v4.0.0) (2022-11-07) + + +### Bug Fixes + +* normalize vite config resolution ([#24369](https://github.com/cypress-io/cypress/issues/24369)) ([feba489](https://github.com/cypress-io/cypress/commit/feba489a9aeaddad3197764fe7e7405cfb4e7a56)) + + +### BREAKING CHANGES + +* vite.config.js is no longer merged when devServer.viteConfig is provided + # [@cypress/vite-dev-server-v3.4.0](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v3.3.1...@cypress/vite-dev-server-v3.4.0) (2022-11-01) diff --git a/npm/vue/CHANGELOG.md b/npm/vue/CHANGELOG.md index c5273798b851..019e48d7ab13 100644 --- a/npm/vue/CHANGELOG.md +++ b/npm/vue/CHANGELOG.md @@ -1,3 +1,30 @@ +# [@cypress/vue-v5.0.1](https://github.com/cypress-io/cypress/compare/@cypress/vue-v5.0.0...@cypress/vue-v5.0.1) (2022-11-08) + + +### Bug Fixes + +* make component derived info not throw ([#24571](https://github.com/cypress-io/cypress/issues/24571)) ([838dd4f](https://github.com/cypress-io/cypress/commit/838dd4fa2e0ec56633d0af2faf10a47d190b5594)) + +# [@cypress/vue-v5.0.0](https://github.com/cypress-io/cypress/compare/@cypress/vue-v4.2.2...@cypress/vue-v5.0.0) (2022-11-07) + + +### Bug Fixes + +* remove dependence on @cypress/ types ([#24415](https://github.com/cypress-io/cypress/issues/24415)) ([58e0ab9](https://github.com/cypress-io/cypress/commit/58e0ab91604618ea6f75932622f7e66e419270e6)) +* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54)) +* remove some CT functions and props ([#24419](https://github.com/cypress-io/cypress/issues/24419)) ([294985f](https://github.com/cypress-io/cypress/commit/294985f8b3e0fa00ed66d25f88c8814603766074)) + + +### Features + +* include component and wrapper in return type for vue mount adapter ([#24479](https://github.com/cypress-io/cypress/issues/24479)) ([33875d7](https://github.com/cypress-io/cypress/commit/33875d75505416b1f65ca7c6d5dedc46f3289f1b)) + + +### BREAKING CHANGES + +* remove last mounted component upon subsequent mount calls of mount +* Vue mount returns wrapper and component rather than wrapper only + # [@cypress/vue-v4.2.2](https://github.com/cypress-io/cypress/compare/@cypress/vue-v4.2.1...@cypress/vue-v4.2.2) (2022-11-01) diff --git a/npm/vue/src/index.ts b/npm/vue/src/index.ts index 5c19cfd95112..c94820bf83d6 100644 --- a/npm/vue/src/index.ts +++ b/npm/vue/src/index.ts @@ -370,7 +370,7 @@ export function mount< * Mounts a component and returns an object containing the component and VueWrapper * @param componentOptions * @param options - * @returns {Cypress.Chainable<{wrapper: VueWrapper, component: T} + * @returns {Cypress.Chainable<{wrapper: VueWrapper, component: T}>} * @see {@link https://on.cypress.io/mounting-vue} for more details. * @example * import { mount } from '@cypress/vue' @@ -387,9 +387,6 @@ export function mount (componentOptions: any, options: any = {}) { // Remove last mounted component if cy.mount is called more than once in a test cleanup() - // TODO: get the real displayName and props from VTU shallowMount - const componentName = getComponentDisplayName(componentOptions) - // then wait for cypress to load return cy.then(() => { // @ts-ignore diff --git a/npm/vue2/CHANGELOG.md b/npm/vue2/CHANGELOG.md index fe5c4a8c0d8a..722749d0c386 100644 --- a/npm/vue2/CHANGELOG.md +++ b/npm/vue2/CHANGELOG.md @@ -1,3 +1,23 @@ +# [@cypress/vue2-v2.0.0](https://github.com/cypress-io/cypress/compare/@cypress/vue2-v1.1.2...@cypress/vue2-v2.0.0) (2022-11-07) + + +### Bug Fixes + +* remove dependence on @cypress/ types ([#24415](https://github.com/cypress-io/cypress/issues/24415)) ([58e0ab9](https://github.com/cypress-io/cypress/commit/58e0ab91604618ea6f75932622f7e66e419270e6)) +* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54)) +* remove some CT functions and props ([#24419](https://github.com/cypress-io/cypress/issues/24419)) ([294985f](https://github.com/cypress-io/cypress/commit/294985f8b3e0fa00ed66d25f88c8814603766074)) + + +### Features + +* include component and wrapper in return type for vue mount adapter ([#24479](https://github.com/cypress-io/cypress/issues/24479)) ([33875d7](https://github.com/cypress-io/cypress/commit/33875d75505416b1f65ca7c6d5dedc46f3289f1b)) + + +### BREAKING CHANGES + +* remove last mounted component upon subsequent mount calls of mount +* Vue mount returns wrapper and component rather than wrapper only + # [@cypress/vue2-v1.1.2](https://github.com/cypress-io/cypress/compare/@cypress/vue2-v1.1.1...@cypress/vue2-v1.1.2) (2022-11-01) diff --git a/npm/webpack-dev-server/CHANGELOG.md b/npm/webpack-dev-server/CHANGELOG.md index 8793b4f537cd..f088b3f3df03 100644 --- a/npm/webpack-dev-server/CHANGELOG.md +++ b/npm/webpack-dev-server/CHANGELOG.md @@ -1,3 +1,17 @@ +# [@cypress/webpack-dev-server-v3.0.0](https://github.com/cypress-io/cypress/compare/@cypress/webpack-dev-server-v2.5.0...@cypress/webpack-dev-server-v3.0.0) (2022-11-07) + + +### Bug Fixes + +* normalize vite config resolution ([#24369](https://github.com/cypress-io/cypress/issues/24369)) ([feba489](https://github.com/cypress-io/cypress/commit/feba489a9aeaddad3197764fe7e7405cfb4e7a56)) +* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54)) + + +### BREAKING CHANGES + +* remove last mounted component upon subsequent mount calls of mount +* vite.config.js is no longer merged when devServer.viteConfig is provided + # [@cypress/webpack-dev-server-v2.5.0](https://github.com/cypress-io/cypress/compare/@cypress/webpack-dev-server-v2.4.1...@cypress/webpack-dev-server-v2.5.0) (2022-11-01) diff --git a/npm/webpack-preprocessor/CHANGELOG.md b/npm/webpack-preprocessor/CHANGELOG.md index fc90e6304add..15b0b8f8f146 100644 --- a/npm/webpack-preprocessor/CHANGELOG.md +++ b/npm/webpack-preprocessor/CHANGELOG.md @@ -1,3 +1,10 @@ +# [@cypress/webpack-preprocessor-v5.15.4](https://github.com/cypress-io/cypress/compare/@cypress/webpack-preprocessor-v5.15.3...@cypress/webpack-preprocessor-v5.15.4) (2022-11-07) + + +### Bug Fixes + +* remove some CT functions and props ([#24419](https://github.com/cypress-io/cypress/issues/24419)) ([294985f](https://github.com/cypress-io/cypress/commit/294985f8b3e0fa00ed66d25f88c8814603766074)) + # [@cypress/webpack-preprocessor-v5.15.3](https://github.com/cypress-io/cypress/compare/@cypress/webpack-preprocessor-v5.15.2...@cypress/webpack-preprocessor-v5.15.3) (2022-11-02) diff --git a/packages/driver/cypress/e2e/e2e/origin/snapshots.cy.ts b/packages/driver/cypress/e2e/e2e/origin/snapshots.cy.ts index 49da844ba0f6..1a7aa7070f32 100644 --- a/packages/driver/cypress/e2e/e2e/origin/snapshots.cy.ts +++ b/packages/driver/cypress/e2e/e2e/origin/snapshots.cy.ts @@ -2,107 +2,156 @@ import '../../../support/utils' describe('cy.origin - snapshots', { browser: '!webkit' }, () => { - const findLog = (logMap: Map, displayName: string, url: string) => { - return Array.from(logMap.values()).find((log: any) => { - const props = log.get() + it('does not create snapshots after the document has unloaded and the AUT has navigated cross-origin', () => { + cy.visit('/fixtures/generic.html') + cy.visit('http://www.foobar.com:3500/fixtures/generic.html') + cy.then(() => { + const snapshot = cy.createSnapshot() - return props.displayName === displayName && (props?.consoleProps?.URL === url || props?.consoleProps()?.URL === url) + expect(snapshot).to.be.null }) - } - let logs: Map + }) + + it('takes snapshots from the secondary origin even after the primary AUT has been unloaded from state', () => { + const findLog = (logMap: Map, selector) => { + return Array.from(logMap.values()).find((log: any) => { + const props = log.get() - beforeEach(() => { - logs = new Map() + return (props?.consoleProps?.Selector === selector) + }) + } + let logs: Map = new Map() cy.on('log:changed', (attrs, log) => { logs.set(attrs.id, log) }) - cy.fixture('foo.bar.baz.json').then((fooBarBaz) => { - cy.intercept('GET', '/foo.bar.baz.json', { body: fooBarBaz }).as('fooBarBaz') - }) - cy.visit('/fixtures/primary-origin.html') cy.get('a[data-cy="xhr-fetch-requests-onload"]').click() - }) - // TODO: the xhr event is showing up twice in the log, which is wrong and causing flake. skipping until: https://github.com/cypress-io/cypress/issues/23840 is addressed. - it.skip('verifies XHR requests made while a secondary origin is active eventually update with snapshots of the secondary origin', () => { cy.origin('http://www.foobar.com:3500', () => { - // need to set isInteractive in the spec bridge in order to take xhr snapshots in run mode, similar to how isInteractive is set within support/defaults.js + // need to set isInteractive in the spec bridge in order to take snapshots in run mode, similar to how isInteractive is set within support/defaults.js // @ts-ignore Cypress.config('isInteractive', true) - cy.visit('http://www.foobar.com:3500/fixtures/xhr-fetch-requests.html') - cy.get(`[data-cy="assertion-header"]`).should('exist') - cy.wait('@fooBarBaz') + cy.get(`[data-cy="assertion-header"]`) }) cy.shouldWithTimeout(() => { - const xhrLogFromSecondaryOrigin = findLog(logs, 'xhr', 'http://localhost:3500/foo.bar.baz.json')?.get() - - expect(xhrLogFromSecondaryOrigin).to.not.be.undefined + const getLogFromSecondaryOrigin = findLog(logs, '[data-cy="assertion-header"]')?.get() - const snapshots = xhrLogFromSecondaryOrigin.snapshots.map((snapshot) => snapshot.body.get()[0]) + expect(getLogFromSecondaryOrigin).to.exist - expect(snapshots.length).to.equal(2) + const snapshots = getLogFromSecondaryOrigin?.snapshots?.map((snapshot) => snapshot?.body.get()[0]) || [] - // TODO: Since we have two events, one of them does not have a request snapshot + expect(snapshots.length).to.equal(1) - expect(snapshots[1].querySelector(`[data-cy="assertion-header"]`)).to.have.property('innerText').that.equals('Making XHR and Fetch Requests behind the scenes if fireOnload is true!') + expect(snapshots[0].querySelector(`[data-cy="assertion-header"]`)).to.have.property('innerText').that.equals('Making XHR and Fetch Requests behind the scenes if fireOnload is true!') }) }) - // TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23437 - it.skip('verifies fetch requests made while a secondary origin is active eventually update with snapshots of the secondary origin', () => { - cy.origin('http://www.foobar.com:3500', () => { - // need to set isInteractive in the spec bridge in order to take xhr snapshots in run mode, similar to how isInteractive is set within support/defaults.js - // @ts-ignore - Cypress.config('isInteractive', true) - cy.visit('http://www.foobar.com:3500/fixtures/xhr-fetch-requests.html') - cy.get(`[data-cy="assertion-header"]`).should('exist') - cy.wait('@fooBarBaz') - }) + describe('e2e log verification', () => { + const findLog = (logMap: Map, displayName: string, url: string) => { + return Array.from(logMap.values()).find((log: any) => { + const props = log.get() - cy.shouldWithTimeout(() => { - const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'http://localhost:3500/foo.bar.baz.json')?.get() + return props.displayName === displayName && (props?.consoleProps?.URL === url || props?.consoleProps()?.URL === url) + }) + } + let logs: Map - expect(xhrLogFromSecondaryOrigin).to.not.be.undefined + beforeEach(() => { + logs = new Map() - const snapshots = xhrLogFromSecondaryOrigin.snapshots.map((snapshot) => snapshot.body.get()[0]) + cy.on('log:changed', (attrs, log) => { + logs.set(attrs.id, log) + }) - snapshots.forEach((snapshot) => { - expect(snapshot.querySelector(`[data-cy="assertion-header"]`)).to.have.property('innerText').that.equals('Making XHR and Fetch Requests behind the scenes if fireOnload is true!') + cy.fixture('foo.bar.baz.json').then((fooBarBaz) => { + cy.intercept('GET', '/foo.bar.baz.json', { body: fooBarBaz }).as('fooBarBaz') }) + + cy.visit('/fixtures/primary-origin.html') + cy.get('a[data-cy="xhr-fetch-requests-onload"]').click() }) - }) - it('Does not take snapshots of XHR/fetch requests from secondary origin if the wrong origin is / origin mismatch, but instead the primary origin (existing behavior)', { - defaultCommandTimeout: 50, - }, - (done) => { - cy.on('fail', () => { - const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'http://localhost:3500/foo.bar.baz.json')?.get() + // TODO: the xhr event is showing up twice in the log, which is wrong and causing flake. skipping until: https://github.com/cypress-io/cypress/issues/23840 is addressed. + it.skip('verifies XHR requests made while a secondary origin is active eventually update with snapshots of the secondary origin', () => { + cy.origin('http://www.foobar.com:3500', () => { + // need to set isInteractive in the spec bridge in order to take xhr snapshots in run mode, similar to how isInteractive is set within support/defaults.js + // @ts-ignore + Cypress.config('isInteractive', true) + cy.visit('http://www.foobar.com:3500/fixtures/xhr-fetch-requests.html') + cy.get(`[data-cy="assertion-header"]`).should('exist') + cy.wait('@fooBarBaz') + }) + + cy.shouldWithTimeout(() => { + const xhrLogFromSecondaryOrigin = findLog(logs, 'xhr', 'http://localhost:3500/foo.bar.baz.json')?.get() - expect(xhrLogFromSecondaryOrigin).to.not.be.undefined + expect(xhrLogFromSecondaryOrigin).to.exist - const snapshots = xhrLogFromSecondaryOrigin.snapshots.map((snapshot) => snapshot.body.get()[0]) + const snapshots = xhrLogFromSecondaryOrigin.snapshots.map((snapshot) => snapshot.body.get()[0]) - snapshots.forEach((snapshot) => { - expect(snapshot.querySelector(`[data-cy="assertion-header"]`)).to.be.null + expect(snapshots.length).to.equal(2) + + // TODO: Since we have two events, one of them does not have a request snapshot + + expect(snapshots[1].querySelector(`[data-cy="assertion-header"]`)).to.have.property('innerText').that.equals('Making XHR and Fetch Requests behind the scenes if fireOnload is true!') + }) + }) + + // TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23437 + it.skip('verifies fetch requests made while a secondary origin is active eventually update with snapshots of the secondary origin', () => { + cy.origin('http://www.foobar.com:3500', () => { + // need to set isInteractive in the spec bridge in order to take xhr snapshots in run mode, similar to how isInteractive is set within support/defaults.js + // @ts-ignore + Cypress.config('isInteractive', true) + cy.visit('http://www.foobar.com:3500/fixtures/xhr-fetch-requests.html') + cy.get(`[data-cy="assertion-header"]`).should('exist') + cy.wait('@fooBarBaz') }) - done() + cy.shouldWithTimeout(() => { + const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'http://localhost:3500/foo.bar.baz.json')?.get() + + expect(xhrLogFromSecondaryOrigin).to.exist + + const snapshots = xhrLogFromSecondaryOrigin.snapshots.map((snapshot) => snapshot.body.get()[0]) + + snapshots.forEach((snapshot) => { + expect(snapshot.querySelector(`[data-cy="assertion-header"]`)).to.have.property('innerText').that.equals('Making XHR and Fetch Requests behind the scenes if fireOnload is true!') + }) + }) }) - cy.visit('http://www.foobar.com:3500/fixtures/xhr-fetch-requests.html') + it('Does not take snapshots of XHR/fetch requests from secondary origin if the wrong origin is visited / origin mismatch, but instead the primary origin (existing behavior)', { + defaultCommandTimeout: 50, + }, + (done) => { + cy.on('fail', () => { + const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'http://localhost:3500/foo.bar.baz.json')?.get() - cy.origin('http://www.barbaz.com:3500', () => { - // need to set isInteractive in the spec bridge in order to take xhr snapshots in run mode, similar to how isInteractive is set within support/defaults.js - // @ts-ignore - Cypress.config('isInteractive', true) + expect(xhrLogFromSecondaryOrigin).to.exist + + const snapshots = xhrLogFromSecondaryOrigin.snapshots.map((snapshot) => snapshot.body.get()[0]) + + snapshots.forEach((snapshot) => { + expect(snapshot.querySelector(`[data-cy="assertion-header"]`)).to.be.null + }) + + done() + }) - cy.get(`[data-cy="assertion-header"]`).should('exist') - cy.wait('@fooBarBaz') + cy.visit('http://www.foobar.com:3500/fixtures/xhr-fetch-requests.html') + + cy.origin('http://www.barbaz.com:3500', () => { + // need to set isInteractive in the spec bridge in order to take xhr snapshots in run mode, similar to how isInteractive is set within support/defaults.js + // @ts-ignore + Cypress.config('isInteractive', true) + + cy.get(`[data-cy="assertion-header"]`).should('exist') + cy.wait('@fooBarBaz') + }) }) }) }) diff --git a/packages/driver/src/cy/snapshots.ts b/packages/driver/src/cy/snapshots.ts index 707a83fd0b39..b39ec8a5c25b 100644 --- a/packages/driver/src/cy/snapshots.ts +++ b/packages/driver/src/cy/snapshots.ts @@ -229,6 +229,15 @@ export const create = ($$: $Cy['$$'], state: StateFunc) => { const createSnapshot = (name, $elToHighlight, preprocessedSnapshot) => { Cypress.action('cy:snapshot', name) + // when using cy.origin() and in a transitionary state, state('document') + // can be undefined, resulting in a bizarre snapshot of the entire Cypress + // UI. better not to take the snapshot in that case. + // https://github.com/cypress-io/cypress/issues/24506 + // also, do not take the snapshot here if it has already been taken and + // preprocessed in a spec bridge. + if (!preprocessedSnapshot && !state('document')) { + return null + } try { const { @@ -241,7 +250,16 @@ export const create = ($$: $Cy['$$'], state: StateFunc) => { const body = { get: () => { if (!attachedBody) { - // If we don't have an AUT document, use the spec bridge document + // logs streaming in from the secondary need to be cloned off a document, + // which means state("document") will be undefined in the primary + // if a cy.origin block is active + + // this could also be possible, but unlikely, if the spec bridge is taking + // snapshots before the document has loaded into state, as could be the case with logs + // generated from before:load event handlers in a spec bridge + + // in any of these cases, fall back to the root document as we only + // need the document to clone the node. const doc = state('document') || window.document attachedBody = $$(doc.adoptNode($body[0])) diff --git a/system-tests/__snapshots__/component_testing_spec.ts.js b/system-tests/__snapshots__/component_testing_spec.ts.js index a8c09d0840e4..3ef7f1ac2cb2 100644 --- a/system-tests/__snapshots__/component_testing_spec.ts.js +++ b/system-tests/__snapshots__/component_testing_spec.ts.js @@ -156,19 +156,20 @@ exports['React major versions with Webpack executes all of the tests for React v mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -200,9 +201,9 @@ exports['React major versions with Webpack executes all of the tests for React v ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✔ All specs passed! XX:XX 9 9 - - - + ✔ All specs passed! XX:XX 10 10 - - - ` @@ -365,19 +366,20 @@ exports['React major versions with Webpack executes all of the tests for React v mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -409,9 +411,9 @@ exports['React major versions with Webpack executes all of the tests for React v ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✔ All specs passed! XX:XX 9 9 - - - + ✔ All specs passed! XX:XX 10 10 - - - ` @@ -573,19 +575,20 @@ exports['React major versions with Vite executes all of the tests for React v17 mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -617,9 +620,9 @@ exports['React major versions with Vite executes all of the tests for React v17 ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✔ All specs passed! XX:XX 9 9 - - - + ✔ All specs passed! XX:XX 10 10 - - - ` @@ -781,19 +784,20 @@ exports['React major versions with Vite executes all of the tests for React v18 mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -825,9 +829,9 @@ exports['React major versions with Vite executes all of the tests for React v18 ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Rerendering.cy.jsx XX:XX 1 1 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✔ All specs passed! XX:XX 9 9 - - - + ✔ All specs passed! XX:XX 10 10 - - - ` diff --git a/system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js b/system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js index 8e0d03dcf76a..55275368df81 100644 --- a/system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js +++ b/system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js @@ -363,19 +363,20 @@ https://on.cypress.io/uncaught-exception-from-application mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -413,9 +414,9 @@ https://on.cypress.io/uncaught-exception-from-application ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✖ 4 of 8 failed (50%) XX:XX 15 8 7 - - + ✖ 4 of 8 failed (50%) XX:XX 16 9 7 - - ` @@ -785,19 +786,20 @@ https://on.cypress.io/uncaught-exception-from-application mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -835,9 +837,9 @@ https://on.cypress.io/uncaught-exception-from-application ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✖ 4 of 8 failed (50%) XX:XX 15 8 7 - - + ✖ 4 of 8 failed (50%) XX:XX 16 9 7 - - ` @@ -1207,19 +1209,20 @@ https://on.cypress.io/uncaught-exception-from-application mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -1257,9 +1260,9 @@ https://on.cypress.io/uncaught-exception-from-application ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✖ 4 of 8 failed (50%) XX:XX 15 8 7 - - + ✖ 4 of 8 failed (50%) XX:XX 16 9 7 - - ` diff --git a/system-tests/__snapshots__/webpack_dev_server_fresh_spec.ts.js b/system-tests/__snapshots__/webpack_dev_server_fresh_spec.ts.js index b6822aac2175..70cf4952478d 100644 --- a/system-tests/__snapshots__/webpack_dev_server_fresh_spec.ts.js +++ b/system-tests/__snapshots__/webpack_dev_server_fresh_spec.ts.js @@ -374,19 +374,20 @@ https://on.cypress.io/uncaught-exception-from-application mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -424,9 +425,9 @@ https://on.cypress.io/uncaught-exception-from-application ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✖ 4 of 8 failed (50%) XX:XX 15 8 7 - - + ✖ 4 of 8 failed (50%) XX:XX 16 9 7 - - ` @@ -816,19 +817,20 @@ https://on.cypress.io/uncaught-exception-from-application mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -866,9 +868,9 @@ https://on.cypress.io/uncaught-exception-from-application ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✖ 4 of 8 failed (50%) XX:XX 15 8 7 - - + ✖ 4 of 8 failed (50%) XX:XX 16 9 7 - - ` @@ -1249,19 +1251,20 @@ https://on.cypress.io/uncaught-exception-from-application mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -1299,9 +1302,9 @@ https://on.cypress.io/uncaught-exception-from-application ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✖ 4 of 8 failed (50%) XX:XX 15 8 7 - - + ✖ 4 of 8 failed (50%) XX:XX 16 9 7 - - ` @@ -1694,19 +1697,20 @@ https://on.cypress.io/uncaught-exception-from-application mount + ✓ does not error when rendering primitives teardown ✓ should mount ✓ should remove previous mounted component - 2 passing + 3 passing (Results) ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ Tests: 2 │ - │ Passing: 2 │ + │ Tests: 3 │ + │ Passing: 3 │ │ Failing: 0 │ │ Pending: 0 │ │ Skipped: 0 │ @@ -1744,9 +1748,9 @@ https://on.cypress.io/uncaught-exception-from-application ├────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ✔ Unmount.cy.jsx XX:XX 3 3 - - - │ ├────────────────────────────────────────────────────────────────────────────────────────────────┤ - │ ✔ mount.cy.jsx XX:XX 2 2 - - - │ + │ ✔ mount.cy.jsx XX:XX 3 3 - - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✖ 4 of 8 failed (50%) XX:XX 15 8 7 - - + ✖ 4 of 8 failed (50%) XX:XX 16 9 7 - - ` 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 1c152d217c9b..a3c7352be12d 100644 --- a/system-tests/project-fixtures/angular/src/app/mount.cy.ts +++ b/system-tests/project-fixtures/angular/src/app/mount.cy.ts @@ -447,4 +447,16 @@ describe('angular mount', () => { cy.get('[id^=root]').children().should('have.length', 1) }) }); + + it('should error when passing in undecorated component', () => { + Cypress.on('fail', (err) => { + expect(err.message).contain("Please add a @Pipe/@Directive/@Component"); + + return false + }) + + class MyClass {} + + cy.mount(MyClass) + }) }); diff --git a/system-tests/project-fixtures/react/src/mount.cy.jsx b/system-tests/project-fixtures/react/src/mount.cy.jsx index 52d5afa6cd82..42d9c975f651 100644 --- a/system-tests/project-fixtures/react/src/mount.cy.jsx +++ b/system-tests/project-fixtures/react/src/mount.cy.jsx @@ -24,4 +24,11 @@ describe('mount', () => { cy.get('[data-cy-root]').children().should('have.length', 1) }) }); + + it('does not error when rendering primitives', () => { + cy.mount('Hello World') + cy.mount(5) + cy.mount(null) + cy.mount(undefined) + }) }) \ No newline at end of file