-
Notifications
You must be signed in to change notification settings - Fork 1.1k
update env / task examples #6331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
167396a
update env / task examples
jennifer-shehane 50b347c
Merge branch 'main' into update-env-task-examples
jennifer-shehane c245f58
update plugin example to be more realistic
jennifer-shehane 8f99bba
lint
jennifer-shehane ca23e2c
more updates
jennifer-shehane 77f7fc2
lint
jennifer-shehane 8ea65c6
few more updates to wording
jennifer-shehane 3e09e47
Update docs/app/continuous-integration/overview.mdx
jennifer-shehane c72bb59
Update docs/api/commands/task.mdx
jennifer-shehane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -347,43 +347,43 @@ Placeholders let you use dynamic and sensitive values while maintaining cache ef | |
| ```typescript | ||
| describe('Campaign Management', () => { | ||
| it('creates multiple campaigns with different discount percentages', () => { | ||
| const adminPassword = Cypress.env('ADMIN_PASSWORD') | ||
|
|
||
| const campaigns = [ | ||
| { name: 'Fall Sale', discountPct: 10 }, | ||
| { name: 'Spring Sale', discountPct: 15 }, | ||
| ] | ||
|
|
||
| // This loop demonstrates the caching benefit: | ||
| // - First iteration: AI generates and caches the code | ||
| // - Subsequent iterations: Reuse cached code with different placeholder values | ||
| campaigns.forEach((campaign) => { | ||
| const campaignName = campaign.name | ||
| const campaignDiscountPct = campaign.discountPct | ||
|
|
||
| cy.prompt( | ||
| [ | ||
| `Visit ${Cypress.env('ADMIN_URL')}/admin/login`, | ||
| // Using {{adminPassword}} prevents this sensitive value from being sent to AI | ||
| 'Type {{adminPassword}} into the password field', | ||
| 'Click Sign In', | ||
| 'Open the Promotions tab', | ||
| 'Click to create a new campaign', | ||
| // Using {{campaignName}} and {{campaignDiscountPct}} | ||
| // allows for high performance caching with different values | ||
| 'Type {{campaignName}} into the name field', | ||
| 'Set discount to {{campaignDiscountPct}}% for all products', | ||
| 'Save the campaign', | ||
| 'Verify the campaign "{{campaignName}}" appears in the list', | ||
| ], | ||
| { | ||
| placeholders: { | ||
| adminPassword, | ||
| campaignName, | ||
| campaignDiscountPct, | ||
| }, | ||
| } | ||
| ) | ||
| cy.task('getSecret', 'ADMIN_PASSWORD').then((adminPassword) => { | ||
| const campaigns = [ | ||
| { name: 'Fall Sale', discountPct: 10 }, | ||
| { name: 'Spring Sale', discountPct: 15 }, | ||
| ] | ||
|
|
||
| // This loop demonstrates the caching benefit: | ||
| // - First iteration: AI generates and caches the code | ||
| // - Subsequent iterations: Reuse cached code with different placeholder values | ||
| campaigns.forEach((campaign) => { | ||
| const campaignName = campaign.name | ||
| const campaignDiscountPct = campaign.discountPct | ||
|
|
||
| cy.prompt( | ||
| [ | ||
| `Visit ${Cypress.env('ADMIN_URL')}/admin/login`, | ||
| // Using {{adminPassword}} prevents this sensitive value from being sent to AI | ||
| 'Type {{adminPassword}} into the password field', | ||
| 'Click Sign In', | ||
| 'Open the Promotions tab', | ||
| 'Click to create a new campaign', | ||
| // Using {{campaignName}} and {{campaignDiscountPct}} | ||
| // allows for high performance caching with different values | ||
| 'Type {{campaignName}} into the name field', | ||
| 'Set discount to {{campaignDiscountPct}}% for all products', | ||
| 'Save the campaign', | ||
| 'Verify the campaign "{{campaignName}}" appears in the list', | ||
| ], | ||
| { | ||
| placeholders: { | ||
| adminPassword, | ||
| campaignName, | ||
| campaignDiscountPct, | ||
| }, | ||
| } | ||
| ) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
@@ -567,7 +567,7 @@ describe('Feature: User Registration', () => { | |
| ], | ||
| { | ||
| placeholders: { | ||
| password: Cypress.env('PASSWORD'), | ||
| password: 'PASSWORD_PLACEHOLDER', // Use cy.task('getSecret', 'PASSWORD') to get the actual value | ||
| }, | ||
| } | ||
| ) | ||
|
|
@@ -687,20 +687,20 @@ The commands in the generated code may look like: | |
| ### Login flow | ||
|
|
||
| ```javascript | ||
| const password = Cypress.env('adminPassword') | ||
|
|
||
| cy.prompt( | ||
| [ | ||
| 'visit the login page', | ||
| 'type "[email protected]" in the email field', | ||
| 'type {{password}} in the password field', | ||
| 'click the login button', | ||
| 'verify we are redirected to the dashboard', | ||
| ], | ||
| { | ||
| placeholders: { password }, | ||
| } | ||
| ) | ||
| cy.task('getSecret', 'ADMIN_PASSWORD').then((password) => { | ||
| cy.prompt( | ||
| [ | ||
| 'visit the login page', | ||
| 'type "[email protected]" in the email field', | ||
| 'type {{password}} in the password field', | ||
| 'click the login button', | ||
| 'verify we are redirected to the dashboard', | ||
| ], | ||
| { | ||
| placeholders: { password }, | ||
| } | ||
| ) | ||
| }) | ||
| ``` | ||
|
|
||
| ### E-commerce checkout | ||
|
|
@@ -794,7 +794,7 @@ cy.origin('https://cloud.cypress.io/login', () => { | |
| ], | ||
| { | ||
| placeholders: { | ||
| password: Cypress.env('PASSWORD'), | ||
| password: 'PASSWORD_PLACEHOLDER', | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,13 +90,30 @@ require('dotenv').config() | |
| ```js | ||
| { | ||
| env: { | ||
| auth0_username: process.env.AUTH0_USERNAME, | ||
| auth0_password: process.env.AUTH0_PASSWORD, | ||
| auth0_domain: process.env.REACT_APP_AUTH0_DOMAIN, | ||
| auth0_audience: process.env.REACT_APP_AUTH0_AUDIENCE, | ||
| auth0_scope: process.env.REACT_APP_AUTH0_SCOPE, | ||
| auth0_client_id: process.env.REACT_APP_AUTH0_CLIENTID, | ||
| auth0_client_secret: process.env.AUTH0_CLIENT_SECRET, | ||
| }, | ||
| setupNodeEvents(on, config) { | ||
| on('task', { | ||
| getAuthCredentials() { | ||
| const username = process.env.AUTH0_USERNAME | ||
| const password = process.env.AUTH0_PASSWORD | ||
| if (!username || !password) { | ||
| throw new Error('AUTH0_USERNAME and AUTH0_PASSWORD must be set') | ||
| } | ||
| return { username, password } | ||
| }, | ||
| getSecret(secretName) { | ||
| const secret = process.env[secretName] | ||
| if (!secret) { | ||
| throw new Error(`Secret ${secretName} is not set`) | ||
| } | ||
| return secret | ||
| }, | ||
| }) | ||
| return config | ||
| }, | ||
| } | ||
| ``` | ||
|
|
@@ -177,10 +194,10 @@ describe('Auth0', function () { | |
| beforeEach(function () { | ||
| cy.task('db:seed') | ||
| cy.intercept('POST', '/graphql').as('createBankAccount') | ||
| cy.loginToAuth0( | ||
| Cypress.env('auth0_username'), | ||
| Cypress.env('auth0_password') | ||
| ) | ||
|
|
||
| cy.task('getAuthCredentials').then(({ username, password }) => { | ||
| cy.loginToAuth0(username, password) | ||
| }) | ||
| cy.visit('/') | ||
| }) | ||
|
|
||
|
|
@@ -256,23 +273,23 @@ Cypress.Commands.add( | |
| (username: string, password: string) => { | ||
| cy.log(`Logging in as ${username}`) | ||
| const client_id = Cypress.env('auth0_client_id') | ||
| const client_secret = Cypress.env('auth0_client_secret') | ||
| const audience = Cypress.env('auth0_audience') | ||
| const scope = Cypress.env('auth0_scope') | ||
|
|
||
| cy.request({ | ||
| method: 'POST', | ||
| url: `https://${Cypress.env('auth0_domain')}/oauth/token`, | ||
| body: { | ||
| grant_type: 'password', | ||
| username, | ||
| password, | ||
| audience, | ||
| scope, | ||
| client_id, | ||
| client_secret, | ||
| }, | ||
| }).then(({ body }) => { | ||
| cy.task('getSecret', 'AUTH0_CLIENT_SECRET').then((client_secret) => { | ||
| cy.request({ | ||
| method: 'POST', | ||
| url: `https://${Cypress.env('auth0_domain')}/oauth/token`, | ||
| body: { | ||
| grant_type: 'password', | ||
| username, | ||
| password, | ||
| audience, | ||
| scope, | ||
| client_id, | ||
| client_secret, | ||
| }, | ||
| }).then(({ body }) => { | ||
| const claims = jwt.decode(body.id_token) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tabs appear off in this section.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was probably fixed in a lint check I've run since then. |
||
| const { | ||
| nickname, | ||
|
|
@@ -309,6 +326,7 @@ Cypress.Commands.add( | |
| window.localStorage.setItem('auth0Cypress', JSON.stringify(item)) | ||
|
|
||
| cy.visit('/') | ||
| }) | ||
| }) | ||
| } | ||
| ) | ||
|
|
@@ -324,10 +342,9 @@ onboarding process and logout. | |
| describe('Auth0', function () { | ||
| beforeEach(function () { | ||
| cy.task('db:seed') | ||
| cy.loginByAuth0Api( | ||
| Cypress.env('auth0_username'), | ||
| Cypress.env('auth0_password') | ||
| ) | ||
| cy.task('getAuthCredentials').then(({ username, password }) => { | ||
| cy.loginByAuth0Api(username, password) | ||
| }) | ||
| }) | ||
|
|
||
| it('shows onboarding', function () { | ||
|
|
@@ -641,14 +658,16 @@ Cypress.Commands.add('loginByAuth0Api', (username, password) => { | |
| cy.exec('curl -4 icanhazip.com') | ||
| .its('stdout') | ||
| .then((ip) => { | ||
| cy.request({ | ||
| method: 'DELETE', | ||
| url: `https://${Cypress.env( | ||
| 'auth0_domain' | ||
| )}/api/v2/anomaly/blocks/ips/${ip}`, | ||
| auth: { | ||
| bearer: Cypress.env('auth0_mgmt_api_token'), | ||
| }, | ||
| cy.task('getSecret', 'AUTH0_MGMT_API_TOKEN').then((token) => { | ||
| cy.request({ | ||
| method: 'DELETE', | ||
| url: `https://${Cypress.env( | ||
| 'auth0_domain' | ||
| )}/api/v2/anomaly/blocks/ips/${ip}`, | ||
| auth: { | ||
| bearer: token, | ||
| }, | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.