Skip to content

Commit

Permalink
fix: Hovering over mount in command log does not show component in AUT (
Browse files Browse the repository at this point in the history
#24346)

Co-authored-by: Mark Noonan <[email protected]>
Co-authored-by: Lachlan Miller <[email protected]>
Co-authored-by: Zachary Williams <[email protected]>
  • Loading branch information
4 people authored Nov 1, 2022
1 parent 239d2e3 commit 355d210
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 43 deletions.
35 changes: 17 additions & 18 deletions npm/react/src/createMount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,6 @@ export const makeMountFn = (

internalMountOptions.render(reactComponent, el, reactDomToUse)

if (options.log !== false) {
Cypress.log({
name: type,
type: 'parent',
message: [message],
// @ts-ignore
$el: (el.children.item(0) as unknown) as JQuery<HTMLElement>,
consoleProps: () => {
return {
// @ts-ignore protect the use of jsx functional components use ReactNode
props: jsx.props,
description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
home: 'https://github.com/cypress-io/cypress',
}
},
}).snapshot('mounted').end()
}

return (
// Separate alias and returned value. Alias returns the component only, and the thenable returns the additional functions
cy.wrap<React.ReactNode>(userComponent, { log: false })
Expand All @@ -123,6 +105,23 @@ export const makeMountFn = (
// and letting hooks and component lifecycle methods to execute mount
// https://github.com/bahmutov/cypress-react-unit-test/issues/200
.wait(0, { log: false })
.then(() => {
Cypress.log({
name: type,
type: 'parent',
message: [message],
// @ts-ignore
$el: (el.children.item(0) as unknown) as JQuery<HTMLElement>,
consoleProps: () => {
return {
// @ts-ignore protect the use of jsx functional components use ReactNode
props: jsx.props,
description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
home: 'https://github.com/cypress-io/cypress',
}
},
})
})
)
// Bluebird types are terrible. I don't think the return type can be carried without this cast
}) as unknown as globalThis.Cypress.Chainable<MountReturn>
Expand Down
2 changes: 1 addition & 1 deletion npm/svelte/src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function mount<T extends SvelteComponent> (
Cypress.log({
name: 'mount',
message: [mountMessage],
}).snapshot('mounted').end()
})
}
})
.wrap({ component: componentInstance as T }, { log: false })
Expand Down
26 changes: 9 additions & 17 deletions npm/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,21 +325,8 @@ export function mount<

// implementation
export function mount (componentOptions: any, options: any = {}) {
// TODO: get the real displayName and props from VTU shallowMount
const componentName = getComponentDisplayName(componentOptions)

const message = `<${componentName} ... />`
let logInstance: Cypress.Log

// then wait for cypress to load
// wait for cypress to load
return cy.then(() => {
if (options.log !== false) {
logInstance = Cypress.log({
name: 'mount',
message: [message],
})
}

// @ts-ignore
const document: Document = cy.state('document')

Expand Down Expand Up @@ -370,9 +357,14 @@ export function mount (componentOptions: any, options: any = {}) {
.wrap(wrapper, { log: false })
.wait(1, { log: false })
.then(() => {
if (logInstance) {
logInstance.snapshot('mounted')
logInstance.end()
if (options.log !== false) {
// TODO: get the real displayName and props from VTU shallowMount
const message = `<${getComponentDisplayName(componentOptions)} ... />`

Cypress.log({
name: 'mount',
message: [message],
})
}

// by returning undefined we keep the previous subject
Expand Down
17 changes: 10 additions & 7 deletions npm/vue2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,6 @@ export const mount = (
})
})
.then((win) => {
if (optionsOrProps.log !== false) {
Cypress.log({
name: 'mount',
message: [message],
}).snapshot('mounted').end()
}

const localVue = createLocalVue()

// @ts-ignore
Expand Down Expand Up @@ -411,6 +404,16 @@ export const mount = (
Cypress.vue = VTUWrapper.vm
Cypress.vueWrapper = VTUWrapper
})
.then(() => {
if (optionsOrProps.log !== false) {
return Vue.nextTick(() => {
Cypress.log({
name: 'mount',
message: [message],
})
})
}
})
}

/**
Expand Down
52 changes: 52 additions & 0 deletions packages/app/cypress/e2e/runner/reporter-ct-mount-hover.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { fixtureDirs } from '@tooling/system-tests'

type ProjectDirs = typeof fixtureDirs

const PROJECTS: {projectName: ProjectDirs[number], test: string}[] = [
{ projectName: 'angular-14', test: 'app.component' },
{ projectName: 'vueclivue2-configured', test: 'HelloWorld.cy' },
{ projectName: 'react-vite-ts-configured', test: 'App.cy' },
{ projectName: 'react18', test: 'App.cy' },
{ projectName: 'create-react-app-configured', test: 'App.cy' },
{ projectName: 'vueclivue3-configured', test: 'HelloWorld.cy' },
{ projectName: 'nuxtjs-vue2-configured', test: 'Tutorial.cy' },
]

// TODO: Add these tests to another cy-in-cy framework test to reduce CI cost as these scaffolding is expensive
for (const { projectName, test } of PROJECTS) {
describe(`CT Mount ${projectName}`, { viewportWidth: 1500, defaultCommandTimeout: 30000 }, () => {
beforeEach(() => {
cy.scaffoldProject(projectName)
cy.findBrowsers()
}),
it(`While hovering on Mount(), shows component on AUT for ${projectName}`, () => {
if (`${projectName}` === 'react18') {
cy.openProject(projectName, ['--config-file', 'cypress-vite.config.ts'])
cy.startAppServer('component')
cy.visitApp()
cy.contains(`${test}`).click()
cy.waitForSpecToFinish()
cy.get('.collapsible-header-inner:first').click().get('.command.command-name-mount > .command-wrapper').click().then(() => {
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)
})
})
} else {
cy.openProject(projectName)
cy.startAppServer('component')
cy.visitApp()
cy.contains(`${test}`).click()
cy.waitForSpecToFinish()
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)
})
}
})
}
})
})
}

5 comments on commit 355d210

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 355d210 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.12.0/linux-arm64/develop-355d2101d38ea4d1e93b9c571cf77babab2bbbfc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 355d210 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.12.0/linux-x64/develop-355d2101d38ea4d1e93b9c571cf77babab2bbbfc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 355d210 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.12.0/darwin-arm64/develop-355d2101d38ea4d1e93b9c571cf77babab2bbbfc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 355d210 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.12.0/darwin-x64/develop-355d2101d38ea4d1e93b9c571cf77babab2bbbfc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 355d210 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.12.0/win32-x64/develop-355d2101d38ea4d1e93b9c571cf77babab2bbbfc/cypress.tgz

Please sign in to comment.