Skip to content

Commit

Permalink
fix: set projectId in a custom config file (#18240)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barthélémy Ledoux authored Sep 27, 2021
1 parent 26f92e0 commit c6758dc
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 27 deletions.
1 change: 1 addition & 0 deletions packages/desktop-gui/cypress/fixtures/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"requestTimeout": 5000,
"resolvedNodePath": null,
"resolvedNodeVersion": "1.2.3",
"configFile": "cypress.json",
"hosts": {
"*.foobar.com": "127.0.0.1"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/desktop-gui/cypress/integration/settings_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ describe('Settings', () => {

context('when configFile is false', () => {
beforeEach(function () {
this.openProject.resolve(Cypress._.assign({
this.openProject.resolve(Cypress._.assign(this.config, {
configFile: false,
}, this.config))
}))

this.goToSettings()

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

context('when configFile is set', function () {
beforeEach(function () {
this.openProject.resolve(Cypress._.assign({
this.openProject.resolve(Cypress._.assign(this.config, {
configFile: 'special-cypress.json',
}, this.config))
}))

this.goToSettings()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const onSubmitNewProject = function (orgId) {
projectName: this.config.projectName,
orgId,
public: false,
configFile: 'cypress.json',
})
})
})
Expand All @@ -25,6 +26,7 @@ const onSubmitNewProject = function (orgId) {
projectRoot: '/foo/bar',
orgId,
public: true,
configFile: 'cypress.json',
})
})
})
Expand Down Expand Up @@ -487,7 +489,10 @@ describe('Connect to Dashboard', function () {
cy.get('.setup-project')
.contains('.btn', 'Set up project').click()
.then(() => {
expect(this.ipc.setProjectId).to.be.calledWith({ id: this.dashboardProjects[1].id, projectRoot: '/foo/bar' })
expect(this.ipc.setProjectId).to.be.calledWith({
id: this.dashboardProjects[1].id,
projectRoot: '/foo/bar',
configFile: 'cypress.json' })
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const setupDashboardProject = (projectDetails) => {
.catch(ipc.isUnauthed, ipc.handleUnauthed)
}

const setProjectId = (id, projectRoot) => {
return ipc.setProjectId({ id, projectRoot })
const setProjectId = (id, projectRoot, configFile) => {
return ipc.setProjectId({ id, projectRoot, configFile })
}

export default {
Expand Down
5 changes: 4 additions & 1 deletion packages/desktop-gui/src/runs/setup-project.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,13 @@ class SetupProject extends Component {
projectRoot: this.props.project.path,
orgId: this.state.selectedOrgId,
public: this.state.public,
configFile: this.props.project.configFile,
})
}

return dashboardProjectsApi.setProjectId(this.state.selectedProjectId, this.props.project.path)
return dashboardProjectsApi.setProjectId(this.state.selectedProjectId,
this.props.project.path,
this.props.project.configFile)
.then((id) => {
const project = dashboardProjectsStore.getProjectById(id)

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/gui/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ const handleEvent = function (options, bus, event, id, type, arg) {
.catch(sendErr)

case 'set:project:id':
return ProjectStatic.writeProjectId(arg.id, arg.projectRoot)
return ProjectStatic.writeProjectId(arg)
.then(send)
.catch(sendErr)

Expand Down
21 changes: 16 additions & 5 deletions packages/server/lib/project_static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,21 @@ export function ensureExists (path, options) {
return settings.exists(path, options)
}

export async function writeProjectId (id: string, projectRoot: string) {
interface ProjectIdOptions{
id: string
projectRoot: string
configFile: string
}

export async function writeProjectId ({ id, projectRoot, configFile }: ProjectIdOptions) {
const attrs = { projectId: id }

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

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

await settings.write(projectRoot, attrs)
await settings.write(projectRoot, attrs, { configFile })

return id
}
Expand All @@ -180,10 +186,11 @@ interface ProjectDetails {
projectRoot: string
orgId: string | null
public: boolean
configFile: string
}

export async function createCiProject (projectDetails: ProjectDetails, projectRoot: string) {
debug('create CI project with projectDetails %o projectRoot %s', projectDetails, projectRoot)
export async function createCiProject ({ projectRoot, configFile, ...projectDetails }: ProjectDetails) {
debug('create CI project with projectDetails %o projectRoot %s', projectDetails)

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

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

await writeProjectId(newProject.id, projectRoot)
await writeProjectId({
configFile,
projectRoot,
id: newProject.id,
})

return newProject
}
12 changes: 6 additions & 6 deletions packages/server/test/unit/gui/events_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,12 +926,12 @@ describe('lib/gui/events', () => {

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

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

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

return this.handleEvent('setup:dashboard:project', arg)
.then(() => {
expect(stub).to.be.calledWith(arg, arg.projectRoot)
expect(stubCreateCiProject).to.be.calledWith(arg)
expect(this.send.firstCall.args[0]).to.eq('response')
expect(this.send.firstCall.args[1].id).to.match(/setup:dashboard:project-/)
})
Expand Down
15 changes: 8 additions & 7 deletions packages/server/test/unit/project_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -948,14 +948,14 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
})

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

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

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

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

sinon.stub(user, 'ensureAuthToken').resolves('auth-token-123')
sinon.stub(settings, 'write').resolves('project-id-123')
sinon.stub(settings, 'write').resolves()
sinon.stub(commitInfo, 'getRemoteOrigin').resolves('remoteOrigin')
sinon.stub(api, 'createProject')
.withArgs({ foo: 'bar' }, 'remoteOrigin', 'auth-token-123')
.resolves(this.newProject)
})

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

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

it('returns project id', function () {
return createCiProject({ foo: 'bar' }, projectRoot).then((projectId) => {
return createCiProject({ foo: 'bar', projectRoot }).then((projectId) => {
expect(projectId).to.eql(this.newProject)
})
})
Expand Down

4 comments on commit c6758dc

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c6758dc Sep 27, 2021

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/8.5.0/circle-develop-c6758dc8f77d171c18e15b59ec92fcb4c2988f40/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c6758dc Sep 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 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/8.5.0/appveyor-develop-c6758dc8f77d171c18e15b59ec92fcb4c2988f40/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c6758dc Sep 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor 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/8.5.0/appveyor-develop-c6758dc8f77d171c18e15b59ec92fcb4c2988f40/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c6758dc Sep 27, 2021

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/8.5.0/circle-develop-c6758dc8f77d171c18e15b59ec92fcb4c2988f40/cypress.tgz

Please sign in to comment.