Skip to content

Commit 2df3598

Browse files
fix: (cy.prompt) handle when the prompt is executed by in CT or when the experiment is not enabled (#32470)
* fix: (cy.prompt) handle when the prompt is executed by in CT or when the experiment is not enabled * Update packages/driver/cypress/e2e/commands/prompt/prompt.cy.ts * Update packages/driver/cypress/e2e/commands/prompt/prompt.cy.ts * update name of errors * Bump cache version to 9-15-2025 * update yarn.lock * fixes * fix snapshot * fix snapshot
1 parent e9954be commit 2df3598

File tree

9 files changed

+149
-2
lines changed

9 files changed

+149
-2
lines changed

.circleci/cache-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Bump this version to force CI to re-create the cache from scratch.
2-
9-12-2025
2+
9-15-2025

packages/driver/cypress/e2e/commands/prompt/prompt.cy.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
describe('src/cy/commands/prompt', () => {
2+
afterEach(() => {
3+
Cypress.testingType = 'e2e'
4+
})
5+
26
it('executes the prompt command', () => {
37
// TODO: (cy.prompt) We will look into supporting other browsers
48
// as this is rolled out. We will add error messages for other browsers
@@ -15,4 +19,17 @@ describe('src/cy/commands/prompt', () => {
1519

1620
cy.get('#log').should('contain', 'clicked')
1721
})
22+
23+
it('fails when testingType is component', (done) => {
24+
cy.on('fail', (err) => {
25+
expect(err.message).to.eq('`cy.prompt` is currently only supported in end-to-end tests.')
26+
done()
27+
})
28+
29+
Cypress.testingType = 'component'
30+
31+
cy.visit('http://www.foobar.com:3500/fixtures/prompt.html')
32+
33+
cy.prompt(['Click the "click me" button'])
34+
})
1835
})

packages/driver/src/cy/commands/prompt/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,31 @@ export default (Commands: Cypress.Cypress['Commands'], Cypress: Cypress.Cypress,
137137
}
138138

139139
Commands.addAll(commands)
140+
} else {
141+
Commands.addAll({
142+
prompt () {
143+
const stack = cy.state('current').get('userInvocationStack')
144+
145+
if (Cypress.testingType === 'component') {
146+
$errUtils.throwErrByPath('prompt.promptTestingTypeError', {
147+
errProps: {
148+
name: 'PromptTestingTypeError',
149+
},
150+
onFail: (err) => {
151+
err.stack = stack
152+
},
153+
})
154+
}
155+
156+
$errUtils.throwErrByPath('prompt.experimentalPromptCommandError', {
157+
errProps: {
158+
name: 'PromptNotEnabledError',
159+
},
160+
onFail: (err) => {
161+
err.stack = stack
162+
},
163+
})
164+
},
165+
})
140166
}
141167
}

packages/driver/src/cypress/error_messages.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,14 @@ export default {
13561356
docsUrl: 'https://on.cypress.io/prompt-download-error',
13571357
}
13581358
},
1359+
promptTestingTypeError: stripIndent`\
1360+
\`cy.prompt\` is currently only supported in end-to-end tests.
1361+
`,
1362+
experimentalPromptCommandError: stripIndent`\
1363+
\`cy.prompt\` cannot be called without the \`experimentalPromptCommand\` being set.
1364+
1365+
Please set this in your Cypress config file to continue using \`cy.prompt\`.
1366+
`,
13591367
},
13601368

13611369
proxy: {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
exports['e2e prompt / fails when experimentalPromptCommand is not set'] = `
2+
3+
====================================================================================================
4+
5+
(Run Starting)
6+
7+
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
8+
│ Cypress: 1.2.3 │
9+
│ Browser: FooBrowser 88 │
10+
│ Specs: 1 found (prompt.cy.js) │
11+
│ Searched: cypress/e2e/prompt.cy.js │
12+
└────────────────────────────────────────────────────────────────────────────────────────────────┘
13+
14+
15+
────────────────────────────────────────────────────────────────────────────────────────────────────
16+
17+
Running: prompt.cy.js (1 of 1)
18+
19+
20+
prompt
21+
1) should fail when experimentalPromptCommand is not set
22+
23+
24+
0 passing
25+
1 failing
26+
27+
1) prompt
28+
should fail when experimentalPromptCommand is not set:
29+
PromptNotEnabledError: \`cy.prompt\` cannot be called without the \`experimentalPromptCommand\` being set.
30+
31+
Please set this in your Cypress config file to continue using \`cy.prompt\`.
32+
[stack trace lines]
33+
34+
35+
36+
37+
(Results)
38+
39+
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
40+
│ Tests: 1 │
41+
│ Passing: 0 │
42+
│ Failing: 1 │
43+
│ Pending: 0 │
44+
│ Skipped: 0 │
45+
│ Screenshots: 1 │
46+
│ Video: false │
47+
│ Duration: X seconds │
48+
│ Spec Ran: prompt.cy.js │
49+
└────────────────────────────────────────────────────────────────────────────────────────────────┘
50+
51+
52+
(Screenshots)
53+
54+
- /XXX/XXX/XXX/cypress/screenshots/prompt.cy.js/prompt -- should fail when experim (1280x720)
55+
entalPromptCommand is not set (failed).png
56+
57+
58+
====================================================================================================
59+
60+
(Run Finished)
61+
62+
63+
Spec Tests Passing Failing Pending Skipped
64+
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
65+
│ ✖ prompt.cy.js XX:XX 1 - 1 - - │
66+
└────────────────────────────────────────────────────────────────────────────────────────────────┘
67+
✖ 1 of 1 failed (100%) XX:XX 1 - 1 - -
68+
69+
70+
`
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { defineConfig } = require('cypress')
2+
3+
module.exports = defineConfig({
4+
e2e: {
5+
supportFile: false,
6+
},
7+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('prompt', () => {
2+
it('should fail when experimentalPromptCommand is not set', () => {
3+
cy.prompt(['Click the "click me" button'])
4+
})
5+
})

system-tests/test/prompt_spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import systemTests from '../lib/system-tests'
2+
3+
describe('e2e prompt', () => {
4+
systemTests.setup()
5+
6+
systemTests.it('fails when experimentalPromptCommand is not set', {
7+
browser: 'electron',
8+
project: 'experimentalPromptCommand',
9+
spec: 'prompt.cy.js',
10+
configFile: 'cypress-disabled-prompt-experiment.config.js',
11+
expectedExitCode: 1,
12+
snapshot: true,
13+
})
14+
})

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32156,7 +32156,7 @@ vitest@2.1.9:
3215632156
vite-node "2.1.9"
3215732157
why-is-node-running "^2.3.0"
3215832158

32159-
vitest@3.2.4, vitest@^3.2.4:
32159+
vitest@^3.2.4:
3216032160
version "3.2.4"
3216132161
resolved "https://registry.yarnpkg.com/vitest/-/vitest-3.2.4.tgz#0637b903ad79d1539a25bc34c0ed54b5c67702ea"
3216232162
integrity sha512-LUCP5ev3GURDysTWiP47wRRUpLKMOfPh+yKTx3kVIEiu5KOMeqzpnYNsKyOoVrULivR8tLcks4+lga33Whn90A==

0 commit comments

Comments
 (0)