Skip to content

Commit

Permalink
Upgrade cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicola committed Nov 30, 2023
1 parent c02eb9a commit 4f07809
Show file tree
Hide file tree
Showing 47 changed files with 1,326 additions and 1,025 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- name: Execute tests with defaults
run: |
npm run serve-and-test:parallel
- name: Execute only some tests
run: |
npm run serve-and-test:parallel:some
- name: Execute tests with spec reporter
run: |
npm run serve-and-test:parallel:spec
Expand Down
1 change: 0 additions & 1 deletion cypress-parallel
Submodule cypress-parallel deleted from 710dd1
13 changes: 13 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
video: false,
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
baseUrl: 'http://localhost:3000',
},
})
1 change: 0 additions & 1 deletion cypress.json

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
describe('Delete pizza', () => {
beforeEach(() => {
cy.server();
cy.fixture('pizzas').as('pizzasAPI');

cy.fixture('pizzas').then((pizzas) => {
cy.intercept({
method: 'DELETE',
url: '/api/pizzas/*'
}, pizzas).as('deletePizza');

cy.intercept({
method: 'GET',
url: '/api/pizzas'
}, pizzas).as('getPizzas');
});
cy.fixture('addTopping').as('addToppingAPI');
cy.route({
method: 'DELETE',
url: '/api/pizzas/*',
response: {}
}).as('deletePizza');
cy.route({
method: 'GET',
status: 200,
url: '/api/pizzas',
response: '@pizzasAPI'
}).as('getPizzas');

cy.visit('');
});
Expand All @@ -31,9 +30,6 @@ describe('Delete pizza', () => {
.contains('Delete Pizza')
.click();

cy.wait('@deletePizza')
.should(res => {
expect(res.status).to.equal(200);
});
cy.wait('@deletePizza').its('response.statusCode').should('eq', 200)
});
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
describe('Modify pizza', () => {
beforeEach(() => {
cy.server();
cy.fixture('pizzas').as('pizzasAPI');
cy.fixture('pizzas').then((pizzas) => {
cy.intercept({
method: 'GET',
url: '/api/pizzas'}, pizzas).as('getPizzas');
});

cy.fixture('addTopping').as('addToppingAPI');
cy.route({

cy.intercept({
method: 'PUT',
url: '/api/pizzas/*'
}).as('addTopping');
cy.route({
method: 'GET',
status: 200,
url: '/api/pizzas',
response: '@pizzasAPI'
}).as('getPizzas');

cy.visit('');
});
Expand All @@ -33,7 +32,7 @@ describe('Modify pizza', () => {
.click();

cy.wait('@addTopping')
.its('requestBody')
.its('request.body')
.then(res => {
expect(res.toppings).to.deep.equal([
{ id: 6, name: 'mushroom' },
Expand Down Expand Up @@ -62,7 +61,7 @@ describe('Modify pizza', () => {
.click();

cy.wait('@addTopping')
.its('requestBody')
.its('request.body')
.then(res => {
expect(res.toppings).to.deep.equal([
{ id: 10, name: 'pepperoni' },
Expand All @@ -88,7 +87,7 @@ describe('Modify pizza', () => {
.click();

cy.wait('@addTopping')
.its('requestBody')
.its('response.body')
.then(res => {
expect(res.toppings).to.deep.equal([
{ id: 10, name: 'pepperoni' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
describe('Create pizza', () => {
beforeEach(() => {
cy.server();
cy.fixture('pizzas').as('pizzasAPI');
cy.route({ method: 'POST', url: '/api/pizzas' }).as('postNewPizza');
cy.route({
method: 'GET',
status: 200,
url: '/api/pizzas',
response: '@pizzasAPI'
}).as('getPizzas');

cy.fixture('pizzas').then((pizzas) => {
cy.intercept('GET', '/api/pizzas', pizzas).as('getPizzas');
});

cy.intercept({ method: 'POST', url: '/api/pizzas' }).as('postNewPizza');

cy.visit('');
});
Expand Down Expand Up @@ -43,7 +40,7 @@ describe('Create pizza', () => {

// This test intentionally fail
cy.wait('@postNewPizza')
.its('requestBody')
.its('request.body')
.then((res) => {
expect(res.name).to.equal('My new pizza');
expect(res.toppings).to.deep.equal([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
describe('Pizza', () => {
beforeEach(() => {
cy.server();
cy.fixture('pizzas').as('pizzasAPI');
cy.route({
method: 'GET',
status: 200,
url: '/api/pizzas',
response: '@pizzasAPI'
}).as('getPizzas');
cy.fixture('pizzas').then((pizzas) => {
cy.intercept('GET', '/api/pizzas', pizzas).as('getPizzas');
});

cy.visit('');
});
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
describe('Delete pizza', () => {
beforeEach(() => {
cy.server();
cy.fixture('pizzas').as('pizzasAPI');

cy.fixture('pizzas').then((pizzas) => {
cy.intercept({
method: 'DELETE',
url: '/api/pizzas/*'
}, pizzas).as('deletePizza');

cy.intercept({
method: 'GET',
url: '/api/pizzas'
}, pizzas).as('getPizzas');
});
cy.fixture('addTopping').as('addToppingAPI');
cy.route({
method: 'DELETE',
url: '/api/pizzas/*',
response: {}
}).as('deletePizza');
cy.route({
method: 'GET',
status: 200,
url: '/api/pizzas',
response: '@pizzasAPI'
}).as('getPizzas');

cy.visit('');
});
Expand All @@ -31,9 +30,6 @@ describe('Delete pizza', () => {
.contains('Delete Pizza')
.click();

cy.wait('@deletePizza')
.should(res => {
expect(res.status).to.equal(200);
});
cy.wait('@deletePizza').its('response.statusCode').should('eq', 200)
});
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
describe('Modify pizza', () => {
beforeEach(() => {
cy.server();
cy.fixture('pizzas').as('pizzasAPI');
cy.fixture('pizzas').then((pizzas) => {
cy.intercept({
method: 'GET',
url: '/api/pizzas'}, pizzas).as('getPizzas');
});

cy.fixture('addTopping').as('addToppingAPI');
cy.route({

cy.intercept({
method: 'PUT',
url: '/api/pizzas/*'
}).as('addTopping');
cy.route({
method: 'GET',
status: 200,
url: '/api/pizzas',
response: '@pizzasAPI'
}).as('getPizzas');

cy.visit('');
});
Expand All @@ -33,7 +32,7 @@ describe('Modify pizza', () => {
.click();

cy.wait('@addTopping')
.its('requestBody')
.its('request.body')
.then(res => {
expect(res.toppings).to.deep.equal([
{ id: 6, name: 'mushroom' },
Expand Down Expand Up @@ -62,7 +61,7 @@ describe('Modify pizza', () => {
.click();

cy.wait('@addTopping')
.its('requestBody')
.its('request.body')
.then(res => {
expect(res.toppings).to.deep.equal([
{ id: 10, name: 'pepperoni' },
Expand All @@ -88,7 +87,7 @@ describe('Modify pizza', () => {
.click();

cy.wait('@addTopping')
.its('requestBody')
.its('response.body')
.then(res => {
expect(res.toppings).to.deep.equal([
{ id: 10, name: 'pepperoni' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
describe('Create pizza', () => {
beforeEach(() => {
cy.server();
cy.fixture('pizzas').as('pizzasAPI');
cy.route({ method: 'POST', url: '/api/pizzas' }).as('postNewPizza');
cy.route({
method: 'GET',
status: 200,
url: '/api/pizzas',
response: '@pizzasAPI'
}).as('getPizzas');

cy.fixture('pizzas').then((pizzas) => {
cy.intercept('GET', '/api/pizzas', pizzas).as('getPizzas');
});

cy.intercept({ method: 'POST', url: '/api/pizzas' }).as('postNewPizza');

cy.visit('');
});
Expand All @@ -35,23 +32,16 @@ describe('Create pizza', () => {
cy.get('.products__new a').click();

cy.get('.pizza-form__input').type('My new pizza');
cy.get('.pizza-toppings-item')
.contains('bacon')
.click();
cy.get('.pizza-toppings-item')
.contains('basil')
.click();
cy.get('.pizza-toppings-item')
.contains('tomato')
.click();

cy.get('button')
.contains('Create Pizza')
.click();
cy.get('.pizza-toppings-item').contains('bacon').click();
cy.get('.pizza-toppings-item').contains('basil').click();
cy.get('.pizza-toppings-item').contains('tomato').click();

cy.get('button').contains('Create Pizza').click();

// This test intentionally fail
cy.wait('@postNewPizza')
.its('requestBody')
.then(res => {
.its('request.body')
.then((res) => {
expect(res.name).to.equal('My new pizza');
expect(res.toppings).to.deep.equal([
{ id: 2, name: 'bacon' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
describe('Pizza', () => {
beforeEach(() => {
cy.server();
cy.fixture('pizzas').as('pizzasAPI');
cy.route({
method: 'GET',
status: 200,
url: '/api/pizzas',
response: '@pizzasAPI'
}).as('getPizzas');
cy.fixture('pizzas').then((pizzas) => {
cy.intercept('GET', '/api/pizzas', pizzas).as('getPizzas');
});

cy.visit('');
});
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
describe('Delete pizza', () => {
beforeEach(() => {
cy.server();
cy.fixture('pizzas').as('pizzasAPI');

cy.fixture('pizzas').then((pizzas) => {
cy.intercept({
method: 'DELETE',
url: '/api/pizzas/*'
}, pizzas).as('deletePizza');

cy.intercept({
method: 'GET',
url: '/api/pizzas'
}, pizzas).as('getPizzas');
});
cy.fixture('addTopping').as('addToppingAPI');
cy.route({
method: 'DELETE',
url: '/api/pizzas/*',
response: {}
}).as('deletePizza');
cy.route({
method: 'GET',
status: 200,
url: '/api/pizzas',
response: '@pizzasAPI'
}).as('getPizzas');

cy.visit('');
});
Expand All @@ -31,9 +30,6 @@ describe('Delete pizza', () => {
.contains('Delete Pizza')
.click();

cy.wait('@deletePizza')
.should(res => {
expect(res.status).to.equal(200);
});
cy.wait('@deletePizza').its('response.statusCode').should('eq', 200)
});
});
Loading

0 comments on commit 4f07809

Please sign in to comment.