11import { init , loadRemote } from '@module-federation/runtime'
22import type { CypressInternal , CyPromptDriverDefaultShape } from './prompt-driver-types'
33import type Emitter from 'component-emitter'
4+ import $errUtils from '../../../cypress/error_utils'
45
56interface CyPromptDriver { default : CyPromptDriverDefaultShape }
67
@@ -15,9 +16,26 @@ declare global {
1516let initializedModule : CyPromptDriverDefaultShape | null = null
1617const initializeModule = async ( Cypress : Cypress . Cypress ) : Promise < CyPromptDriverDefaultShape > => {
1718 // Wait for the cy prompt bundle to be downloaded and ready
18- const { success } = await Cypress . backend ( 'wait:for:cy:prompt:ready' )
19+ const { success, error } = await Cypress . backend ( 'wait:for:cy:prompt:ready' )
20+
21+ if ( error ) {
22+ if ( error . name === 'ENOSPC' ) {
23+ $errUtils . throwErrByPath ( 'prompt.promptDownloadError' , {
24+ args : {
25+ error,
26+ } ,
27+ } )
28+ } else {
29+ $errUtils . throwErrByPath ( 'prompt.promptDownloadTimedOut' , {
30+ args : {
31+ error,
32+ } ,
33+ } )
34+ }
35+ }
1936
20- if ( ! success ) {
37+ if ( ! success && ! error ) {
38+ // TODO: Generic error message
2139 throw new Error ( 'error waiting for cy prompt bundle to be downloaded and ready' )
2240 }
2341
@@ -40,6 +58,7 @@ const initializeModule = async (Cypress: Cypress.Cypress): Promise<CyPromptDrive
4058 const module = await loadRemote < CyPromptDriver > ( 'cy-prompt' )
4159
4260 if ( ! module ?. default ) {
61+ // TODO: Generic error message
4362 throw new Error ( 'error loading cy prompt driver' )
4463 }
4564
@@ -75,10 +94,18 @@ export default (Commands, Cypress, cy) => {
7594 }
7695
7796 const prompt = async ( message : string , options : object = { } ) => {
97+ if ( Cypress . testingType === 'component' ) {
98+ $errUtils . throwErrByPath ( 'prompt.promptTestingTypeError' )
99+
100+ return
101+ }
102+
78103 if ( ! initializeCloudCyPromptPromise ) {
79104 // TODO: (cy.prompt) We will look into supporting other browsers (and testing them)
80105 // as this is rolled out
81- throw new Error ( '`cy.prompt()` is not supported in this browser.' )
106+ $errUtils . throwErrByPath ( 'prompt.promptSupportedBrowser' )
107+
108+ return
82109 }
83110
84111 try {
@@ -92,6 +119,8 @@ export default (Commands, Cypress, cy) => {
92119
93120 return await cyPrompt ( message , options )
94121 } catch ( error ) {
122+ // TODO: Check error that the user is logged in / record key
123+
95124 // TODO: handle this better
96125 throw new Error ( `CyPromptDriver not found: ${ error } ` )
97126 }
0 commit comments