Skip to content

Commit c6758dc

Browse files
author
Barthélémy Ledoux
authored
fix: set projectId in a custom config file (#18240)
1 parent 26f92e0 commit c6758dc

File tree

9 files changed

+48
-27
lines changed

9 files changed

+48
-27
lines changed

packages/desktop-gui/cypress/fixtures/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"requestTimeout": 5000,
148148
"resolvedNodePath": null,
149149
"resolvedNodeVersion": "1.2.3",
150+
"configFile": "cypress.json",
150151
"hosts": {
151152
"*.foobar.com": "127.0.0.1"
152153
},

packages/desktop-gui/cypress/integration/settings_spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ describe('Settings', () => {
326326

327327
context('when configFile is false', () => {
328328
beforeEach(function () {
329-
this.openProject.resolve(Cypress._.assign({
329+
this.openProject.resolve(Cypress._.assign(this.config, {
330330
configFile: false,
331-
}, this.config))
331+
}))
332332

333333
this.goToSettings()
334334

@@ -342,9 +342,9 @@ describe('Settings', () => {
342342

343343
context('when configFile is set', function () {
344344
beforeEach(function () {
345-
this.openProject.resolve(Cypress._.assign({
345+
this.openProject.resolve(Cypress._.assign(this.config, {
346346
configFile: 'special-cypress.json',
347-
}, this.config))
347+
}))
348348

349349
this.goToSettings()
350350

packages/desktop-gui/cypress/integration/setup_project_spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const onSubmitNewProject = function (orgId) {
88
projectName: this.config.projectName,
99
orgId,
1010
public: false,
11+
configFile: 'cypress.json',
1112
})
1213
})
1314
})
@@ -25,6 +26,7 @@ const onSubmitNewProject = function (orgId) {
2526
projectRoot: '/foo/bar',
2627
orgId,
2728
public: true,
29+
configFile: 'cypress.json',
2830
})
2931
})
3032
})
@@ -487,7 +489,10 @@ describe('Connect to Dashboard', function () {
487489
cy.get('.setup-project')
488490
.contains('.btn', 'Set up project').click()
489491
.then(() => {
490-
expect(this.ipc.setProjectId).to.be.calledWith({ id: this.dashboardProjects[1].id, projectRoot: '/foo/bar' })
492+
expect(this.ipc.setProjectId).to.be.calledWith({
493+
id: this.dashboardProjects[1].id,
494+
projectRoot: '/foo/bar',
495+
configFile: 'cypress.json' })
491496
})
492497
})
493498

packages/desktop-gui/src/dashboard-projects/dashboard-projects-api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const setupDashboardProject = (projectDetails) => {
4545
.catch(ipc.isUnauthed, ipc.handleUnauthed)
4646
}
4747

48-
const setProjectId = (id, projectRoot) => {
49-
return ipc.setProjectId({ id, projectRoot })
48+
const setProjectId = (id, projectRoot, configFile) => {
49+
return ipc.setProjectId({ id, projectRoot, configFile })
5050
}
5151

5252
export default {

packages/desktop-gui/src/runs/setup-project.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,13 @@ class SetupProject extends Component {
378378
projectRoot: this.props.project.path,
379379
orgId: this.state.selectedOrgId,
380380
public: this.state.public,
381+
configFile: this.props.project.configFile,
381382
})
382383
}
383384

384-
return dashboardProjectsApi.setProjectId(this.state.selectedProjectId, this.props.project.path)
385+
return dashboardProjectsApi.setProjectId(this.state.selectedProjectId,
386+
this.props.project.path,
387+
this.props.project.configFile)
385388
.then((id) => {
386389
const project = dashboardProjectsStore.getProjectById(id)
387390

packages/server/lib/gui/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ const handleEvent = function (options, bus, event, id, type, arg) {
337337
.catch(sendErr)
338338

339339
case 'set:project:id':
340-
return ProjectStatic.writeProjectId(arg.id, arg.projectRoot)
340+
return ProjectStatic.writeProjectId(arg)
341341
.then(send)
342342
.catch(sendErr)
343343

packages/server/lib/project_static.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,21 @@ export function ensureExists (path, options) {
162162
return settings.exists(path, options)
163163
}
164164

165-
export async function writeProjectId (id: string, projectRoot: string) {
165+
interface ProjectIdOptions{
166+
id: string
167+
projectRoot: string
168+
configFile: string
169+
}
170+
171+
export async function writeProjectId ({ id, projectRoot, configFile }: ProjectIdOptions) {
166172
const attrs = { projectId: id }
167173

168174
logger.info('Writing Project ID', _.clone(attrs))
169175

170176
// TODO: We need to set this
171177
// this.generatedProjectIdTimestamp = new Date()
172178

173-
await settings.write(projectRoot, attrs)
179+
await settings.write(projectRoot, attrs, { configFile })
174180

175181
return id
176182
}
@@ -180,10 +186,11 @@ interface ProjectDetails {
180186
projectRoot: string
181187
orgId: string | null
182188
public: boolean
189+
configFile: string
183190
}
184191

185-
export async function createCiProject (projectDetails: ProjectDetails, projectRoot: string) {
186-
debug('create CI project with projectDetails %o projectRoot %s', projectDetails, projectRoot)
192+
export async function createCiProject ({ projectRoot, configFile, ...projectDetails }: ProjectDetails) {
193+
debug('create CI project with projectDetails %o projectRoot %s', projectDetails)
187194

188195
const authToken = await user.ensureAuthToken()
189196
const remoteOrigin = await commitInfo.getRemoteOrigin(projectRoot)
@@ -195,7 +202,11 @@ export async function createCiProject (projectDetails: ProjectDetails, projectRo
195202

196203
const newProject = await api.createProject(projectDetails, remoteOrigin, authToken)
197204

198-
await writeProjectId(newProject.id, projectRoot)
205+
await writeProjectId({
206+
configFile,
207+
projectRoot,
208+
id: newProject.id,
209+
})
199210

200211
return newProject
201212
}

packages/server/test/unit/gui/events_spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -926,12 +926,12 @@ describe('lib/gui/events', () => {
926926

927927
describe('set:project:id', () => {
928928
it('calls writeProjectId with projectRoot', function () {
929-
const arg = { id: '1', projectRoot: '/project/root/' }
930-
const stub = sinon.stub(ProjectStatic, 'writeProjectId').resolves()
929+
const arg = { id: '1', projectRoot: '/project/root/', configFile: 'cypress.json' }
930+
const stubWriteProjectId = sinon.stub(ProjectStatic, 'writeProjectId').resolves()
931931

932932
return this.handleEvent('set:project:id', arg)
933933
.then(() => {
934-
expect(stub).to.be.calledWith(arg.id, arg.projectRoot)
934+
expect(stubWriteProjectId).to.be.calledWith(arg)
935935
expect(this.send.firstCall.args[0]).to.eq('response')
936936
expect(this.send.firstCall.args[1].id).to.match(/set:project:id-/)
937937
})
@@ -940,12 +940,12 @@ describe('lib/gui/events', () => {
940940

941941
describe('setup:dashboard:project', () => {
942942
it('returns result of ProjectStatic.createCiProject', function () {
943-
const arg = { projectRoot: '/project/root/' }
944-
const stub = sinon.stub(ProjectStatic, 'createCiProject').resolves()
943+
const arg = { projectRoot: '/project/root/', configFile: 'cypress.json' }
944+
const stubCreateCiProject = sinon.stub(ProjectStatic, 'createCiProject').resolves()
945945

946946
return this.handleEvent('setup:dashboard:project', arg)
947947
.then(() => {
948-
expect(stub).to.be.calledWith(arg, arg.projectRoot)
948+
expect(stubCreateCiProject).to.be.calledWith(arg)
949949
expect(this.send.firstCall.args[0]).to.eq('response')
950950
expect(this.send.firstCall.args[1].id).to.match(/setup:dashboard:project-/)
951951
})

packages/server/test/unit/project_spec.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,14 +948,14 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
948948
})
949949

950950
it('calls Settings.write with projectRoot and attrs', function () {
951-
return writeProjectId('id-123').then((id) => {
951+
return writeProjectId({ id: 'id-123' }).then((id) => {
952952
expect(id).to.eq('id-123')
953953
})
954954
})
955955

956956
// TODO: This
957957
xit('sets generatedProjectIdTimestamp', function () {
958-
return writeProjectId('id-123').then(() => {
958+
return writeProjectId({ id: 'id-123' }).then(() => {
959959
expect(this.project.generatedProjectIdTimestamp).to.be.a('date')
960960
})
961961
})
@@ -1016,33 +1016,34 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
10161016

10171017
context('#createCiProject', () => {
10181018
const projectRoot = '/_test-output/path/to/project-e2e'
1019+
const configFile = 'cypress.config.js'
10191020

10201021
beforeEach(function () {
10211022
this.project = new ProjectBase({ projectRoot, testingType: 'e2e' })
10221023
this.newProject = { id: 'project-id-123' }
10231024

10241025
sinon.stub(user, 'ensureAuthToken').resolves('auth-token-123')
1025-
sinon.stub(settings, 'write').resolves('project-id-123')
1026+
sinon.stub(settings, 'write').resolves()
10261027
sinon.stub(commitInfo, 'getRemoteOrigin').resolves('remoteOrigin')
10271028
sinon.stub(api, 'createProject')
10281029
.withArgs({ foo: 'bar' }, 'remoteOrigin', 'auth-token-123')
10291030
.resolves(this.newProject)
10301031
})
10311032

10321033
it('calls api.createProject with user session', function () {
1033-
return createCiProject({ foo: 'bar' }, projectRoot).then(() => {
1034+
return createCiProject({ foo: 'bar', projectRoot }).then(() => {
10341035
expect(api.createProject).to.be.calledWith({ foo: 'bar' }, 'remoteOrigin', 'auth-token-123')
10351036
})
10361037
})
10371038

10381039
it('calls writeProjectId with id', function () {
1039-
return createCiProject({ foo: 'bar' }, projectRoot).then(() => {
1040-
expect(settings.write).to.be.calledWith(projectRoot, { projectId: 'project-id-123' })
1040+
return createCiProject({ foo: 'bar', projectRoot, configFile }).then(() => {
1041+
expect(settings.write).to.be.calledWith(projectRoot, { projectId: 'project-id-123' }, { configFile })
10411042
})
10421043
})
10431044

10441045
it('returns project id', function () {
1045-
return createCiProject({ foo: 'bar' }, projectRoot).then((projectId) => {
1046+
return createCiProject({ foo: 'bar', projectRoot }).then((projectId) => {
10461047
expect(projectId).to.eql(this.newProject)
10471048
})
10481049
})

0 commit comments

Comments
 (0)