Skip to content

Commit

Permalink
fix: add safety check for command.clone when cmd does not have args (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyrohrbough committed Apr 8, 2022
1 parent b031803 commit d5c033f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
76 changes: 76 additions & 0 deletions packages/driver/cypress/integration/cypress/command_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const { Command } = Cypress

describe('driver/src/cypress/command', () => {
let command

context('$Command', () => {
context('._removeNonPrimitives', () => {
before(() => {
command = Command.create({ })
})

it('when args are undefined it does not remove non properties', () => {
const args = undefined

command._removeNonPrimitives(args)
expect(args).to.be.undefined
})

it('when args is an object it filters out non-primitive properties ', () => {
const args = ['.fake_get_selector', {
opt1: 'option',
opt2: {
nested: 'hello',
},
}]

command._removeNonPrimitives(args)
expect(args).to.be.eq(args)
})

it('sets log to true if previously options set it to false', () => {
const args = [{ log: false }]

command._removeNonPrimitives(args)
expect(args).to.have.length(1)
expect(args[0]).to.have.property('log')
expect(args[0].log).to.be.true
})
})

context('.clone', () => {
it('successfully clones command with arguments', () => {
const args = ['.selector']

command = Command.create({
type: 'parent',
name: 'command1',
chainerId: 'id1',
args,
})

const spy = cy.spy(command, '_removeNonPrimitives')
let clonedCommand = command.clone()

expect(clonedCommand).to.be.instanceOf(Command)
expect(spy).to.have.been.calledWith(args)
expect(clonedCommand.attributes).to.deep.eq(command.attributes)
})

it('successfully clones command with without arguments', () => {
command = Command.create({
type: 'parent',
name: 'command1',
chainerId: 'id1',
})

const spy = cy.spy(command, '_removeNonPrimitives')
let clonedCommand = command.clone()

expect(clonedCommand).to.be.instanceOf(Command)
expect(spy).to.have.been.calledWith(undefined)
expect(clonedCommand.attributes).to.deep.eq(command.attributes)
})
})
})
})
2 changes: 1 addition & 1 deletion packages/driver/src/cypress/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class $Command {
return this.attributes
}

_removeNonPrimitives (args) {
_removeNonPrimitives (args: Array<any> = []) {
// if the obj has options and
// log is false, set it to true
for (let i = args.length - 1; i >= 0; i--) {
Expand Down

3 comments on commit d5c033f

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d5c033f Apr 8, 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/9.5.4/linux-x64/develop-d5c033fba8572fbd8dcbc656221ab224255001fe/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d5c033f Apr 8, 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/9.5.4/darwin-x64/develop-d5c033fba8572fbd8dcbc656221ab224255001fe/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d5c033f Apr 8, 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/9.5.4/win32-x64/develop-d5c033fba8572fbd8dcbc656221ab224255001fe/cypress.tgz

Please sign in to comment.