From 752d55ad4a0b5d0c39c26c463662c226ef5fbcc0 Mon Sep 17 00:00:00 2001 From: RoopeK <35376295+Toopemus@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:25:09 +0200 Subject: [PATCH 01/13] added compose file, added working defaults in .env.example --- README.md | 19 ++++++++++++------- backend/.env.example | 16 ++++++++-------- backend/compose.yaml | 13 +++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 backend/compose.yaml diff --git a/README.md b/README.md index 92aef2a..f7c68a8 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Before you run the project, make sure that you have the following tools and soft - [Git](https://git-scm.com/downloads) - [Node.js](https://nodejs.org/en/download/) `v18.11.0+` - [NPM](https://www.npmjs.com/) (usually included with Node.js) -- SQL database +- Docker ### Installation @@ -31,13 +31,13 @@ To install the project on your computer, follow these steps: 1. Clone the repository to your local machine. ```bash - git clone https://github.com/TonyMckes/conduit-realworld-example-app.git + git clone https://github.com/Toopemus/conduit-realworld-e2e-testing.git ``` 2. Navigate to the project directory. ```bash - cd conduit-realworld-example-app + cd conduit-realworld-e2e-testing ``` 3. Install project dependencies by running the command: @@ -49,9 +49,9 @@ To install the project on your computer, follow these steps: ### Configuration 1. Create a `.env` file in the root directory of the project -2. Add the required environment variables as specified in the [`.env.example`](backend/.env.example) file -3. (Optional) update the Sequelize configuration parameters in the [`config.js`](backend/config/config.js) file -4. If you are **not** using PostgreSQL, you may also have to install the driver for your database: +2. Copy the environment variables as specified in the [`.env.example`](backend/.env.example) file +3. ~~(Optional) update the Sequelize configuration parameters in the [`config.js`](backend/config/config.js) file~~ +4. ~~If you are **not** using PostgreSQL, you may also have to install the driver for your database:~~
Use one of the following commands to install:
@@ -75,7 +75,12 @@ To install the project on your computer, follow these steps: 5. Create database specified by configuration by executing - > :warning: Please, make sure you have already created a superuser for your database. + > You should have docker engine running. In most cases this means you need to start the Docker Desktop app + + ```bash + # spin up the database in backend/ + docker compose up + ``` ```bash npm run sqlz -- db:create diff --git a/backend/.env.example b/backend/.env.example index b12220e..fcba202 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -3,19 +3,19 @@ PORT=3001 JWT_KEY=supersecretkey_example ## Development Database -DEV_DB_USERNAME=root -DEV_DB_PASSWORD=null +DEV_DB_USERNAME=test +DEV_DB_PASSWORD=password DEV_DB_NAME=database_development DEV_DB_HOSTNAME=127.0.0.1 -DEV_DB_DIALECT=mysql +DEV_DB_DIALECT=postgres DEV_DB_LOGGGIN=true ## Testing Database -TEST_DB_USERNAME=root -TEST_DB_PASSWORD=null +TEST_DB_USERNAME=test +TEST_DB_PASSWORD=password TEST_DB_NAME=database_testing TEST_DB_HOSTNAME=127.0.0.1 -TEST_DB_DIALECT=mysql +TEST_DB_DIALECT=postgres TEST_DB_LOGGGIN=true ## Production Database @@ -23,5 +23,5 @@ PROD_DB_USERNAME=root PROD_DB_PASSWORD=null PROD_DB_NAME=database_production PROD_DB_HOSTNAME=127.0.0.1 -PROD_DB_DIALECT=mysql -PROD_DB_LOGGGIN=false \ No newline at end of file +PROD_DB_DIALECT=postgres +PROD_DB_LOGGGIN=false diff --git a/backend/compose.yaml b/backend/compose.yaml new file mode 100644 index 0000000..4620b3c --- /dev/null +++ b/backend/compose.yaml @@ -0,0 +1,13 @@ +version: "1" +volumes: + psql: +services: + psql: + image: postgres # latest version + environment: + POSTGRES_USER: ${TEST_DB_USERNAME} + POSTGRES_PASSWORD: ${TEST_DB_PASSWORD} # ONLY in development ! + # volumes: + # - psql:/var/lib/postgresql/data # save data between restarts + ports: + - 5432:5432 From 5c53c57c51ca33faa1a674b1c0407eece0c467e3 Mon Sep 17 00:00:00 2001 From: RoopeK <35376295+Toopemus@users.noreply.github.com> Date: Sat, 10 Feb 2024 17:06:30 +0200 Subject: [PATCH 02/13] install cypress and init some boilerplate tests --- README.md | 6 +- cypress.config.js | 9 + cypress/e2e/1-getting-started/todo.cy.js | 143 + cypress/e2e/2-advanced-examples/actions.cy.js | 299 ++ .../e2e/2-advanced-examples/aliasing.cy.js | 39 + .../e2e/2-advanced-examples/assertions.cy.js | 176 ++ .../e2e/2-advanced-examples/connectors.cy.js | 98 + cypress/e2e/2-advanced-examples/cookies.cy.js | 118 + .../e2e/2-advanced-examples/cypress_api.cy.js | 185 ++ cypress/e2e/2-advanced-examples/files.cy.js | 85 + .../e2e/2-advanced-examples/location.cy.js | 32 + cypress/e2e/2-advanced-examples/misc.cy.js | 104 + .../e2e/2-advanced-examples/navigation.cy.js | 56 + .../network_requests.cy.js | 163 ++ .../e2e/2-advanced-examples/querying.cy.js | 114 + .../spies_stubs_clocks.cy.js | 201 ++ cypress/e2e/2-advanced-examples/storage.cy.js | 110 + .../e2e/2-advanced-examples/traversal.cy.js | 121 + .../e2e/2-advanced-examples/utilities.cy.js | 108 + .../e2e/2-advanced-examples/viewport.cy.js | 58 + cypress/e2e/2-advanced-examples/waiting.cy.js | 30 + cypress/e2e/2-advanced-examples/window.cy.js | 22 + cypress/fixtures/example.json | 5 + cypress/support/commands.js | 25 + cypress/support/e2e.js | 20 + package-lock.json | 2478 ++++++++++++++++- package.json | 10 +- 27 files changed, 4725 insertions(+), 90 deletions(-) create mode 100644 cypress.config.js create mode 100644 cypress/e2e/1-getting-started/todo.cy.js create mode 100644 cypress/e2e/2-advanced-examples/actions.cy.js create mode 100644 cypress/e2e/2-advanced-examples/aliasing.cy.js create mode 100644 cypress/e2e/2-advanced-examples/assertions.cy.js create mode 100644 cypress/e2e/2-advanced-examples/connectors.cy.js create mode 100644 cypress/e2e/2-advanced-examples/cookies.cy.js create mode 100644 cypress/e2e/2-advanced-examples/cypress_api.cy.js create mode 100644 cypress/e2e/2-advanced-examples/files.cy.js create mode 100644 cypress/e2e/2-advanced-examples/location.cy.js create mode 100644 cypress/e2e/2-advanced-examples/misc.cy.js create mode 100644 cypress/e2e/2-advanced-examples/navigation.cy.js create mode 100644 cypress/e2e/2-advanced-examples/network_requests.cy.js create mode 100644 cypress/e2e/2-advanced-examples/querying.cy.js create mode 100644 cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js create mode 100644 cypress/e2e/2-advanced-examples/storage.cy.js create mode 100644 cypress/e2e/2-advanced-examples/traversal.cy.js create mode 100644 cypress/e2e/2-advanced-examples/utilities.cy.js create mode 100644 cypress/e2e/2-advanced-examples/viewport.cy.js create mode 100644 cypress/e2e/2-advanced-examples/waiting.cy.js create mode 100644 cypress/e2e/2-advanced-examples/window.cy.js create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/support/commands.js create mode 100644 cypress/support/e2e.js diff --git a/README.md b/README.md index f7c68a8..e7fa4ad 100644 --- a/README.md +++ b/README.md @@ -113,12 +113,14 @@ To run the project, follow these steps: #### Running Tests -To run tests, simply run the following command: +To start e2e-testing, simply run the tool. ```bash -npm run test +npm run cypress:open ``` +You can find some cypress example tests in `cypress/e2e/` to learn from. + #### Production The following command will build the production version of the app: diff --git a/cypress.config.js b/cypress.config.js new file mode 100644 index 0000000..97f47c4 --- /dev/null +++ b/cypress.config.js @@ -0,0 +1,9 @@ +const { defineConfig } = require("cypress"); + +module.exports = defineConfig({ + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, +}); diff --git a/cypress/e2e/1-getting-started/todo.cy.js b/cypress/e2e/1-getting-started/todo.cy.js new file mode 100644 index 0000000..4768ff9 --- /dev/null +++ b/cypress/e2e/1-getting-started/todo.cy.js @@ -0,0 +1,143 @@ +/// + +// Welcome to Cypress! +// +// This spec file contains a variety of sample tests +// for a todo list app that are designed to demonstrate +// the power of writing tests in Cypress. +// +// To learn more about how Cypress works and +// what makes it such an awesome testing tool, +// please read our getting started guide: +// https://on.cypress.io/introduction-to-cypress + +describe('example to-do app', () => { + beforeEach(() => { + // Cypress starts out with a blank slate for each test + // so we must tell it to visit our website with the `cy.visit()` command. + // Since we want to visit the same URL at the start of all our tests, + // we include it in our beforeEach function so that it runs before each test + cy.visit('https://example.cypress.io/todo') + }) + + it('displays two todo items by default', () => { + // We use the `cy.get()` command to get all elements that match the selector. + // Then, we use `should` to assert that there are two matched items, + // which are the two default items. + cy.get('.todo-list li').should('have.length', 2) + + // We can go even further and check that the default todos each contain + // the correct text. We use the `first` and `last` functions + // to get just the first and last matched elements individually, + // and then perform an assertion with `should`. + cy.get('.todo-list li').first().should('have.text', 'Pay electric bill') + cy.get('.todo-list li').last().should('have.text', 'Walk the dog') + }) + + it('can add new todo items', () => { + // We'll store our item text in a variable so we can reuse it + const newItem = 'Feed the cat' + + // Let's get the input element and use the `type` command to + // input our new list item. After typing the content of our item, + // we need to type the enter key as well in order to submit the input. + // This input has a data-test attribute so we'll use that to select the + // element in accordance with best practices: + // https://on.cypress.io/selecting-elements + cy.get('[data-test=new-todo]').type(`${newItem}{enter}`) + + // Now that we've typed our new item, let's check that it actually was added to the list. + // Since it's the newest item, it should exist as the last element in the list. + // In addition, with the two default items, we should have a total of 3 elements in the list. + // Since assertions yield the element that was asserted on, + // we can chain both of these assertions together into a single statement. + cy.get('.todo-list li') + .should('have.length', 3) + .last() + .should('have.text', newItem) + }) + + it('can check off an item as completed', () => { + // In addition to using the `get` command to get an element by selector, + // we can also use the `contains` command to get an element by its contents. + // However, this will yield the