From 1dd75fa9c912691f6328d613bb438484693a649e Mon Sep 17 00:00:00 2001 From: Eric Passmore Date: Mon, 12 Jun 2023 09:50:52 -0700 Subject: [PATCH 1/2] initial cypress test for nav img --- README.md | 7 +++++++ cypress.config.ts | 15 +++++++++++++++ cypress/e2e/base_page_check.cy.ts | 6 ++++++ cypress/support/commands.ts | 5 +++++ cypress/support/e2e.ts | 15 +++++++++++++++ cypress/tsconfig.json | 8 ++++++++ package.json | 2 +- yarn.lock | 2 +- 8 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 cypress.config.ts create mode 100644 cypress/e2e/base_page_check.cy.ts create mode 100644 cypress/support/commands.ts create mode 100644 cypress/support/e2e.ts create mode 100644 cypress/tsconfig.json diff --git a/README.md b/README.md index 1a58321..a6aff26 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,10 @@ TBD - [x] Save address to localStorage - [x] Mobile optimization - [x] Edge runtime + +## Cypress Testing +To run the tests use the following command +`npx cypress run` + +You may find the spec tests under `cypress/e2e/*.cy.ts`. You may add additional tests to the existing file or start a new file in the same directory. Files in the `cypress/e2e` directory will automatically be picked up. + diff --git a/cypress.config.ts b/cypress.config.ts new file mode 100644 index 0000000..b32a137 --- /dev/null +++ b/cypress.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } from 'cypress' + +// example EVN vars can use in spec like the following: +// cy.visit(Cypress.env('proto')+'://'+Cypress.env('host')+'/');` +export default defineConfig({ + projectId: 'ENF EVM Faucet', + e2e: { + baseUrl: 'http://10.3.0.1:4173', + }, + //env: { + // proto: 'http', + // host: '10.3.0.1:4173', + //}, + video: false, +}) diff --git a/cypress/e2e/base_page_check.cy.ts b/cypress/e2e/base_page_check.cy.ts new file mode 100644 index 0000000..9b0978e --- /dev/null +++ b/cypress/e2e/base_page_check.cy.ts @@ -0,0 +1,6 @@ +describe('Base Page', () => { + it('navigation has image', () => { + cy.visit('/'); + cy.get('nav').find('img').should('have.attr', 'src', '/eos-evm.svg'); + }); +}); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts new file mode 100644 index 0000000..f0121ab --- /dev/null +++ b/cypress/support/commands.ts @@ -0,0 +1,5 @@ +// Example of a custom command +Cypress.Commands.add('dataCy', (value) => { + return cy.get(`[data-cy=${value}]`) +}); + diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts new file mode 100644 index 0000000..32b5b33 --- /dev/null +++ b/cypress/support/e2e.ts @@ -0,0 +1,15 @@ +import './commands' + +// + +declare global { + namespace Cypress { + interface Chainable { + /** + * Custom command to select DOM element by data-cy attribute. + * @example cy.dataCy('greeting') + */ + dataCy(value: string): Chainable; + } + } +} diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json new file mode 100644 index 0000000..d4314d0 --- /dev/null +++ b/cypress/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "es6", + "lib": ["es6", "dom"], + "types": ["cypress", "node"] + }, + "include": ["**/*.ts"] +} diff --git a/package.json b/package.json index 6fac3db..d8a2591 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@wharfkit/session": "latest", "@wharfkit/wallet-plugin-privatekey": "latest", "autoprefixer": "^10.4.7", - "cypress": "^12.11.0", + "cypress": "^12.14.0", "dayjs": "1.x", "dotenv": "^16.0.3", "eslint": "^8.28.0", diff --git a/yarn.lock b/yarn.lock index 887fa9c..9cbf9a9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1037,7 +1037,7 @@ cssesc@^3.0.0: resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee" integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg== -cypress@^12.11.0: +cypress@^12.14.0: version "12.14.0" resolved "https://registry.yarnpkg.com/cypress/-/cypress-12.14.0.tgz#37a19b85f5e9d881995e9fee1ddf41b3d3a623dd" integrity sha512-HiLIXKXZaIT1RT7sw1sVPt+qKtis3uYNm6KwC4qoYjabwLKaqZlyS/P+uVvvlBNcHIwL/BC6nQZajpbUd7hOgQ== From 1ba66434763d227495abc5fc4e9c74b5808dc99e Mon Sep 17 00:00:00 2001 From: Eric Passmore Date: Mon, 12 Jun 2023 09:54:22 -0700 Subject: [PATCH 2/2] change cypress to point to localhost --- cypress.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress.config.ts b/cypress.config.ts index b32a137..f311c2c 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -5,11 +5,11 @@ import { defineConfig } from 'cypress' export default defineConfig({ projectId: 'ENF EVM Faucet', e2e: { - baseUrl: 'http://10.3.0.1:4173', + baseUrl: 'http://localhost:4173', }, //env: { // proto: 'http', - // host: '10.3.0.1:4173', + // host: '10.10.10.1:4173', //}, video: false, })