Skip to content

Commit

Permalink
fix(server): correctly include projectRoot when adding a CI project f…
Browse files Browse the repository at this point in the history
…rom GUI (#17514)

Co-authored-by: Barthélémy Ledoux <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>
Co-authored-by: Jennifer Shehane <[email protected]>
Co-authored-by: Chris Breiding <[email protected]>
  • Loading branch information
5 people authored Jul 29, 2021
1 parent a5305de commit e49b3a4
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 21 deletions.
7 changes: 7 additions & 0 deletions npm/vite-dev-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [@cypress/vite-dev-server-v2.0.3](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.2...@cypress/vite-dev-server-v2.0.3) (2021-07-27)


### Bug Fixes

* make vite re-run on supportFile change ([#17485](https://github.com/cypress-io/cypress/issues/17485)) ([6cbf4c3](https://github.com/cypress-io/cypress/commit/6cbf4c38296d6287fbcbb0ef5ecd21cf63606153))

# [@cypress/vite-dev-server-v2.0.2](https://github.com/cypress-io/cypress/compare/@cypress/vite-dev-server-v2.0.1...@cypress/vite-dev-server-v2.0.2) (2021-07-15)


Expand Down
3 changes: 3 additions & 0 deletions npm/vite-dev-server/cypress/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: indigo;
}
1 change: 1 addition & 0 deletions npm/vite-dev-server/cypress/support.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '@testing-library/cypress/add-commands'
import './styles.css'

before(() => {
window.supportFileWasLoaded = true
Expand Down
6 changes: 3 additions & 3 deletions npm/vite-dev-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { debug as debugFn } from 'debug'
import { start as createDevServer, StartDevServer } from './startServer'
import { start as createDevServer, StartDevServerOptions } from './startServer'
const debug = debugFn('cypress:vite-dev-server:vite')

export { StartDevServer }
export { StartDevServerOptions }

type DoneCallback = () => unknown

Expand All @@ -11,7 +11,7 @@ export interface ResolvedDevServerConfig {
close: (done?: DoneCallback) => void
}

export async function startDevServer (startDevServerArgs: StartDevServer): Promise<ResolvedDevServerConfig> {
export async function startDevServer (startDevServerArgs: StartDevServerOptions): Promise<ResolvedDevServerConfig> {
const viteDevServer = await createDevServer(startDevServerArgs)

const app = await viteDevServer.listen()
Expand Down
13 changes: 9 additions & 4 deletions npm/vite-dev-server/src/makeCypressPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ const INIT_FILEPATH = resolve(__dirname, '../client/initCypressTests.js')

const HMR_DEPENDENCY_LOOKUP_MAX_ITERATION = 50

function getSpecsSet (specs: Spec[]) {
return new Set<string>(specs.map((spec) => spec.absolute))
function getSpecsPathsSet (specs: Spec[], supportFile?: string | null) {
return new Set<string>(
supportFile
? [...specs.map((spec) => spec.absolute), supportFile]
: specs.map((spec) => spec.absolute),
)
}

interface Spec{
Expand All @@ -38,10 +42,10 @@ export const makeCypressPlugin = (
): Plugin => {
let base = '/'

let specsPathsSet = getSpecsSet(specs)
let specsPathsSet = getSpecsPathsSet(specs, supportFilePath)

devServerEvents.on('dev-server:specs:changed', (specs: Spec[]) => {
specsPathsSet = getSpecsSet(specs)
specsPathsSet = getSpecsPathsSet(specs, supportFilePath)
})

const posixSupportFilePath = supportFilePath ? convertPathToPosix(resolve(projectRoot, supportFilePath)) : undefined
Expand Down Expand Up @@ -101,6 +105,7 @@ export const makeCypressPlugin = (

// as soon as we find one of the specs, we trigger the re-run of tests
for (const mod of moduleImporters.values()) {
debug('handleHotUpdate - mod.file', mod.file)
if (specsPathsSet.has(mod.file)) {
debug('handleHotUpdate - compile success')
devServerEvents.emit('dev-server:compile:success', { specFile: mod.file })
Expand Down
6 changes: 3 additions & 3 deletions npm/vite-dev-server/src/startServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Options {
[key: string]: unknown
}

export interface StartDevServer {
export interface StartDevServerOptions {
/**
* the Cypress options object
*/
Expand All @@ -27,7 +27,7 @@ export interface StartDevServer {
viteConfig?: UserConfig
}

const resolveServerConfig = async ({ viteConfig, options }: StartDevServer): Promise<InlineConfig> => {
const resolveServerConfig = async ({ viteConfig, options }: StartDevServerOptions): Promise<InlineConfig> => {
const { projectRoot, supportFile } = options.config

const requiredOptions: InlineConfig = {
Expand Down Expand Up @@ -66,7 +66,7 @@ const resolveServerConfig = async ({ viteConfig, options }: StartDevServer): Pro
return finalConfig
}

export async function start (devServerOptions: StartDevServer): Promise<ViteDevServer> {
export async function start (devServerOptions: StartDevServerOptions): Promise<ViteDevServer> {
if (!devServerOptions.viteConfig) {
debug('User did not pass in any Vite dev server configuration')
devServerOptions.viteConfig = {}
Expand Down
7 changes: 7 additions & 0 deletions npm/vue/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [@cypress/vue-v3.0.0-beta.4](https://github.com/cypress-io/cypress/compare/@cypress/vue-v3.0.0-beta.3...@cypress/vue-v3.0.0-beta.4) (2021-07-27)


### Bug Fixes

* do not register CT specific event in e2e mode ([5836203](https://github.com/cypress-io/cypress/commit/58362037fd231c6fdc587e422fc139bf7546ac2d))

# [@cypress/vue-v3.0.0-beta.3](https://github.com/cypress-io/cypress/compare/@cypress/vue-v3.0.0-beta.2...@cypress/vue-v3.0.0-beta.3) (2021-06-24)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const onSubmitNewProject = function (orgId) {
.contains('.btn', 'Set up project').click()
.then(() => {
expect(this.ipc.setupDashboardProject).to.be.calledWith({
projectRoot: '/foo/bar',
projectName: this.config.projectName,
orgId,
public: false,
Expand All @@ -21,6 +22,7 @@ const onSubmitNewProject = function (orgId) {
.then(() => {
expect(this.ipc.setupDashboardProject).to.be.calledWith({
projectName: 'New Project',
projectRoot: '/foo/bar',
orgId,
public: true,
})
Expand Down Expand Up @@ -114,7 +116,7 @@ describe('Connect to Dashboard', function () {
cy.stub(this.ipc, 'getRecordKeys').resolves(this.keys)
cy.stub(this.ipc, 'pingApiServer').resolves()
cy.stub(this.ipc, 'externalOpen')
cy.stub(this.ipc, 'setProjectId').resolvesArg(0)
cy.stub(this.ipc, 'setProjectId').callsFake((arg) => Promise.resolve(arg.id))
cy.stub(this.ipc, 'beginAuth').resolves()

this.getCurrentUser = this.util.deferred()
Expand Down Expand Up @@ -485,7 +487,7 @@ describe('Connect to Dashboard', function () {
cy.get('.setup-project')
.contains('.btn', 'Set up project').click()
.then(() => {
expect(this.ipc.setProjectId).to.be.calledWith(this.dashboardProjects[1].id)
expect(this.ipc.setProjectId).to.be.calledWith({ id: this.dashboardProjects[1].id, projectRoot: '/foo/bar' })
})
})

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) => {
return ipc.setProjectId(id)
const setProjectId = (id, projectRoot) => {
return ipc.setProjectId({ id, projectRoot })
}

export default {
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-gui/src/runs/runs-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class RunsList extends Component {

_getRecordKeys () {
if (this._needsKey()) {
projectsApi.getRecordKeys().then((keys = []) => {
if (keys.length) {
projectsApi.getRecordKeys().then((keys) => {
if (keys && keys.length) {
this.setState({ recordKey: keys[0].id })
}
})
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-gui/src/runs/setup-project.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,13 @@ class SetupProject extends Component {
if (this.state.newProject) {
return dashboardProjectsApi.setupDashboardProject({
projectName: this.state.projectName,
projectRoot: this.props.project.path,
orgId: this.state.selectedOrgId,
public: this.state.public,
})
}

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

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

case 'setup:dashboard:project':
return ProjectStatic.createCiProject(arg, options.projectRoot)
return ProjectStatic.createCiProject(arg, arg.projectRoot)
.then(send)
.catch(sendErr)

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

Expand Down
1 change: 1 addition & 0 deletions packages/server/lib/project_static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export async function writeProjectId (id: string, projectRoot: string) {

interface ProjectDetails {
projectName: string
projectRoot: string
orgId: string | null
public: boolean
}
Expand Down
24 changes: 22 additions & 2 deletions packages/server/test/unit/gui/events_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,28 @@ 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()

return this.handleEvent('set:project:id', arg)
.then(() => {
expect(stub).to.be.calledWith(arg.id, arg.projectRoot)
expect(this.send.firstCall.args[0]).to.eq('response')
expect(this.send.firstCall.args[1].id).to.match(/set:project:id-/)
})
})
})

describe('setup:dashboard:project', () => {
it('returns result of ProjectStatic.createCiProject', function () {
return this.handleEvent('setup:dashboard:project').then((assert) => {
const arg = { projectRoot: '/project/root/' }
const stub = sinon.stub(ProjectStatic, 'createCiProject').resolves()

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

sinon.stub(ProjectStatic, 'createCiProject').rejects(err)

return this.handleEvent('setup:dashboard:project').then((assert) => {
return this.handleEvent('setup:dashboard:project', { projectRoot: '/foo/bar' })
.then((assert) => {
return assert.sendErrCalledWith(err)
})
})
Expand Down

8 comments on commit e49b3a4

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e49b3a4 Jul 29, 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.0.0/circle-develop-e49b3a4b9fc99bb392235b7cad36139faff08eec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e49b3a4 Jul 29, 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.0.0/appveyor-develop-e49b3a4b9fc99bb392235b7cad36139faff08eec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e49b3a4 Jul 29, 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.0.0/appveyor-develop-e49b3a4b9fc99bb392235b7cad36139faff08eec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e49b3a4 Jul 29, 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.0.0/circle-develop-e49b3a4b9fc99bb392235b7cad36139faff08eec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e49b3a4 Jul 29, 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.1.0/circle-develop-e49b3a4b9fc99bb392235b7cad36139faff08eec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e49b3a4 Jul 29, 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.1.0/appveyor-develop-e49b3a4b9fc99bb392235b7cad36139faff08eec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e49b3a4 Jul 29, 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.1.0/appveyor-develop-e49b3a4b9fc99bb392235b7cad36139faff08eec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e49b3a4 Jul 29, 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.1.0/circle-develop-e49b3a4b9fc99bb392235b7cad36139faff08eec/cypress.tgz

Please sign in to comment.