Skip to content

Commit 355d210

Browse files
amehta265marktnoonanlmiller1990ZachJW34
authored
fix: Hovering over mount in command log does not show component in AUT (#24346)
Co-authored-by: Mark Noonan <mark@cypress.io> Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com> Co-authored-by: Zachary Williams <zachjw34@gmail.com>
1 parent 239d2e3 commit 355d210

File tree

5 files changed

+89
-43
lines changed

5 files changed

+89
-43
lines changed

npm/react/src/createMount.ts

+17-18
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,6 @@ export const makeMountFn = (
9090

9191
internalMountOptions.render(reactComponent, el, reactDomToUse)
9292

93-
if (options.log !== false) {
94-
Cypress.log({
95-
name: type,
96-
type: 'parent',
97-
message: [message],
98-
// @ts-ignore
99-
$el: (el.children.item(0) as unknown) as JQuery<HTMLElement>,
100-
consoleProps: () => {
101-
return {
102-
// @ts-ignore protect the use of jsx functional components use ReactNode
103-
props: jsx.props,
104-
description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
105-
home: 'https://github.com/cypress-io/cypress',
106-
}
107-
},
108-
}).snapshot('mounted').end()
109-
}
110-
11193
return (
11294
// Separate alias and returned value. Alias returns the component only, and the thenable returns the additional functions
11395
cy.wrap<React.ReactNode>(userComponent, { log: false })
@@ -123,6 +105,23 @@ export const makeMountFn = (
123105
// and letting hooks and component lifecycle methods to execute mount
124106
// https://github.com/bahmutov/cypress-react-unit-test/issues/200
125107
.wait(0, { log: false })
108+
.then(() => {
109+
Cypress.log({
110+
name: type,
111+
type: 'parent',
112+
message: [message],
113+
// @ts-ignore
114+
$el: (el.children.item(0) as unknown) as JQuery<HTMLElement>,
115+
consoleProps: () => {
116+
return {
117+
// @ts-ignore protect the use of jsx functional components use ReactNode
118+
props: jsx.props,
119+
description: type === 'mount' ? 'Mounts React component' : 'Rerenders mounted React component',
120+
home: 'https://github.com/cypress-io/cypress',
121+
}
122+
},
123+
})
124+
})
126125
)
127126
// Bluebird types are terrible. I don't think the return type can be carried without this cast
128127
}) as unknown as globalThis.Cypress.Chainable<MountReturn>

npm/svelte/src/mount.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function mount<T extends SvelteComponent> (
8282
Cypress.log({
8383
name: 'mount',
8484
message: [mountMessage],
85-
}).snapshot('mounted').end()
85+
})
8686
}
8787
})
8888
.wrap({ component: componentInstance as T }, { log: false })

npm/vue/src/index.ts

+9-17
Original file line numberDiff line numberDiff line change
@@ -325,21 +325,8 @@ export function mount<
325325

326326
// implementation
327327
export function mount (componentOptions: any, options: any = {}) {
328-
// TODO: get the real displayName and props from VTU shallowMount
329-
const componentName = getComponentDisplayName(componentOptions)
330-
331-
const message = `<${componentName} ... />`
332-
let logInstance: Cypress.Log
333-
334-
// then wait for cypress to load
328+
// wait for cypress to load
335329
return cy.then(() => {
336-
if (options.log !== false) {
337-
logInstance = Cypress.log({
338-
name: 'mount',
339-
message: [message],
340-
})
341-
}
342-
343330
// @ts-ignore
344331
const document: Document = cy.state('document')
345332

@@ -370,9 +357,14 @@ export function mount (componentOptions: any, options: any = {}) {
370357
.wrap(wrapper, { log: false })
371358
.wait(1, { log: false })
372359
.then(() => {
373-
if (logInstance) {
374-
logInstance.snapshot('mounted')
375-
logInstance.end()
360+
if (options.log !== false) {
361+
// TODO: get the real displayName and props from VTU shallowMount
362+
const message = `<${getComponentDisplayName(componentOptions)} ... />`
363+
364+
Cypress.log({
365+
name: 'mount',
366+
message: [message],
367+
})
376368
}
377369

378370
// by returning undefined we keep the previous subject

npm/vue2/src/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,6 @@ export const mount = (
362362
})
363363
})
364364
.then((win) => {
365-
if (optionsOrProps.log !== false) {
366-
Cypress.log({
367-
name: 'mount',
368-
message: [message],
369-
}).snapshot('mounted').end()
370-
}
371-
372365
const localVue = createLocalVue()
373366

374367
// @ts-ignore
@@ -411,6 +404,16 @@ export const mount = (
411404
Cypress.vue = VTUWrapper.vm
412405
Cypress.vueWrapper = VTUWrapper
413406
})
407+
.then(() => {
408+
if (optionsOrProps.log !== false) {
409+
return Vue.nextTick(() => {
410+
Cypress.log({
411+
name: 'mount',
412+
message: [message],
413+
})
414+
})
415+
}
416+
})
414417
}
415418

416419
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { fixtureDirs } from '@tooling/system-tests'
2+
3+
type ProjectDirs = typeof fixtureDirs
4+
5+
const PROJECTS: {projectName: ProjectDirs[number], test: string}[] = [
6+
{ projectName: 'angular-14', test: 'app.component' },
7+
{ projectName: 'vueclivue2-configured', test: 'HelloWorld.cy' },
8+
{ projectName: 'react-vite-ts-configured', test: 'App.cy' },
9+
{ projectName: 'react18', test: 'App.cy' },
10+
{ projectName: 'create-react-app-configured', test: 'App.cy' },
11+
{ projectName: 'vueclivue3-configured', test: 'HelloWorld.cy' },
12+
{ projectName: 'nuxtjs-vue2-configured', test: 'Tutorial.cy' },
13+
]
14+
15+
// TODO: Add these tests to another cy-in-cy framework test to reduce CI cost as these scaffolding is expensive
16+
for (const { projectName, test } of PROJECTS) {
17+
describe(`CT Mount ${projectName}`, { viewportWidth: 1500, defaultCommandTimeout: 30000 }, () => {
18+
beforeEach(() => {
19+
cy.scaffoldProject(projectName)
20+
cy.findBrowsers()
21+
}),
22+
it(`While hovering on Mount(), shows component on AUT for ${projectName}`, () => {
23+
if (`${projectName}` === 'react18') {
24+
cy.openProject(projectName, ['--config-file', 'cypress-vite.config.ts'])
25+
cy.startAppServer('component')
26+
cy.visitApp()
27+
cy.contains(`${test}`).click()
28+
cy.waitForSpecToFinish()
29+
cy.get('.collapsible-header-inner:first').click().get('.command.command-name-mount > .command-wrapper').click().then(() => {
30+
cy.get('iframe.aut-iframe').its('0.contentDocument.body').then(cy.wrap).within(() => {
31+
cy.get('[data-cy-root]').children().should('have.length.at.least', 1)
32+
})
33+
})
34+
} else {
35+
cy.openProject(projectName)
36+
cy.startAppServer('component')
37+
cy.visitApp()
38+
cy.contains(`${test}`).click()
39+
cy.waitForSpecToFinish()
40+
cy.get('.command.command-name-mount > .command-wrapper').click().then(() => {
41+
if (`${projectName}` === 'angular-14') {
42+
cy.get('iframe.aut-iframe').its('0.contentDocument.body').children().should('have.length.at.least', 2)
43+
} else {
44+
cy.get('iframe.aut-iframe').its('0.contentDocument.body').then(cy.wrap).within(() => {
45+
cy.get('[data-cy-root]').children().should('have.length.at.least', 1)
46+
})
47+
}
48+
})
49+
}
50+
})
51+
})
52+
}

0 commit comments

Comments
 (0)