Skip to content

Commit

Permalink
Merge branch 'develop' into mikep/23064-spec-name-display
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyrohrbough authored Aug 16, 2022
2 parents 5abc89f + 937d4e7 commit ea2af61
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 83 deletions.
4 changes: 4 additions & 0 deletions cli/__snapshots__/download_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ exports['desktop url from template'] = `
https://download.cypress.io/desktop/0.20.2/OS-ARCH/cypress.zip
`

exports['desktop url from template with version'] = `
https://mycompany/0.20.2/OS-ARCH/cypress.zip
`

exports['desktop url from template with escaped dollar sign'] = `
https://download.cypress.io/desktop/0.20.2/OS-ARCH/cypress.zip
`
Expand Down
7 changes: 5 additions & 2 deletions cli/lib/tasks/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const getCA = () => {
})
}

const prepend = (arch, urlPath) => {
const prepend = (arch, urlPath, version) => {
const endpoint = url.resolve(getBaseUrl(), urlPath)
const platform = os.platform()
const pathTemplate = util.getEnv('CYPRESS_DOWNLOAD_PATH_TEMPLATE', true)
Expand All @@ -71,6 +71,7 @@ const prepend = (arch, urlPath) => {
.replace(/\\?\$\{endpoint\}/, endpoint)
.replace(/\\?\$\{platform\}/, platform)
.replace(/\\?\$\{arch\}/, arch)
.replace(/\\?\$\{version\}/, version)
)
: `${endpoint}?platform=${platform}&arch=${arch}`
}
Expand All @@ -82,7 +83,9 @@ const getUrl = (arch, version) => {
return version
}

return version ? prepend(arch, `desktop/${version}`) : prepend(arch, 'desktop')
const urlPath = version ? `desktop/${version}` : 'desktop'

return prepend(arch, urlPath, version)
}

const statusMessage = (err) => {
Expand Down
7 changes: 7 additions & 0 deletions cli/test/lib/tasks/download_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ describe('lib/tasks/download', function () {
snapshot('desktop url from template', normalize(url))
})

it('returns custom url from template with version', () => {
process.env.CYPRESS_DOWNLOAD_PATH_TEMPLATE = 'https://mycompany/${version}/${platform}-${arch}/cypress.zip'
const url = download.getUrl('ARCH', '0.20.2')

snapshot('desktop url from template with version', normalize(url))
})

it('returns custom url from template with escaped dollar sign', () => {
process.env.CYPRESS_DOWNLOAD_PATH_TEMPLATE = '\\${endpoint}/\\${platform}-\\${arch}/cypress.zip'
const url = download.getUrl('ARCH', '0.20.2')
Expand Down
81 changes: 49 additions & 32 deletions packages/app/cypress/e2e/runner/sessions.ui.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,51 +131,68 @@ describe('runner/cypress sessions.ui.spec', {
cy.percySnapshot()
})

it('restores saved session', () => {
loadSpec({
projectName: 'session-and-origin-e2e-specs',
filePath: 'session/restores_saved_session.cy.js',
passCount: 2,
describe('restores saved session', () => {
beforeEach(() => {
loadSpec({
projectName: 'session-and-origin-e2e-specs',
filePath: 'session/restores_saved_session.cy.js',
passCount: 5,
failCount: 1,
})
})

cy.get('.test').each(($el) => cy.wrap($el).click())
it('restores session as expected', () => {
cy.get('.test').each(($el) => cy.wrap($el).click())

cy.log('validate new session was created in first test')
cy.get('.test').eq(0).within(() => {
validateSessionsInstrumentPanel(['user1'])
cy.get('.command-name-session').contains('created')
})
cy.log('validate new session was created in first test')
cy.get('.test').eq(0).within(() => {
validateSessionsInstrumentPanel(['user1'])
cy.get('.command-name-session').contains('created')
})

cy.log('validate saved session was used in second test')
cy.get('.test').eq(1).within(() => {
validateSessionsInstrumentPanel(['user1'])
cy.log('validate saved session was used in second test')
cy.get('.test').eq(1).within(() => {
validateSessionsInstrumentPanel(['user1'])

cy.get('.command-name-session')
.within(() => {
cy.get('.command-expander').first().click()
cy.contains('user1')
cy.contains('restored')
cy.get('.command-name-session')
.within(() => {
cy.get('.command-expander').first().click()
cy.contains('user1')
cy.contains('restored')

cy.get('.command-name-Clear-page').should('have.length', 2)
cy.get('.command-name-Clear-page').should('have.length', 2)

cy.contains('Restore saved session')
cy.contains('Restore saved session')

cy.contains('Validate session')
.closest('.command').as('validateSession')
cy.contains('Validate session')
.closest('.command').as('validateSession')

cy.get('@validateSession')
.find('.command-expander')
.should('not.have.class', 'command-expander-is-open')
.click()
cy.get('@validateSession')
.find('.command-expander')
.should('not.have.class', 'command-expander-is-open')
.click()

cy.get('@validateSession')
.find('.command-alias')
.contains('runValidation')
cy.get('@validateSession')
.find('.command-alias')
.contains('runValidation')
})

cy.get('.command-name-session').get('.command-expander').first().click()

cy.get('.command').should('have.length', 2)
})
})

cy.get('.command-name-session').get('.command-expander').first().click()
// https://github.com/cypress-io/cypress/issues/22381
it('ensures sessionid integrity is maintained across tests', () => {
cy.contains('test sessionid integrity is maintained').closest('.runnable').should('have.class', 'runnable-failed')
cy.get('.test').should('have.length', 6)

cy.get('.command').should('have.length', 2)
cy.get('.test').eq(2).should('have.class', 'runnable-passed')
cy.get('.test').eq(3).should('have.class', 'runnable-passed')
cy.get('.test').eq(4).should('have.class', 'runnable-passed')
cy.get('.test').eq(5).should('have.class', 'runnable-failed')
cy.contains('If you want to specify different options, please use a unique name').should('exist')
})
})

Expand Down
6 changes: 5 additions & 1 deletion packages/data-context/src/sources/FileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export class FileDataSource {
// The working directory path may include characters that conflict with glob
// syntax (brackets, parentheses, etc.) and cause our searches to inadvertently fail.
// We scope our search to the working directory using the `cwd` globby option.
return globPattern.replace(cwd, '.')
if (globPattern.startsWith(cwd)) {
return globPattern.replace(cwd, '.')
}

return globPattern
})

const ignoreGlob = (globOptions?.ignore ?? []).concat('**/node_modules/**')
Expand Down
18 changes: 18 additions & 0 deletions packages/data-context/test/unit/sources/FileDataSource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ describe('FileDataSource', () => {
expect(files).to.have.length(2)
})

it('does not replace working directory in glob pattern if it is not leading', async () => {
// Create a redundant structure within the project dir matching its absolute path
// and write a new script in that location
const nestedScriptPath = path.join(projectPath, 'cypress', projectPath)

await fs.mkdirs(nestedScriptPath)
await fs.writeFile(path.join(nestedScriptPath, 'nested-script.js'), '')

// Verify that the glob pattern is not impacted if if contains directories equivalent
// to the working directory
let files = await fileDataSource.getFilesByGlob(
projectPath,
`./cypress${projectPath}/nested-script.js`,
)

expect(files).to.have.length(1)
})

it('finds files matching multiple patterns', async () => {
const files = await fileDataSource.getFilesByGlob(
projectPath,
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/cypress/e2e/commands/sessions/manager.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('src/cy/commands/sessions/manager.ts', () => {

expect(sessionsManager).to.haveOwnProperty('cy')
expect(sessionsManager).to.haveOwnProperty('Cypress')
expect(sessionsManager).to.haveOwnProperty('currentTestRegisteredSessions')
expect(sessionsManager.currentTestRegisteredSessions).to.be.instanceOf(Map)
expect(sessionsManager).to.haveOwnProperty('registeredSessions')
expect(sessionsManager.registeredSessions).to.be.instanceOf(Map)
})

describe('.setActiveSession()', () => {
Expand Down
23 changes: 12 additions & 11 deletions packages/driver/cypress/e2e/commands/sessions/sessions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('cy.session', { retries: 0 }, () => {

it('accepts array as id', () => {
cy.session('session-id', () => {})
cy.session('session-id')
})

it('accepts object as id', () => {
Expand All @@ -35,7 +36,7 @@ describe('cy.session', { retries: 0 }, () => {
const setup = cy.stub().as('setupSession')
const validate = cy.stub().as('validateSession')

cy.session('session-id', setup, { validate })
cy.session('session-id-3rd-arg', setup, { validate })
cy.then(() => {
expect(setup).to.be.calledOnce
expect(validate).to.be.calledOnce
Expand Down Expand Up @@ -236,7 +237,7 @@ describe('cy.session', { retries: 0 }, () => {
setupTestContext()
cy.log('Creating new session with validation to test against')

cy.session('session-1', setup, { validate })
cy.session(`session-${Cypress.state('test').id}`, setup, { validate })
cy.url().should('eq', 'about:blank')
})

Expand Down Expand Up @@ -366,22 +367,22 @@ describe('cy.session', { retries: 0 }, () => {

validate.callsFake(() => false)

cy.session('session-1', setup, { validate })
cy.session(`session-${Cypress.state('test').id}`, setup, { validate })
})
})

describe('restores saved session flow', () => {
before(() => {
setupTestContext()
cy.log('Creating new session for test')
cy.session('session-1', setup)
cy.session(`session-${Cypress.state('test').id}`, setup)
.then(() => {
// reset and only test restored session
resetMocks()
})

cy.log('restore session to test against')
cy.session('session-1', setup)
cy.session(`session-${Cypress.state('test').id}`, setup)
cy.url().should('eq', 'about:blank')
})

Expand Down Expand Up @@ -433,14 +434,14 @@ describe('cy.session', { retries: 0 }, () => {
before(() => {
setupTestContext()
cy.log('Creating new session for test')
cy.session('session-1', setup, { validate })
cy.session(`session-${Cypress.state('test').id}`, setup, { validate })
.then(() => {
// reset and only test restored session
resetMocks()
})

cy.log('restore session to test against')
cy.session('session-1', setup, { validate })
cy.session(`session-${Cypress.state('test').id}`, setup, { validate })
cy.url().should('eq', 'about:blank')
})

Expand Down Expand Up @@ -504,7 +505,7 @@ describe('cy.session', { retries: 0 }, () => {
before(() => {
setupTestContext()
cy.log('Creating new session for test')
cy.session('session-1', setup, { validate })
cy.session(`session-${Cypress.state('test').id}`, setup, { validate })
.then(() => {
// reset and only test restored session
resetMocks()
Expand All @@ -516,7 +517,7 @@ describe('cy.session', { retries: 0 }, () => {
})

cy.log('restore session to test against')
cy.session('session-1', setup, { validate })
cy.session(`session-${Cypress.state('test').id}`, setup, { validate })
cy.url().should('eq', 'about:blank')
})

Expand Down Expand Up @@ -627,7 +628,7 @@ describe('cy.session', { retries: 0 }, () => {
it('fails to recreate session and logs correctly', function (done) {
setupTestContext()
cy.log('Creating new session for test')
cy.session('session-1', setup, { validate })
cy.session(`session-${Cypress.state('test').id}`, setup, { validate })
.then(() => {
// reset and only test restored session
resetMocks()
Expand Down Expand Up @@ -733,7 +734,7 @@ describe('cy.session', { retries: 0 }, () => {
})

cy.log('restore session to test against')
cy.session('session-1', setup, { validate })
cy.session(`session-${Cypress.state('test').id}`, setup, { validate })
})
})
})
Expand Down
12 changes: 5 additions & 7 deletions packages/driver/src/cy/commands/sessions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export default function (Commands, Cypress, cy) {
Cypress.on('run:start', () => {
Cypress.on('test:before:run:async', () => {
if (Cypress.config('experimentalSessionAndOrigin')) {
sessionsManager.currentTestRegisteredSessions.clear()

const clearPage = Cypress.config('testIsolation') === 'strict' ? navigateAboutBlank(false) : new Cypress.Promise.resolve()

return clearPage
Expand Down Expand Up @@ -92,18 +90,18 @@ export default function (Commands, Cypress, cy) {
}

let existingSession: SessionData = sessionsManager.getActiveSession(id)
const isRegisteredSessionForTest = sessionsManager.currentTestRegisteredSessions.has(id)
const isRegisteredSessionForSpec = sessionsManager.registeredSessions.has(id)

if (!setup) {
if (!existingSession || !isRegisteredSessionForTest) {
if (!existingSession || !isRegisteredSessionForSpec) {
$errUtils.throwErrByPath('sessions.session.not_found', { args: { id } })
}
} else {
const isUniqSessionDefinition = !existingSession || existingSession.setup.toString().trim() !== setup.toString().trim()

if (isUniqSessionDefinition) {
if (isRegisteredSessionForTest) {
$errUtils.throwErrByPath('sessions.session.duplicateId', { args: { id: existingSession.id } })
if (isRegisteredSessionForSpec) {
$errUtils.throwErrByPath('sessions.session.duplicateId', { args: { id } })
}

existingSession = sessions.defineSession({
Expand All @@ -112,7 +110,7 @@ export default function (Commands, Cypress, cy) {
validate: options.validate,
})

sessionsManager.currentTestRegisteredSessions.set(id, true)
sessionsManager.registeredSessions.set(id, true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/sessions/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getLogProperties = (displayName) => {
export default class SessionsManager {
Cypress
cy
currentTestRegisteredSessions = new Map()
registeredSessions = new Map()

constructor (Cypress, cy) {
this.Cypress = Cypress
Expand Down
13 changes: 5 additions & 8 deletions system-tests/__snapshots__/session_spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ exports['e2e sessions / session tests'] = `
can wait for login redirect automatically
✓ t1
can wait for a js redirect with an assertion
✓ t1
same session name, different options, multiple tests
✓ t1
✓ t2
Expand All @@ -107,15 +104,15 @@ exports['e2e sessions / session tests'] = `
✓ clears only secure context data - 2/2
43 passing
42 passing
1 pending
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 44
│ Passing: 43
│ Tests: 43
│ Passing: 42
│ Failing: 0 │
│ Pending: 1 │
│ Skipped: 0 │
Expand All @@ -133,9 +130,9 @@ exports['e2e sessions / session tests'] = `
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ session.cy.js XX:XX 44 43 - 1 - │
│ ✔ session.cy.js XX:XX 43 42 - 1 - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 44 43 - 1 -
✔ All specs passed! XX:XX 43 42 - 1 -
`
Expand Down
Loading

0 comments on commit ea2af61

Please sign in to comment.