Skip to content

Commit

Permalink
Merge branch 'develop' into retry-flake
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Dec 12, 2022
2 parents 285134b + 8888cd9 commit b84b45f
Show file tree
Hide file tree
Showing 16 changed files with 418 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .circleci/cache-version.txt
@@ -1,3 +1,3 @@
# Bump this version to force CI to re-create the cache from scratch.

12-05-22
12-12-22
56 changes: 43 additions & 13 deletions packages/driver/cypress/e2e/commands/sessions/sessions.cy.js
Expand Up @@ -256,7 +256,8 @@ describe('cy.session', { retries: 0 }, () => {
const sessionStorageData = consoleProps.groups[0].groups[0]

expect(sessionStorageData.name).to.contain('Session Storage - (1)')
expect(sessionStorageData.items).to.deep.eq({ cypressAuthToken: '{"body":{"username":"tester"}}' })
expect(sessionStorageData.items).to.have.property('cypressAuthToken')
expect(sessionStorageData.items.cypressAuthToken).to.contains('"username":"tester"')
})
})

Expand Down Expand Up @@ -839,29 +840,39 @@ describe('cy.session', { retries: 0 }, () => {
let clearPageCount = 0
let sessionGroupId
let setup
let slowSetup
let validate

const handleSetup = () => {
const handleSetup = (slowLogin = false) => {
// create session clears page before running
cy.contains('Default blank page').should('not.exist')

cy.visit('/fixtures/auth/index.html')
cy.contains('You are not logged in')
cy.window().then((win) => {
win.sessionStorage.setItem('cypressAuthToken', JSON.stringify({ body: { username: 'tester' } }))
})
cy.get('[data-cy=login-same-origin]').click()
cy.get('input').type('tester')
if (slowLogin) {
cy.get('[data-cy=slow-login]').click()
} else {
cy.get('[data-cy=login]').click()
}
}

const handleSlowSetup = () => handleSetup(true)

const handleValidate = () => {
// both create & restore session clears page after running
// both create & restore session clears page after running
cy.contains('Default blank page').should('not.exist')

cy.visit('/fixtures/auth/index.html')
cy.contains('Welcome tester')
cy.window()
.its('sessionStorage')
.its('cypressAuthToken', { timeout: 5000 })
.should('contain', '"username":"tester"')
}

before(() => {
setup = cy.stub().callsFake(handleSetup).as('setupSession')
slowSetup = cy.stub().callsFake(handleSlowSetup).as('setupSlowSession')
validate = cy.stub().callsFake(handleValidate).as('validateSession')
})

Expand All @@ -879,7 +890,7 @@ describe('cy.session', { retries: 0 }, () => {
resetMocks()
clearAllSavedSessions()
cy.on('log:added', (attrs, log) => {
if (attrs.name === 'session' || attrs.name === 'sessions_manager' || attrs.name === 'page load' || attrs.alias?.includes('setupSession') || attrs.alias?.includes('validateSession')) {
if (attrs.name === 'session' || attrs.name === 'sessions_manager' || attrs.alias?.includes('setupSession') || attrs.alias?.includes('setupSlowSession') || attrs.alias?.includes('validateSession')) {
logs.push(log)
if (!sessionGroupId) {
sessionGroupId = attrs.id
Expand Down Expand Up @@ -974,7 +985,8 @@ describe('cy.session', { retries: 0 }, () => {
const sessionStorageData = consoleProps.groups[0].groups[0]

expect(sessionStorageData.name).to.contain('Session Storage - (1)')
expect(sessionStorageData.items).to.deep.eq({ cypressAuthToken: '{"body":{"username":"tester"}}' })
expect(sessionStorageData.items).to.have.property('cypressAuthToken')
expect(sessionStorageData.items.cypressAuthToken).to.contains('"username":"tester"')
})
})

Expand All @@ -985,15 +997,15 @@ describe('cy.session', { retries: 0 }, () => {
setupTestContext()
cy.log('Creating new session with validation to test against')
sessionId = `session-${Cypress.state('test').id}`
cy.session(sessionId, setup, { validate })
cy.session(sessionId, slowSetup, { validate })
})

it('does not clear the page after command', () => {
cy.url().should('contain', '/fixtures/auth/index.html')
})

it('successfully creates new session and validates it', () => {
expect(setup).to.be.calledOnce
expect(slowSetup).to.be.calledOnce
expect(validate).to.be.calledOnce
expect(clearPageCount, 'total times session cleared the page').to.eq(0)
})
Expand Down Expand Up @@ -1024,7 +1036,7 @@ describe('cy.session', { retries: 0 }, () => {
})

expect(logs[3].get()).to.deep.contain({
alias: ['setupSession'],
alias: ['setupSlowSession'],
group: createNewSessionGroup.id,
})

Expand All @@ -1040,6 +1052,24 @@ describe('cy.session', { retries: 0 }, () => {
group: validateSessionGroup.id,
})
})

it('has session details in the consoleProps', () => {
const consoleProps = logs[0].get('consoleProps')()

expect(consoleProps.Command).to.eq('session')
expect(consoleProps.id).to.eq(sessionId)
expect(consoleProps.Domains).to.eq('This session captured data from localhost.')

expect(consoleProps.groups).to.have.length(1)
expect(consoleProps.groups[0].name).to.eq('localhost data:')
expect(consoleProps.groups[0].groups).to.have.length(1)

const sessionStorageData = consoleProps.groups[0].groups[0]

expect(sessionStorageData.name).to.contain('Session Storage - (1)')
expect(sessionStorageData.items).to.have.property('cypressAuthToken')
expect(sessionStorageData.items.cypressAuthToken).to.contains('"username":"tester"')
})
})

describe('create session with failed validation flow', () => {
Expand Down
18 changes: 14 additions & 4 deletions packages/driver/cypress/fixtures/auth/index.html
Expand Up @@ -13,7 +13,7 @@


if (newToken) {
sessionStorage.setItem('cypressAuthToken', decodeURIComponent(newToken));
sessionStorage.setItem('cypressAuthToken', decodeURIComponent(newToken))
urlParams.delete('token')
const newSearchParams = urlParams.toString()

Expand Down Expand Up @@ -43,13 +43,23 @@

// Add Login button that redirects to the idp
const loginBtn = document.createElement("button");
loginBtn.innerHTML = "Login IDP"
loginBtn.dataset.cy = "login-idp"
loginBtn.innerHTML = "Login Same Origin"
loginBtn.dataset.cy = "login-same-origin"
loginBtn.onclick = function () {
window.location.href = `http://www.idp.com:3500/fixtures/auth/idp.html?redirect=${encodeURIComponent(window.location.href)}`
window.location.href = `http://localhost:3500/fixtures/auth/idp.html?redirect=${encodeURIComponent(window.location.href)}`
};
document.body.appendChild(loginBtn);


// Add Login button that redirects to the idp
const loginIDPBtn = document.createElement("button");
loginIDPBtn.innerHTML = "Login IDP"
loginIDPBtn.dataset.cy = "login-idp"
loginIDPBtn.onclick = function () {
window.location.href = `http://www.idp.com:3500/fixtures/auth/idp.html?redirect=${encodeURIComponent(window.location.href)}`
};
document.body.appendChild(loginIDPBtn);

// Add Login button that redirects to the idp
const loginFoobarBtn = document.createElement("button");
loginFoobarBtn.innerHTML = "Login Foobar"
Expand Down
16 changes: 16 additions & 0 deletions packages/driver/src/cy/commands/sessions/index.ts
Expand Up @@ -185,6 +185,8 @@ export default function (Commands, Cypress, cy) {
consoleProps: () => {
return {
Step: statusMap.stepName(step),
Message: 'The following is the collected session data after the session was successfully setup:',

...getConsoleProps(existingSession),
}
},
Expand Down Expand Up @@ -396,6 +398,20 @@ export default function (Commands, Cypress, cy) {
}
}

// collect all session data again that may have been updated during the validation check
const data = await sessions.getCurrentSessionData()

_.extend(existingSession, data)
validateLog.set({
consoleProps: () => {
return {
Step: 'Validate Session',
Message: 'The following is the collected session data after the session was successfully validated:',
...getConsoleProps(existingSession),
}
},
})

return isValidSession
})

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 32 additions & 2 deletions packages/errors/src/errors.ts
Expand Up @@ -279,7 +279,37 @@ export const AllCypressErrors = {
https://on.cypress.io/parallel-disallowed`
},
CLOUD_PARALLEL_GROUP_PARAMS_MISMATCH: (arg1: {runUrl: string, parameters: any}) => {
CLOUD_PARALLEL_GROUP_PARAMS_MISMATCH: (arg1: {runUrl: string, parameters: any, payload: any }) => {
let params: any = arg1.parameters

if (arg1.payload?.differentParams) {
params = {}

_.map(arg1.parameters, (value, key) => {
if (key === 'specs' && arg1.payload.differentSpecs?.length) {
const addedSpecs: string[] = []
const missingSpecs: string[] = []

_.forEach(arg1.payload.differentSpecs, (s) => {
if (value.includes(s)) {
addedSpecs.push(s)
} else {
missingSpecs.push(s)
}
})

params['differentSpecs'] = {
added: addedSpecs,
missing: missingSpecs,
}
} else if (arg1.payload.differentParams[key]?.expected) {
params[key] = `${value}.... (Expected: ${(arg1.payload.differentParams[key].expected)})`
} else {
params[key] = value
}
})
}

return errTemplate`\
You passed the ${fmt.flag(`--parallel`)} flag, but we do not parallelize tests across different environments.
Expand All @@ -299,7 +329,7 @@ export const AllCypressErrors = {
This machine sent the following parameters:
${fmt.meta(arg1.parameters)}
${fmt.meta(params)}
https://on.cypress.io/parallel-group-params-mismatch`
},
Expand Down
34 changes: 34 additions & 0 deletions packages/errors/test/unit/visualSnapshotErrors_spec.ts
Expand Up @@ -487,6 +487,40 @@ describe('visual error templates', () => {
'cypress/integration/app_spec.js',
],
},
payload: {},
},
],
differentParams: [
{
group: 'foo',
runUrl: 'https://cloud.cypress.io/project/abcd/runs/1',
ciBuildId: 'test-ciBuildId-123',
parameters: {
osName: 'darwin',
osVersion: 'v1',
browserName: 'Electron',
browserVersion: '59.1.2.3',
specs: [
'cypress/integration/app_spec.js',
'cypress/integration/foo_spec.js',
'cypress/integration/bar_spec.js',
],
},
payload: {
differentParams: {
browserName: {
detected: 'Chrome',
expected: 'Electron',
},
browserVersion: {
detected: '65',
expected: '64',
},
},
differentSpecs: [
'cypress/integration/foo_spec.js',
],
},
},
],
}
Expand Down
13 changes: 8 additions & 5 deletions packages/server/__snapshots__/cypress_spec.js
Expand Up @@ -203,11 +203,14 @@ This machine sent the following parameters:
{
"osName": "darwin",
"osVersion": "v1",
"browserName": "Electron",
"browserVersion": "59.1.2.3",
"specs": [
"cypress/e2e/app.cy.js"
]
"browserName": "Electron.... (Expected: Electron)",
"browserVersion": "59.1.2.3.... (Expected: 64)",
"differentSpecs": {
"added": [],
"missing": [
"cypress/integration/foo_spec.js"
]
}
}
https://on.cypress.io/parallel-group-params-mismatch
Expand Down
1 change: 1 addition & 0 deletions packages/server/lib/modes/record.js
Expand Up @@ -466,6 +466,7 @@ const createRun = Promise.method((options = {}) => {
browserVersion,
specs,
},
payload,
})
}
case 'PARALLEL_DISALLOWED':
Expand Down

5 comments on commit b84b45f

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b84b45f Dec 12, 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/12.1.0/linux-arm64/retry-flake-b84b45f1f494e07e14cd8a240129c31ea5ff050e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b84b45f Dec 12, 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/12.1.0/linux-x64/retry-flake-b84b45f1f494e07e14cd8a240129c31ea5ff050e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b84b45f Dec 12, 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/12.1.0/darwin-x64/retry-flake-b84b45f1f494e07e14cd8a240129c31ea5ff050e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b84b45f Dec 12, 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/12.1.0/win32-x64/retry-flake-b84b45f1f494e07e14cd8a240129c31ea5ff050e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on b84b45f Dec 12, 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/12.1.0/darwin-arm64/retry-flake-b84b45f1f494e07e14cd8a240129c31ea5ff050e/cypress.tgz

Please sign in to comment.