Skip to content

Commit

Permalink
chore: capture log:false logs when protocol is enabled (#28531)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyrohrbough committed Dec 28, 2023
1 parent f80027f commit 8ba64c4
Show file tree
Hide file tree
Showing 79 changed files with 3,636 additions and 1,326 deletions.
4 changes: 2 additions & 2 deletions .circleci/workflows.yml
Expand Up @@ -31,7 +31,7 @@ mainBuildFilters: &mainBuildFilters
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- 'feature/experimental-retries'
- 'publish-binary'
- 'em/shallow-checkout'
- 'em/protocol-log-false'

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand Down Expand Up @@ -155,7 +155,7 @@ commands:
name: Set environment variable to determine whether or not to persist artifacts
command: |
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "publish-binary" && "$CIRCLE_BRANCH" != "lerna-optimize-tasks" ]]; then
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "publish-binary" && "$CIRCLE_BRANCH" != "em/protocol-log-false" ]]; then
export SHOULD_PERSIST_ARTIFACTS=true
fi' >> "$BASH_ENV"
# You must run `setup_should_persist_artifacts` command and be using bash before running this command
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/runner/event-manager.ts
Expand Up @@ -617,6 +617,7 @@ export class EventManager {
})

Cypress.on('test:before:run:async', async (...args) => {
crossOriginLogs = {}
const [attributes, test] = args

this.reporterBus.emit('test:before:run:async', attributes)
Expand Down Expand Up @@ -860,7 +861,6 @@ export class EventManager {
Cypress.primaryOriginCommunicator.removeAllListeners()
// clean up the cross origin logs in memory to prevent dangling references as the log objects themselves at this point will no longer be needed.
crossOriginLogs = {}

this.studioStore.setInactive()
}

Expand Down
7 changes: 6 additions & 1 deletion packages/app/src/runner/events/capture-protocol.ts
@@ -1,4 +1,9 @@
const attachCypressProtocolInfo = (info) => {
type ProtocolInfo = {
type: 'cy:protocol-snapshot' | 'log:added' | 'log:changed' | 'page:loading'| 'test:before:run:async' | 'test:before:after:run:async' | 'test:after:run:async' | 'url:changed' | 'viewport:changed'
timestamp: DOMHighResTimeStamp
}

const attachCypressProtocolInfo = (info: ProtocolInfo) => {
let cypressProtocolElement: HTMLElement | null = document.getElementById('__cypress-protocol')

// If element does not exist, create it
Expand Down
97 changes: 95 additions & 2 deletions packages/driver/cypress/e2e/commands/actions/check.cy.js
Expand Up @@ -616,8 +616,39 @@ describe('src/cy/commands/actions/check', () => {
cy.on('log:added', (attrs, log) => {
this.lastLog = log
})
})

return null
it('can turn off logging when protocol is disabled', { protocolEnabled: false }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get(':checkbox:first').check({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name')).to.eq('get')
expect(hiddenLog).to.be.undefined
})
})

it('can send hidden log when protocol is enabled', { protocolEnabled: true }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get(':checkbox:first').check({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name')).to.eq('get')

expect(hiddenLog.get('name'), 'log name').to.eq('check')
expect(hiddenLog.get('hidden'), 'log hidden').to.be.true
expect(hiddenLog.get('snapshots').length, 'log snapshot length').to.eq(2)
})
})

it('logs immediately before resolving', (done) => {
Expand Down Expand Up @@ -766,6 +797,22 @@ describe('src/cy/commands/actions/check', () => {
expect(consoleProps.props.Coords).to.deep.eq(
_.pick(fromElWindow, 'x', 'y'),
)

expect(consoleProps).to.have.property('table')
expect(consoleProps.table[1]()).to.containSubset({
'name': 'Mouse Events',
'data': [
{ 'Event Type': 'pointerover' },
{ 'Event Type': 'mouseover' },
{ 'Event Type': 'pointermove' },
{ 'Event Type': 'pointerdown' },
{ 'Event Type': 'mousedown' },
{ 'Event Type': 'pointerover' },
{ 'Event Type': 'pointerup' },
{ 'Event Type': 'mouseup' },
{ 'Event Type': 'click' },
],
})
})
})

Expand Down Expand Up @@ -1209,8 +1256,38 @@ describe('src/cy/commands/actions/check', () => {
cy.on('log:added', (attrs, log) => {
this.lastLog = log
})
})

return null
it('can turn off logging when protocol is disabled', { protocolEnabled: false }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get(':checkbox:first').check().uncheck({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name'), 'log name').to.not.eq('uncheck')
expect(hiddenLog).to.be.undefined
})
})

it('can send hidden log when protocol is enabled', { protocolEnabled: true }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get(':checkbox:first').check().uncheck({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name'), 'log name').to.not.eq('uncheck')
expect(hiddenLog.get('name'), 'log name').to.eq('uncheck')
expect(hiddenLog.get('hidden'), 'log hidden').to.be.true
expect(hiddenLog.get('snapshots').length, 'log snapshot length').to.eq(2)
})
})

it('logs immediately before resolving', (done) => {
Expand Down Expand Up @@ -1315,6 +1392,22 @@ describe('src/cy/commands/actions/check', () => {
expect(consoleProps.props.Coords).to.deep.eq(
_.pick(fromElWindow, 'x', 'y'),
)

expect(consoleProps).to.have.property('table')
expect(consoleProps.table[1]()).to.containSubset({
'name': 'Mouse Events',
'data': [
{ 'Event Type': 'pointerover' },
{ 'Event Type': 'mouseover' },
{ 'Event Type': 'pointermove' },
{ 'Event Type': 'pointerdown' },
{ 'Event Type': 'mousedown' },
{ 'Event Type': 'pointerover' },
{ 'Event Type': 'pointerup' },
{ 'Event Type': 'mouseup' },
{ 'Event Type': 'click' },
],
})
})
})

Expand Down
63 changes: 62 additions & 1 deletion packages/driver/cypress/e2e/commands/actions/clear.cy.js
Expand Up @@ -477,8 +477,38 @@ describe('src/cy/commands/actions/type - #clear', () => {
cy.on('log:added', (attrs, log) => {
this.lastLog = log
})
})

it('can turn off logging when protocol is disabled', { protocolEnabled: false }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

null
cy.get('input:first').clear({ log: false })
.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name')).to.eq('get')
expect(hiddenLog).to.be.undefined
})
})

it('can send hidden log when protocol is enabled', { protocolEnabled: true }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get('input:first').clear({ log: false })
.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name')).to.eq('get')

expect(hiddenLog).to.be.ok
expect(hiddenLog.get('name'), 'log name').to.eq('clear')
expect(hiddenLog.get('hidden'), 'log hidden').to.be.true
expect(hiddenLog.get('snapshots').length, 'log snapshot length').to.eq(1)
})
})

it('logs immediately before resolving', () => {
Expand Down Expand Up @@ -537,5 +567,36 @@ describe('src/cy/commands/actions/type - #clear', () => {
expect(lastLog.invoke('consoleProps').props.Options).to.deep.eq({ force: true, timeout: 1000 })
})
})

it('logs console props', () => {
cy.get('input:first')
.clear().then(function () {
const { lastLog } = this
const consoleProps = lastLog.invoke('consoleProps')

expect(consoleProps).to.be.ok
expect(consoleProps).to.have.property('name', 'clear')
expect(consoleProps).to.have.property('type', 'command')
expect(consoleProps).to.have.property('props')
expect(consoleProps.props).to.have.property('Applied To')
expect(consoleProps.props).to.have.property('Elements', 1)
expect(consoleProps.props).to.have.property('Coords')
expect(consoleProps).to.have.property('table')
expect(consoleProps.table[1]()).to.containSubset({
'name': 'Mouse Events',
'data': [
{ 'Event Type': 'pointerover' },
{ 'Event Type': 'mouseover' },
{ 'Event Type': 'pointermove' },
{ 'Event Type': 'pointerdown' },
{ 'Event Type': 'mousedown' },
{ 'Event Type': 'pointerover' },
{ 'Event Type': 'pointerup' },
{ 'Event Type': 'mouseup' },
{ 'Event Type': 'click' },
],
})
})
})
})
})
97 changes: 95 additions & 2 deletions packages/driver/cypress/e2e/commands/actions/click.cy.js
Expand Up @@ -2431,6 +2431,39 @@ describe('src/cy/commands/actions/click', () => {
})
})

it('can turn off logging when protocol is disabled', { protocolEnabled: false }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get('button:first').click({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name'), 'log name').to.not.eq('click')
expect(hiddenLog).to.be.undefined
})
})

it('can send hidden log when protocol is enabled', { protocolEnabled: true }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get('button:first').click({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name'), 'log name').to.not.eq('click')

expect(hiddenLog.get('name'), 'log name').to.eq('click')
expect(hiddenLog.get('hidden'), 'log hidden').to.be.true
expect(hiddenLog.get('snapshots').length, 'log snapshot length').to.eq(2)
})
})

it('logs immediately before resolving', (done) => {
const button = cy.$$('button:first')

Expand Down Expand Up @@ -3305,8 +3338,38 @@ describe('src/cy/commands/actions/click', () => {

this.logs.push(log)
})
})

null
it('can turn off logging when protocol is disabled', { protocolEnabled: false }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get('button:first').dblclick({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name'), 'log name').to.not.eq('dblclick')
expect(hiddenLog).to.be.undefined
})
})

it('can send hidden log when protocol is enabled', { protocolEnabled: true }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get('button:first').dblclick({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name'), 'log name').to.not.eq('dblclick')
expect(hiddenLog.get('name'), 'log name').to.eq('dblclick')
expect(hiddenLog.get('hidden'), 'log hidden').to.be.true
expect(hiddenLog.get('snapshots').length, 'log snapshot length').to.eq(2)
})
})

it('logs immediately before resolving', (done) => {
Expand Down Expand Up @@ -3711,8 +3774,38 @@ describe('src/cy/commands/actions/click', () => {

this.logs.push(log)
})
})

null
it('can turn off logging when protocol is disabled', { protocolEnabled: false }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get('button:first').rightclick({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name'), 'log name').to.not.eq('rightclick')
expect(hiddenLog).to.be.undefined
})
})

it('can send hidden log when protocol is enabled', { protocolEnabled: true }, function () {
cy.on('_log:added', (attrs, log) => {
this.hiddenLog = log
})

cy.get('button:first').rightclick({ log: false })

cy.then(function () {
const { lastLog, hiddenLog } = this

expect(lastLog.get('name'), 'log name').to.not.eq('rightclick')
expect(hiddenLog.get('name'), 'log name').to.eq('rightclick')
expect(hiddenLog.get('hidden'), 'log hidden').to.be.true
expect(hiddenLog.get('snapshots').length, 'log snapshot length').to.eq(2)
})
})

it('logs immediately before resolving', (done) => {
Expand Down

5 comments on commit 8ba64c4

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8ba64c4 Dec 28, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/linux-x64/develop-8ba64c4798ad59e0895495958afe4ae8e0fc2535/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8ba64c4 Dec 28, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/linux-arm64/develop-8ba64c4798ad59e0895495958afe4ae8e0fc2535/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8ba64c4 Dec 28, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/darwin-x64/develop-8ba64c4798ad59e0895495958afe4ae8e0fc2535/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8ba64c4 Dec 28, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/win32-x64/develop-8ba64c4798ad59e0895495958afe4ae8e0fc2535/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8ba64c4 Dec 28, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/darwin-arm64/develop-8ba64c4798ad59e0895495958afe4ae8e0fc2535/cypress.tgz

Please sign in to comment.