Skip to content

Commit

Permalink
Merge pull request #3 from Invertus/feature/cypress
Browse files Browse the repository at this point in the history
feature / cypress
  • Loading branch information
tomas862 authored Nov 24, 2023
2 parents d13b354 + a2e0a6c commit ba34a43
Show file tree
Hide file tree
Showing 13 changed files with 3,707 additions and 8 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [pull_request]

jobs:
# similar job as below. Editing this one don't forget the one below
unit-system-tests:
unit-system-e2e-tests:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -27,4 +27,18 @@ jobs:
- run: sudo composer self-update 2.2.11
- run: cp .env.dist .env
- run: composer install
- run: make run-tests-github-actions ps_instance=${{ matrix.presta-versions }}
# integration tests
- run: make run-tests-github-actions ps_instance=${{ matrix.presta-versions }}
# e2e tests
- run: sudo apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb
- run: npm install
- run: npx cypress run

- name: Archive videos and screenshots
uses: actions/upload-artifact@v3
if: always()
with:
name: videos and screenshots
path: |
./cypress/videos
./cypress/screenshots
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
vendor
.idea
.env
.env
node_modules
composer.lock
cypress/videos/*
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
run-ps:
docker network create prestashop-net-${ps_instance} || true
docker run -ti --name some-mysql-${ps_instance} --network prestashop-net-${ps_instance} --platform ${platform} -e APP_ENV=ci -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_DATABASE=prestashop -p 4420:3306 -d mariadb:10.7.4
docker run -ti -v $(ROOT_DIR):/var/www/html/modules/prestashopdevcon --platform ${platform} --name some-prestashop-${ps_instance} --network prestashop-net-${ps_instance} -e DB_SERVER=some-mysql-${ps_instance} -e PS_INSTALL_AUTO=1 -e DB_NAME=prestashop -e PS_DOMAIN=localhost:8080 -e PS_FOLDER_ADMIN=admin1 -p 8080:80 -d prestashop/prestashop:${ps_instance}
docker run -ti -v $(ROOT_DIR):/var/www/html/modules/prestashopdevcon --platform ${platform} --name some-prestashop-${ps_instance} --network prestashop-net-${ps_instance} -e PS_DEV_MODE=1 -e DB_SERVER=some-mysql-${ps_instance} -e PS_INSTALL_AUTO=1 -e DB_NAME=prestashop -e PS_DOMAIN=localhost:8080 -e PS_FOLDER_ADMIN=admin1 -p 8080:80 -d prestashop/prestashop:${ps_instance}

install-module:
docker exec -i some-prestashop-${ps_instance} sh -c "cd /var/www/html && php bin/console prestashop:module install prestashopdevcon"

reset-module:
docker exec -i some-prestashop-${ps_instance} sh -c "cd /var/www/html && php bin/console prestashop:module reset prestashopdevcon"

run-wiremock:
docker run -d -ti --rm --name wiremock-${ps_instance} --network prestashop-net-${ps_instance} -v $(ROOT_DIR)/wiremock:/home/wiremock -p 8443:8080 wiremock/wiremock

change-permissions:
docker exec -i some-prestashop-${ps_instance} sh -c "chmod -R 777 /var/www/html"

run-integration-tests:
docker exec -i some-prestashop-${ps_instance} sh -c "cd /var/www/html && php bin/console prestashop:module install prestashopdevcon"
make install-module
make change-permissions
docker exec -i some-prestashop-${ps_instance} sh -c "cd /var/www/html/modules/prestashopdevcon && php vendor/bin/phpunit -c tests/phpunit.xml --testsuite Integration"

run-tests-github-actions:
Expand Down
11 changes: 11 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
video: true,
e2e: {
baseUrl: 'http://localhost:8080',
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
15 changes: 15 additions & 0 deletions cypress/e2e/cartPage.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe('Home page specs', () => {
beforeEach(function () {
cy.fixture('products').then((products) => {
this.products = products
})
})

it('cart page displays module information', function () {
cy.visit(this.products[0].url)
cy.get('.add-to-cart').click()
cy.get('#blockcart-modal').should('exist')
cy.visit('/cart')
cy.get('[data-cy="card-list"] li').should('exist')
})
})
10 changes: 10 additions & 0 deletions cypress/e2e/homePage.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe('Home page specs', () => {
it('home page loads', () => {
cy.request({
url: '/',
}).then((resp) => {
// redirect status code is 302
expect(resp.status).to.eq(200)
})
})
})
6 changes: 6 additions & 0 deletions cypress/fixtures/products.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"url": "/men/1-1-hummingbird-printed-t-shirt.html#/1-size-s/8-color-white",
"name": "HUMMINGBIRD PRINTED T-SHIRT"
}
]
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

0 comments on commit ba34a43

Please sign in to comment.