-
-
Save RobDoan/102fcb9ae37832749b07d08de943a22d to your computer and use it in GitHub Desktop.
Revisions
-
textbook revised this gist
Oct 17, 2022 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ cat <<-EOF > cypress.config.js video: false, }); EOF echo "\nimport '@testing-library/cypress/add-commands';" >> cypress/support/commands.js echo 'Creating basic E2E test' mkdir cypress/e2e/ -
textbook revised this gist
Jun 6, 2022 . 2 changed files with 40 additions and 25 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -13,26 +13,31 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat 2. Open the Cypress UI to bootstrap the test setup: ```bash $ npx cypress open --e2e ``` NPX will use the executable in the `node_modules/.bin/` directory, so you can use it for things you don't want to add to the package file. 3. Delete the example files: ```bash $ rm -rf ./cypress/fixtures/example.json ``` 4. Set a base URL in the `cypress.config.js` per the [best practices](https://docs.cypress.io/guides/references/best-practices.html#Setting-a-global-baseUrl) (I've also disabled automatic video recording): ```js const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { baseUrl: "http://localhost:3000", setupNodeEvents(on, config) { // implement node event listeners here }, }, video: false, }); ``` 5. Set up the Testing Library utilities by adding the following to `./cypress/support/commands.js`: @@ -61,7 +66,7 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat }, ``` 8. Create a new test file e.g. `./cypress/e2e/home.cy.js` with the following: ```javascript it("should load the page", () => { 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 charactersOriginal file line number Diff line number Diff line change @@ -7,33 +7,43 @@ if [[ $# -ne 1 ]]; then exit 1 fi echo 'Creating default React app' npx create-react-app@latest "$1" cd "$1" echo 'Installing Cypress dependencies' npm install \ cypress \ eslint-plugin-cypress \ @testing-library/cypress echo 'Opening Cypress, please exit the UI once it has loaded' npx cypress open --e2e echo 'Removing preinstalled examples' rm -rf \ cypress/fixtures/example.json echo 'Updating Cypress configuration' cat <<-EOF > cypress.config.js const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { baseUrl: "http://localhost:3000", setupNodeEvents(on, config) { // implement node event listeners here }, }, video: false, }); EOF echo "import '@testing-library/cypress/add-commands';" >> cypress/support/commands.js echo 'Creating basic E2E test' mkdir cypress/e2e/ cat <<-EOF > cypress/e2e/home.cy.js it("should load the page", () => { cy.visit("/"); cy.findAllByText(/learn react/i).should("have.length", 1); @@ -49,12 +59,12 @@ cat <<-EOF >> .gitignore EOF echo 'Setting NPM package configuration' npm set-script e2e 'cypress run' npm set-script lint 'eslint cypress/ src/' cat package.json \ | jq '.eslintConfig.overrides = [{"extends": ["plugin:cypress/recommended"], "files": ["cypress/**/*.js"]}]' \ | tee package.json echo 'Committing changes' git add . git commit -m 'Set up Cypress testing' -
textbook revised this gist
May 16, 2022 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat ```json { "baseUrl": "http://localhost:3000", "video": false } ``` -
textbook revised this gist
Apr 10, 2021 . 1 changed file with 11 additions and 11 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped application. Assumes the \*nix command line, you may need to adapt this for a Windows command line (or use WSL or Git Bash). 1. Install [Cypress](https://www.cypress.io/) and the [Testing Library](https://testing-library.com/docs/cypress-testing-library/intro) utilities for it (to match the helpers CRA installs): ```bash $ npm i {,@testing-library/}cypress @@ -10,7 +10,7 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat CRA seems to install everything as a production dependency, but you can add `--save-dev` if you like. 2. Open the Cypress UI to bootstrap the test setup: ```bash $ ./node_modules/.bin/cypress open @@ -20,13 +20,13 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat You can quit the Cypress UI after you've had a look at the examples. 3. Delete the example files: ```bash $ rm -rf ./cypress/fixtures/example.json ./cypress/integration/examples/ ``` 4. Set a base URL in the `cypress.json` per the [best practices](https://docs.cypress.io/guides/references/best-practices.html#Setting-a-global-baseUrl) (I've also disabled automatic video recording): ```json { @@ -35,21 +35,21 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat } ``` 5. Set up the Testing Library utilities by adding the following to `./cypress/support/commands.js`: ```javascript import "@testing-library/cypress/add-commands"; ``` 6. Make sure you exclude any videos and screenshots recorded by Cypress from your commits by adding the following to `.gitignore`: ```ignore # Cypress cypress/screenshots/ cypress/videos/ ``` 7. Add a script that runs the E2E tests into the package file: ```json "scripts": @@ -61,7 +61,7 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat }, ``` 8. Create a new test file e.g. `./cypress/integration/home.test.js` with the following: ```javascript it("should load the page", () => { @@ -72,9 +72,9 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat This is the same as the default `src/App.test.js`, but running via Cypress rather than Jest. 9. Start the app in one terminal (`npm start`) then run the tests in another (`npm run e2e`). It should pass! 10. Install the ESLint plugin with `npm install eslint-plugin-cypress` then add the following to the `eslintConfig` object in `package.json`: ```json "overrides": [ @@ -89,4 +89,4 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat ] ``` This is optional, but will ensure the linting passes (by adding the Cypress globals) and give some useful hints on good test practices. -
textbook revised this gist
Apr 10, 2021 . 1 changed file with 11 additions and 11 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -77,16 +77,16 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat 10. _[Optional]_ Install the ESLint plugin with `npm install eslint-plugin-cypress` then add the following to the `eslintConfig` object in `package.json`: ```json "overrides": [ { "extends": [ "plugin:cypress/recommended" ], "files": [ "cypress/**/*.js" ] } ] ``` This will ensure the linting passes, by adding the Cypress globals, and give some useful hints on good test practices. -
textbook revised this gist
Apr 10, 2021 . 1 changed file with 3 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -87,4 +87,6 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat ] } ] ``` This will ensure the linting passes, by adding the Cypress globals, and give some useful hints on good test practices. -
textbook revised this gist
Apr 10, 2021 . 1 changed file with 16 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -72,4 +72,19 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat This is the same as the default `src/App.test.js`, but running via Cypress rather than Jest. 9. Start the app in one terminal (`npm start`) then run the tests in another (`npm run e2e`). It should pass! 10. _[Optional]_ Install the ESLint plugin with `npm install eslint-plugin-cypress` then add the following to the `eslintConfig` object in `package.json`: ```json "overrides": [ { "extends": [ "plugin:cypress/recommended" ], "files": [ "cypress/**/*.js" ] } ] ``` -
textbook revised this gist
Apr 10, 2021 . 1 changed file with 13 additions and 6 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -26,23 +26,30 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat $ rm -rf ./cypress/fixtures/example.json ./cypress/integration/examples/ ``` 4. Set a base URL in the `cypress.json` per the [best practices](https://docs.cypress.io/guides/references/best-practices.html#Setting-a-global-baseUrl) (I've also disabled automatic video recording): ```json { "baseUrl": "http://localhost:3000", "videos": false } ``` 5. Set up the Testing Library utilities by adding the following to `./cypress/support/commands.js`: ```javascript import "@testing-library/cypress/add-commands"; ``` 6. Make sure you exclude any videos and screenshots recorded by Cypress from your commits by adding the following to `.gitignore`: ```ignore # Cypress cypress/screenshots/ cypress/videos/ ``` 7. Add a script that runs the E2E tests into the package file: ```json "scripts": @@ -54,7 +61,7 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat }, ``` 8. Create a new test file e.g. `./cypress/integration/home.test.js` with the following: ```javascript it("should load the page", () => { @@ -65,4 +72,4 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat This is the same as the default `src/App.test.js`, but running via Cypress rather than Jest. 9. Start the app in one terminal (`npm start`) then run the tests in another (`npm run e2e`). It should pass! -
textbook revised this gist
Mar 11, 2021 . 1 changed file with 8 additions and 11 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -34,17 +34,18 @@ echo "import '@testing-library/cypress/add-commands';" >> cypress/support/comman echo 'Creating basic E2E test' cat <<-EOF > cypress/integration/home.test.js it("should load the page", () => { cy.visit("/"); cy.findAllByText(/learn react/i).should("have.length", 1); }); EOF echo 'Ignoring Cypress test assets' cat <<-EOF >> .gitignore # cypress cypress/screenshots/ cypress/videos/ EOF echo 'Setting NPM package configuration' @@ -54,10 +55,6 @@ cat package.json \ | jq '.eslintConfig.overrides = [{"extends": ["plugin:cypress/recommended"], "files": ["cypress/**/*.js"]}]' \ | tee package.json echo 'Install and configure Cypress' git add . git commit -m 'Set up Cypress testing' -
textbook revised this gist
Mar 11, 2021 . 1 changed file with 63 additions and 0 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ #!/bin/bash set -euo pipefail if [[ $# -ne 1 ]]; then echo 'Usage: new-cra-app.sh <app-name>' exit 1 fi echo 'Create default React app' npx create-react-app@latest --use-npm "$1" cd "$1" echo 'Install Cypress dependencies' npm install \ cypress \ eslint-plugin-cypress \ @testing-library/cypress echo 'Opening Cypress, please exit the UI once it has loaded' node_modules/.bin/cypress open echo 'Removing preinstalled examples' rm -rf \ cypress/fixtures/example.json \ cypress/integration/examples/ echo 'Updating Cypress configuration' echo '{"baseUrl": "http://localhost:3000", "video": false}' \ | jq \ | tee cypress.json echo "import '@testing-library/cypress/add-commands';" >> cypress/support/commands.js echo 'Creating basic E2E test' cat <<-EOF > cypress/integration/home.test.js it("should load the page", () => { cy.visit("/"); cy.findAllByText(/learn react/i).should("have.length", 1); }); EOF echo 'Ignoring Cypress test assets' cat <<-EOF >> .gitignore # cypress cypress/screenshots/ cypress/videos/ EOF echo 'Setting NPM package configuration' cat package.json \ | jq '.scripts.e2e = "cypress run"' \ | jq '.scripts.lint = "eslint cypress/ src/"' \ | jq '.eslintConfig.overrides = [{"extends": ["plugin:cypress/recommended"], "files": ["cypress/**/*.js"]}]' \ | tee package.json echo 'Fix code style' npm run lint -- --fix echo 'Install and configure Cypress' git add . git commit -m 'Set up Cypress testing' -
textbook revised this gist
Oct 25, 2020 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped applicat $ npm i {,@testing-library/}cypress ``` `i` is short for install, and the braces `{}` are expanded by [brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html) to `cypress @testing-library/cypress`. CRA seems to install everything as a production dependency, but you can add `--save-dev` if you like. -
textbook revised this gist
Oct 25, 2020 . 1 changed file with 9 additions and 5 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,12 @@ Here is how to add Cypress E2E tests to a Create React App bootstrapped application. Assumes the \*nix command line, you may need to adapt this for a Windows command line (or use WSL or Git Bash). 1. Install [Cypress](https://www.cypress.io/) and the [Testing Library](https://testing-library.com/docs/cypress-testing-library/intro) utilities for it (to match the helpers CRA installs): ```bash $ npm i {,@testing-library/}cypress ``` `i` is short for install, and the braces `{}` are expanded CRA seems to install everything as a production dependency, but you can add `--save-dev` if you like. @@ -30,15 +34,15 @@ } ``` 5. Make sure you exclude any videos and screenshots recorded by Cypress from your commits by adding the following to `.gitignore`: ```ignore # Cypress cypress/screenshots/ cypress/videos/ ``` 6. Add a script that runs the E2E tests into the package file: ```json "scripts": @@ -50,7 +54,7 @@ }, ``` 7. Create a new test file e.g. `./cypress/integration/home.test.js` with the following: ```javascript it("should load the page", () => { @@ -61,4 +65,4 @@ This is the same as the default `src/App.test.js`, but running via Cypress rather than Jest. 8. Start the app in one terminal (`npm start`) then run the tests in another (`npm run e2e`). It should pass! -
textbook created this gist
Oct 25, 2020 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ 1. Install [Cypress](https://www.cypress.io/) and the [Testing Library](https://testing-library.com/docs/cypress-testing-library/intro) utilities for it (to match the helpers CRA installs): ```bash $ npm install cypress @testing-library/cypress ``` CRA seems to install everything as a production dependency, but you can add `--save-dev` if you like. 2. Open the Cypress UI to bootstrap the test setup: ```bash $ ./node_modules/.bin/cypress open ``` NPM installs the executables for all of your installed modules in the `.bin` directory, so you can use this for things you don't want to add to the package file. You can quit the Cypress UI after you've had a look at the examples. 3. Delete the example files: ```bash $ rm -rf ./cypress/fixtures/example.json ./cypress/integration/examples/ ``` 4. Set a base URL in the `cypress.json` per the [best practices](https://docs.cypress.io/guides/references/best-practices.html#Setting-a-global-baseUrl): ```json { "baseUrl": "http://localhost:3000" } ``` - Make sure you exclude any videos and screenshots recorded by Cypress from your commits by adding the following to `.gitignore`: ```ignore # Cypress cypress/screenshots/ cypress/videos/ ``` - Add a script that runs the E2E tests into the package file: ```json "scripts": "e2e": "cypress run", "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, ``` - Create a new test file e.g. `./cypress/integration/home.test.js` with the following: ```javascript it("should load the page", () => { cy.visit("/"); cy.findAllByText(/learn react/i).should("have.length", 1); }); ``` This is the same as the default `src/App.test.js`, but running via Cypress rather than Jest. - Start the app in one terminal (`npm start`) then run the tests in another (`npm run e2e`). It should pass!