mirror of
https://github.com/cypress-io/cypress.git
synced 2026-03-13 21:00:48 -05:00
fix: Throw error when custom config file does not return expected value (#22927)
* fix: Throw error when custom config file does not return expected value * Improve test to avoid false positive * Code review changes * remove old code * remove unused yarn.lock Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>
This commit is contained in:
@@ -233,7 +233,7 @@ export class ProjectLifecycleManager {
|
||||
const devServerOptions = await this.ctx._apis.projectApi.getDevServer().start({ specs: this.ctx.project.specs, config: finalConfig })
|
||||
|
||||
if (!devServerOptions?.port) {
|
||||
this.ctx.onError(getError('CONFIG_FILE_DEV_SERVER_INVALID_RETURN', devServerOptions))
|
||||
throw getError('CONFIG_FILE_DEV_SERVER_INVALID_RETURN', devServerOptions)
|
||||
}
|
||||
|
||||
finalConfig.baseUrl = `http://localhost:${devServerOptions?.port}`
|
||||
|
||||
@@ -294,4 +294,38 @@ describe('setupNodeEvents', () => {
|
||||
cy.get('h1').should('contain', 'Choose a Browser')
|
||||
cy.get('[data-cy="alert"]').should('contain', 'Warning: Cannot Connect Base Url Warning')
|
||||
})
|
||||
|
||||
it('handles a devServer function returning wrong structure', () => {
|
||||
cy.scaffoldProject('dev-server-invalid')
|
||||
|
||||
// sets the current project to enable writeFileInProject
|
||||
cy.openProject('dev-server-invalid')
|
||||
|
||||
cy.visitLaunchpad()
|
||||
|
||||
cy.get('[data-cy-testingtype=component]').click()
|
||||
|
||||
cy.get('body')
|
||||
.should('contain.text', cy.i18n.launchpadErrors.generic.configErrorTitle)
|
||||
.and('contain.text', 'The returned value of the devServer function is not valid.')
|
||||
|
||||
cy.get('[data-cy="collapsible-header"]')
|
||||
.should('have.attr', 'aria-expanded', 'true')
|
||||
.contains(cy.i18n.launchpadErrors.generic.stackTraceLabel)
|
||||
|
||||
cy.log('Fix error and validate it reloads configuration')
|
||||
|
||||
cy.withCtx(async (ctx) => {
|
||||
await ctx.actions.file.writeFileInProject('cypress.config.js',
|
||||
`module.exports = {
|
||||
devServer: () => ({ port: '3000' })
|
||||
}`)
|
||||
})
|
||||
|
||||
cy.findByRole('button', { name: 'Try again' }).click()
|
||||
|
||||
cy.get('body')
|
||||
.should('not.contain.text', cy.i18n.launchpadErrors.generic.configErrorTitle)
|
||||
.should('contain.text', 'Welcome to Cypress!')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
retries: null,
|
||||
component: {
|
||||
supportFile: false,
|
||||
devServer (cypressConfig) {},
|
||||
indexHtmlFile: 'cypress/component/support/component-index.html',
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<title>Components App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div data-cy-root></div>
|
||||
</body>
|
||||
</html>
|
||||
1
system-tests/projects/dev-server-invalid/vite.config.js
Normal file
1
system-tests/projects/dev-server-invalid/vite.config.js
Normal file
@@ -0,0 +1 @@
|
||||
export default {}
|
||||
Reference in New Issue
Block a user