From c4f6a47b2610a2cc2e5c76f5a13f63f959e7035f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Odini?= Date: Wed, 8 May 2024 00:58:22 +0200 Subject: [PATCH] test: setup E2E tests with Cypress (#572) --- .github/workflows/tests.yml | 16 + CONTRIBUTING.md | 6 + README.md | 2 +- cypress.config.js | 16 + package.json | 7 +- src/components/PriceCard.vue | 2 +- src/components/PriceCountChip.vue | 2 +- src/components/ProductCard.vue | 4 +- src/components/ProductMissingChip.vue | 2 +- src/views/Home.vue | 4 +- tests/e2e/spec.cy.js | 51 + tests/fixtures/pitted_apricot_prices.json | 104 ++ tests/fixtures/prices.json | 624 ++++++++ tests/fixtures/product_3011360030498.json | 20 + .../product_3011360030498_prices.json | 73 + tests/fixtures/products.json | 208 +++ tests/support/commands.js | 25 + tests/support/e2e.js | 20 + yarn.lock | 1313 ++++++++++++++++- 19 files changed, 2487 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/tests.yml create mode 100644 cypress.config.js create mode 100644 tests/e2e/spec.cy.js create mode 100644 tests/fixtures/pitted_apricot_prices.json create mode 100644 tests/fixtures/prices.json create mode 100644 tests/fixtures/product_3011360030498.json create mode 100644 tests/fixtures/product_3011360030498_prices.json create mode 100644 tests/fixtures/products.json create mode 100644 tests/support/commands.js create mode 100644 tests/support/e2e.js diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000000..7e842dbf7f --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,16 @@ +name: End-to-end tests + +on: push + +jobs: + cypress-run: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + # Install npm dependencies, cache them correctly + # and run all Cypress tests + - name: Cypress run + uses: cypress-io/github-action@v6 + with: + start: yarn dev diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d014e7803e..78657dad9a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,3 +21,9 @@ We use the [yarn](https://yarnpkg.com/getting-started/install) for package manag ```sh yarn build ``` + +## Tests + +```sh +yarn test +``` diff --git a/README.md b/README.md index dd459fcf74..970353d7b0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Works with an Open Prices server, see https://github.com/openfoodfacts/open-pric ## Contribute -See [CONTRIBUTING.md](https://github.com/openfoodfacts/open-prices-frontend/blob/main/CONTRIBUTING.md) +See [CONTRIBUTING.md](https://github.com/openfoodfacts/open-prices-frontend/blob/master/CONTRIBUTING.md)

Weekly meetings

* see https://github.com/openfoodfacts/open-prices#weekly-meetings diff --git a/cypress.config.js b/cypress.config.js new file mode 100644 index 0000000000..9938981923 --- /dev/null +++ b/cypress.config.js @@ -0,0 +1,16 @@ +const { defineConfig } = require("cypress"); + +module.exports = defineConfig({ + e2e: { + specPattern: '**/*.cy.js', + fixturesFolder: 'tests/fixtures', + screenshotsFolder: 'tests/screenshots', + videosFolder: 'tests/videos', + downloadsFolder: 'tests/downloads', + supportFile: 'tests/support/e2e.js', + setupNodeEvents(on, config) { + // implement node event listeners here + }, + baseUrl: 'http://localhost:5173', + }, +}); diff --git a/package.json b/package.json index 68b8cbf742..ffd9d97a95 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,10 @@ "build": "vite build", "build-staging": "vite build --base=/app/ --mode preprod", "build-prod": "vite build --base=/app/ --mode prod", - "preview": "vite preview" + "preview": "vite preview", + "cy:open": "cypress open", + "cy:run": "cypress run", + "test": "start-server-and-test dev http://localhost:5173 cy:run" }, "dependencies": { "@intlify/unplugin-vue-i18n": "^2.0.0", @@ -33,7 +36,9 @@ "@vue/compiler-sfc": "^3.3.9", "autoprefixer": "^10.4.16", "cross-env": "^7.0.3", + "cypress": "^13.8.1", "postcss": "^8.4.31", + "start-server-and-test": "^2.0.3", "vite": "^4.5.0" }, "resolutions": { diff --git a/src/components/PriceCard.vue b/src/components/PriceCard.vue index 87f89f5ca3..cc3e1edcff 100644 --- a/src/components/PriceCard.vue +++ b/src/components/PriceCard.vue @@ -1,5 +1,5 @@ diff --git a/src/components/ProductCard.vue b/src/components/ProductCard.vue index c3caae8a70..a5477dd5b3 100644 --- a/src/components/ProductCard.vue +++ b/src/components/ProductCard.vue @@ -1,5 +1,5 @@