Skip to content

Commit 72078ef

Browse files
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>
1 parent 6adba46 commit 72078ef

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

packages/data-context/src/data/ProjectLifecycleManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class ProjectLifecycleManager {
233233
const devServerOptions = await this.ctx._apis.projectApi.getDevServer().start({ specs: this.ctx.project.specs, config: finalConfig })
234234

235235
if (!devServerOptions?.port) {
236-
this.ctx.onError(getError('CONFIG_FILE_DEV_SERVER_INVALID_RETURN', devServerOptions))
236+
throw getError('CONFIG_FILE_DEV_SERVER_INVALID_RETURN', devServerOptions)
237237
}
238238

239239
finalConfig.baseUrl = `http://localhost:${devServerOptions?.port}`

packages/launchpad/cypress/e2e/config-files-error-handling.cy.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,38 @@ describe('setupNodeEvents', () => {
294294
cy.get('h1').should('contain', 'Choose a Browser')
295295
cy.get('[data-cy="alert"]').should('contain', 'Warning: Cannot Connect Base Url Warning')
296296
})
297+
298+
it('handles a devServer function returning wrong structure', () => {
299+
cy.scaffoldProject('dev-server-invalid')
300+
301+
// sets the current project to enable writeFileInProject
302+
cy.openProject('dev-server-invalid')
303+
304+
cy.visitLaunchpad()
305+
306+
cy.get('[data-cy-testingtype=component]').click()
307+
308+
cy.get('body')
309+
.should('contain.text', cy.i18n.launchpadErrors.generic.configErrorTitle)
310+
.and('contain.text', 'The returned value of the devServer function is not valid.')
311+
312+
cy.get('[data-cy="collapsible-header"]')
313+
.should('have.attr', 'aria-expanded', 'true')
314+
.contains(cy.i18n.launchpadErrors.generic.stackTraceLabel)
315+
316+
cy.log('Fix error and validate it reloads configuration')
317+
318+
cy.withCtx(async (ctx) => {
319+
await ctx.actions.file.writeFileInProject('cypress.config.js',
320+
`module.exports = {
321+
devServer: () => ({ port: '3000' })
322+
}`)
323+
})
324+
325+
cy.findByRole('button', { name: 'Try again' }).click()
326+
327+
cy.get('body')
328+
.should('not.contain.text', cy.i18n.launchpadErrors.generic.configErrorTitle)
329+
.should('contain.text', 'Welcome to Cypress!')
330+
})
297331
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
retries: null,
3+
component: {
4+
supportFile: false,
5+
devServer (cypressConfig) {},
6+
indexHtmlFile: 'cypress/component/support/component-index.html',
7+
},
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
</head>
9+
<body>
10+
<div data-cy-root></div>
11+
</body>
12+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {}

0 commit comments

Comments
 (0)