Skip to content

Commit aa543ae

Browse files
chore: cy prompt infrastructure (#31748)
* feat: cy prompt infrastructure * refactor and add tests * refactor * rename experimental config * prompt * fix test * Update cy-prompt-development.md * Update cy-prompt-development.md * PR comments * Update packages/server/lib/cloud/api/cy-prompt/get_cy_prompt_bundle.ts Co-authored-by: Copilot <[email protected]> * PR comments --------- Co-authored-by: Copilot <[email protected]>
1 parent c26b182 commit aa543ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1614
-75
lines changed

cli/types/cypress.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,11 @@ declare namespace Cypress {
18261826
*/
18271827
prevUntil<E extends Node = HTMLElement>(element: E | JQuery<E>, filter?: string, options?: Partial<Loggable & Timeoutable>): Chainable<JQuery<E>>
18281828

1829+
/**
1830+
* TODO: add docs
1831+
*/
1832+
prompt(message: string, options?: Partial<Loggable & Timeoutable>): Chainable<Subject>
1833+
18291834
/**
18301835
* Read a file and yield its contents.
18311836
*
@@ -3158,6 +3163,11 @@ declare namespace Cypress {
31583163
* @default false
31593164
*/
31603165
experimentalStudio: boolean
3166+
/**
3167+
* Enables the prompt command feature.
3168+
* @default false
3169+
*/
3170+
experimentalPromptCommand: boolean
31613171
/**
31623172
* Adds support for testing in the WebKit browser engine used by Safari. See https://on.cypress.io/webkit-experiment for more information.
31633173
* @default false

guides/cy-prompt-development.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1+
# `cy.prompt` Development
12

3+
In production, the code used to facilitate the prompt command will be retrieved from the Cloud.
4+
5+
To run against locally developed `cy.prompt`:
6+
7+
- Clone the `cypress-services` repo
8+
- Run `yarn`
9+
- Run `yarn watch` in `app/packages/cy-prompt`
10+
- Set:
11+
- `CYPRESS_INTERNAL_ENV=<environment>` (e.g. `staging` or `production` if you want to hit those deployments of `cypress-services` or `development` if you want to hit a locally running version of `cypress-services`)
12+
- `CYPRESS_LOCAL_CY_PROMPT_PATH` to the path to the `cypress-services/app/packages/cy-prompt/dist/development` directory
13+
- Clone the `cypress` repo
14+
- Run `yarn`
15+
- Run `yarn cypress:open`
16+
- Log In to the Cloud via the App
17+
- Open a project that has `experimentalPromptCommand: true` set in the `e2e` config of the `cypress.config.js|ts` file.
18+
19+
To run against a deployed version of `cy.prompt`:
20+
21+
- Set:
22+
- `CYPRESS_INTERNAL_ENV=<environment>` (e.g. `staging` or `production` if you want to hit those deployments of `cypress-services` or `development` if you want to hit a locally running version of `cypress-services`)
23+
24+
## Testing
25+
26+
### Unit/Component Testing
27+
28+
The code that supports cloud `cy.prompt` and lives in the `cypress` monorepo is unit, integration, and e2e tested in a similar fashion to the rest of the code in the repo. See the [contributing guide](https://github.com/cypress-io/cypress/blob/ad353fcc0f7fdc51b8e624a2a1ef4e76ef9400a0/CONTRIBUTING.md?plain=1#L366) for more specifics.
29+
30+
The code that supports cloud `cy.prompt` and lives in the `cypress-services` monorepo has unit tests that live alongside the code in that monorepo.

packages/config/__snapshots__/index.spec.ts.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ exports['config/src/index .getDefaultValues returns list of public config keys 1
4646
'experimentalSourceRewriting': false,
4747
'experimentalSingleTabRunMode': false,
4848
'experimentalStudio': false,
49+
'experimentalPromptCommand': false,
4950
'experimentalWebKitSupport': false,
5051
'fileServerFolder': '',
5152
'fixturesFolder': 'cypress/fixtures',
@@ -137,6 +138,7 @@ exports['config/src/index .getDefaultValues returns list of public config keys f
137138
'experimentalSourceRewriting': false,
138139
'experimentalSingleTabRunMode': false,
139140
'experimentalStudio': false,
141+
'experimentalPromptCommand': false,
140142
'experimentalWebKitSupport': false,
141143
'fileServerFolder': '',
142144
'fixturesFolder': 'cypress/fixtures',
@@ -224,6 +226,7 @@ exports['config/src/index .getPublicConfigKeys returns list of public config key
224226
'experimentalSourceRewriting',
225227
'experimentalSingleTabRunMode',
226228
'experimentalStudio',
229+
'experimentalPromptCommand',
227230
'experimentalWebKitSupport',
228231
'fileServerFolder',
229232
'fixturesFolder',

packages/config/src/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ const driverConfigOptions: Array<DriverConfigOption> = [
259259
validation: validate.isBoolean,
260260
isExperimental: true,
261261
requireRestartOnChange: 'browser',
262+
}, {
263+
name: 'experimentalPromptCommand',
264+
defaultValue: false,
265+
validation: validate.isBoolean,
266+
isExperimental: true,
267+
requireRestartOnChange: 'server',
262268
}, {
263269
name: 'experimentalWebKitSupport',
264270
defaultValue: false,

packages/config/test/project/utils.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,7 @@ describe('config/src/project/utils', () => {
10781078
experimentalRunAllSpecs: { value: false, from: 'default' },
10791079
experimentalSingleTabRunMode: { value: false, from: 'default' },
10801080
experimentalStudio: { value: false, from: 'default' },
1081+
experimentalPromptCommand: { value: false, from: 'default' },
10811082
experimentalSourceRewriting: { value: false, from: 'default' },
10821083
experimentalWebKitSupport: { value: false, from: 'default' },
10831084
fileServerFolder: { value: '', from: 'default' },
@@ -1197,6 +1198,7 @@ describe('config/src/project/utils', () => {
11971198
experimentalRunAllSpecs: { value: false, from: 'default' },
11981199
experimentalSingleTabRunMode: { value: false, from: 'default' },
11991200
experimentalStudio: { value: false, from: 'default' },
1201+
experimentalPromptCommand: { value: false, from: 'default' },
12001202
experimentalSourceRewriting: { value: false, from: 'default' },
12011203
experimentalWebKitSupport: { value: false, from: 'default' },
12021204
fileServerFolder: { value: '', from: 'default' },

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FoundBrowser, Editor, AllowedState, AllModeOptions, TestingType, BrowserStatus, PACKAGE_MANAGERS, AuthStateName, MIGRATION_STEPS, MigrationStep, StudioLifecycleManagerShape } from '@packages/types'
1+
import { FoundBrowser, Editor, AllowedState, AllModeOptions, TestingType, BrowserStatus, PACKAGE_MANAGERS, AuthStateName, MIGRATION_STEPS, MigrationStep, StudioLifecycleManagerShape, CyPromptLifecycleManagerShape } from '@packages/types'
22
import { WizardBundler, CT_FRAMEWORKS, resolveComponentFrameworkDefinition, ErroredFramework } from '@packages/scaffold-config'
33
import type { NexusGenObjects } from '@packages/graphql/src/gen/nxs.gen'
44
// tslint:disable-next-line no-implicit-dependencies - electron dep needs to be defined
@@ -165,6 +165,7 @@ export interface CoreDataShape {
165165
eventCollectorSource: EventCollectorSource | null
166166
didBrowserPreviouslyHaveUnexpectedExit: boolean
167167
studioLifecycleManager?: StudioLifecycleManagerShape
168+
cyPromptLifecycleManager?: CyPromptLifecycleManagerShape
168169
}
169170

170171
/**

packages/driver/cypress.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const baseConfig: Cypress.ConfigOptions = {
77
experimentalStudio: true,
88
experimentalMemoryManagement: true,
99
experimentalWebKitSupport: true,
10+
experimentalPromptCommand: true,
1011
hosts: {
1112
'foobar.com': '127.0.0.1',
1213
'*.foobar.com': '127.0.0.1',
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
describe('src/cy/commands/prompt', () => {
2+
it('executes the prompt command', () => {
3+
cy.visit('/fixtures/dom.html')
4+
5+
// TODO: add more tests when cy.prompt is built out, but for now this just
6+
// verifies that the command executes without throwing an error
7+
cy.prompt('Hello, world!')
8+
})
9+
})

packages/driver/cypress/e2e/e2e/origin/commands/misc.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ it('verifies number of cy commands', () => {
224224
'writeFile', 'fixture', 'clearLocalStorage', 'url', 'hash', 'location', 'end', 'noop', 'log', 'wrap', 'reload', 'go', 'visit',
225225
'focused', 'get', 'contains', 'shadow', 'within', 'request', 'session', 'screenshot', 'task', 'find', 'filter', 'not',
226226
'children', 'eq', 'closest', 'first', 'last', 'next', 'nextAll', 'nextUntil', 'parent', 'parents', 'parentsUntil', 'prev', 'press',
227-
'prevAll', 'prevUntil', 'siblings', 'wait', 'title', 'window', 'document', 'viewport', 'server', 'route', 'intercept', 'origin',
227+
'prevAll', 'prevUntil', 'prompt', 'siblings', 'wait', 'title', 'window', 'document', 'viewport', 'server', 'route', 'intercept', 'origin',
228228
'mount', 'as', 'root', 'getAllLocalStorage', 'clearAllLocalStorage', 'getAllSessionStorage', 'clearAllSessionStorage',
229229
'getAllCookies', 'clearAllCookies',
230230
]

packages/driver/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@cypress/unique-selector": "0.0.5",
2323
"@cypress/webpack-dev-server": "0.0.0-development",
2424
"@cypress/webpack-preprocessor": "0.0.0-development",
25+
"@module-federation/runtime": "^0.8.11",
2526
"@packages/config": "0.0.0-development",
2627
"@packages/errors": "0.0.0-development",
2728
"@packages/net-stubbing": "0.0.0-development",

0 commit comments

Comments
 (0)