Skip to content

Commit 36278fc

Browse files
authored
feat: Add login state to manifest request for analytics (#22791)
1 parent 2def224 commit 36278fc

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

packages/data-context/src/sources/VersionsDataSource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export class VersionsDataSource {
139139
'x-os-name': os.platform(),
140140
'x-arch': os.arch(),
141141
'x-initial-launch': String(this._initialLaunch),
142+
'x-logged-in': String(!!this.ctx.user),
142143
}
143144

144145
if (this._currentTestingType) {

packages/data-context/test/unit/sources/VersionsDataSource.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe('VersionsDataSource', () => {
5252
'x-initial-launch': String(true),
5353
'x-machine-id': 'abcd123',
5454
'x-testing-type': 'e2e',
55+
'x-logged-in': 'false',
5556
},
5657
}).resolves({
5758
json: sinon.stub().resolves({
@@ -104,6 +105,7 @@ describe('VersionsDataSource', () => {
104105
'x-arch': 'x64',
105106
'x-initial-launch': String(false),
106107
'x-testing-type': 'component',
108+
'x-logged-in': 'false',
107109
},
108110
}).resolves({
109111
json: sinon.stub().resolves({
@@ -136,6 +138,7 @@ describe('VersionsDataSource', () => {
136138
'x-initial-launch': String(true),
137139
'x-machine-id': 'abcd123',
138140
'x-testing-type': 'e2e',
141+
'x-logged-in': 'false',
139142
},
140143
})
141144
.rejects()
@@ -162,6 +165,7 @@ describe('VersionsDataSource', () => {
162165
'x-initial-launch': String(true),
163166
'x-machine-id': 'abcd123',
164167
'x-testing-type': 'e2e',
168+
'x-logged-in': 'false',
165169
},
166170
})
167171
.callsFake(async () => new Response('Error'))

packages/launchpad/cypress/e2e/open-mode.cy.ts

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,53 @@ describe('Launchpad: Open Mode', () => {
2828
cy.get('h1').should('contain', 'Choose a Browser')
2929
})
3030

31-
it('includes x-framework and x-dev-server in request to Cypress manifest, even when launched in e2e mode', () => {
32-
cy.withCtx((ctx, o) => {
33-
o.sinon.spy(ctx.util.fetch)
31+
describe('request for Cypress manifest', () => {
32+
beforeEach(() => {
33+
cy.withCtx((ctx, o) => {
34+
o.sinon.spy(ctx.util.fetch)
35+
})
36+
37+
cy.scaffoldProject('todos')
38+
cy.openProject('todos', ['--e2e'])
3439
})
3540

36-
cy.scaffoldProject('todos')
37-
cy.openProject('todos', ['--e2e'])
38-
cy.visitLaunchpad()
39-
cy.get('h1').should('contain', 'Choose a Browser')
40-
cy.withCtx((ctx, o) => {
41-
expect(ctx.util.fetch).to.have.been.calledWithMatch('https://download.cypress.io/desktop.json', {
42-
headers: {
43-
'x-framework': 'react',
44-
'x-dev-server': 'webpack',
45-
},
41+
it('includes x-framework and x-dev-server, even when launched in e2e mode', () => {
42+
cy.visitLaunchpad()
43+
cy.get('h1').should('contain', 'Choose a Browser')
44+
cy.withCtx((ctx, o) => {
45+
expect(ctx.util.fetch).to.have.been.calledWithMatch('https://download.cypress.io/desktop.json', {
46+
headers: {
47+
'x-framework': 'react',
48+
'x-dev-server': 'webpack',
49+
},
50+
})
51+
})
52+
})
53+
54+
describe('logged-in state', () => {
55+
it(`sends 'false' when not logged in`, () => {
56+
cy.visitLaunchpad()
57+
cy.get('h1').should('contain', 'Choose a Browser')
58+
cy.withCtx((ctx, o) => {
59+
expect(ctx.util.fetch).to.have.been.calledWithMatch('https://download.cypress.io/desktop.json', {
60+
headers: {
61+
'x-logged-in': 'false',
62+
},
63+
})
64+
})
65+
})
66+
67+
it(`sends 'true' when logged in`, () => {
68+
cy.loginUser()
69+
cy.visitLaunchpad()
70+
cy.get('h1').should('contain', 'Choose a Browser')
71+
cy.withCtx((ctx, o) => {
72+
expect(ctx.util.fetch).to.have.been.calledWithMatch('https://download.cypress.io/desktop.json', {
73+
headers: {
74+
'x-logged-in': 'true',
75+
},
76+
})
77+
})
4678
})
4779
})
4880
})

0 commit comments

Comments
 (0)