From f8925dbfd6186cbc8c09eda1b2c85d6b48996296 Mon Sep 17 00:00:00 2001 From: Walmyr Filho Date: Mon, 13 Sep 2021 18:35:48 +0200 Subject: [PATCH] Alternative to using fixtures --- .gitignore | 1 - cypress.json | 1 + cypress/fixtures/example.json | 164 ---------------------- cypress/integration/hackerStories.spec.js | 18 +-- cypress/support/commands.js | 8 +- 5 files changed, 14 insertions(+), 178 deletions(-) delete mode 100644 cypress/fixtures/example.json diff --git a/.gitignore b/.gitignore index 72613da..702b7c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .DS_Store cypress.env.json -cypress/fixtures/stories.json cypress/screenshots/ cypress/videos/ node_modules/ \ No newline at end of file diff --git a/cypress.json b/cypress.json index ab4e7f5..7cfa028 100644 --- a/cypress.json +++ b/cypress.json @@ -1,4 +1,5 @@ { "baseUrl": "https://wlsf82-hacker-stories.web.app/", + "fixturesFolder": false, "pluginsFile": false } diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json deleted file mode 100644 index 3a884ae..0000000 --- a/cypress/fixtures/example.json +++ /dev/null @@ -1,164 +0,0 @@ -{ - "hits": [ - { - "title": "explicabo quidem qui", - "url": "https://shanny.org", - "author": "Ericka Reinger", - "num_comments": "20903", - "points": "23417", - "objectID": "754c5ee6-ae49-4796-8be7-7cf3a065e7de" - }, - { - "title": "velit ut minus", - "url": "https://luciano.org", - "author": "Ally Kutch", - "num_comments": "14775", - "points": "30964", - "objectID": "76752051-ebf3-40fa-808a-2b1e86d05967" - }, - { - "title": "illo deleniti nihil", - "url": "http://alfonzo.biz", - "author": "Lori Marks", - "num_comments": "31675", - "points": "50555", - "objectID": "cd26cbb5-295e-4ce4-8370-708459db1f52" - }, - { - "title": "deleniti ipsa eveniet", - "url": "https://erik.info", - "author": "Trycia Kessler", - "num_comments": "66965", - "points": "90801", - "objectID": "c5fade2c-6cce-41fc-8429-9bd62d3a113a" - }, - { - "title": "laboriosam ullam debitis", - "url": "http://jude.net", - "author": "Efrain Ernser", - "num_comments": "15400", - "points": "76726", - "objectID": "36971674-aae6-4464-a904-d120a54a369f" - }, - { - "title": "rerum sed magni", - "url": "http://ceasar.name", - "author": "Myra Heaney", - "num_comments": "75655", - "points": "22012", - "objectID": "f693a57d-75f9-4f72-9f44-fc93ad73aeb6" - }, - { - "title": "sit et ut", - "url": "https://floyd.net", - "author": "Anna Hayes", - "num_comments": "94535", - "points": "94620", - "objectID": "75fcc3a4-4316-4c95-a680-4af7de9aaa13" - }, - { - "title": "sit velit expedita", - "url": "https://francisco.biz", - "author": "Margaret Kovacek", - "num_comments": "30563", - "points": "20906", - "objectID": "7cdb78fd-f709-4648-b4e5-64cde259b6ed" - }, - { - "title": "consequuntur illo iure", - "url": "http://diego.name", - "author": "Elton Ondricka", - "num_comments": "37772", - "points": "86031", - "objectID": "74f43b1d-49f5-4093-86ca-4ca38f499111" - }, - { - "title": "error enim necessitatibus", - "url": "https://tamia.biz", - "author": "Terrell Ondricka", - "num_comments": "66101", - "points": "74754", - "objectID": "81c799b1-a23e-40fa-b1ce-cb5fa2d7dd57" - }, - { - "title": "quae exercitationem omnis", - "url": "http://magdalen.info", - "author": "Pearl Cruickshank", - "num_comments": "89344", - "points": "59089", - "objectID": "93ad971f-d569-4f87-a415-09a70a33f250" - }, - { - "title": "pariatur officia minima", - "url": "http://jairo.biz", - "author": "Mose Hoppe", - "num_comments": "65877", - "points": "55739", - "objectID": "a931201b-aad1-4f5e-aeae-7850bd1a865a" - }, - { - "title": "deserunt ut minus", - "url": "https://adan.info", - "author": "Thomas Lueilwitz", - "num_comments": "45130", - "points": "37752", - "objectID": "83829fd2-8ad6-44b4-babd-fc670fb3869c" - }, - { - "title": "veritatis tenetur consequuntur", - "url": "http://kailee.net", - "author": "Josefina Goldner", - "num_comments": "85740", - "points": "80780", - "objectID": "acc329d9-13d0-4a24-9d54-c29609ad74a1" - }, - { - "title": "sit maxime hic", - "url": "https://terry.biz", - "author": "Darwin Sawayn", - "num_comments": "50470", - "points": "31234", - "objectID": "b0577ca1-a471-4c8c-999d-bd36f0bc35f5" - }, - { - "title": "doloremque a quia", - "url": "https://mckenzie.org", - "author": "Jamarcus Crist", - "num_comments": "28114", - "points": "83578", - "objectID": "aa54f095-c709-4939-a101-4c2a0b5b929b" - }, - { - "title": "doloribus neque sequi", - "url": "https://delmer.name", - "author": "Justus Rippin", - "num_comments": "95380", - "points": "61885", - "objectID": "bbfb50cd-3b69-47da-8712-fdd5a0b723b2" - }, - { - "title": "dolor ipsam odit", - "url": "https://joy.info", - "author": "Colby Beer", - "num_comments": "93683", - "points": "14466", - "objectID": "e948a599-04a3-4d6e-ad3a-3a7cceb3f5bb" - }, - { - "title": "praesentium sed ullam", - "url": "https://alyce.com", - "author": "Erling Schroeder", - "num_comments": "76600", - "points": "33894", - "objectID": "a8930bae-4d89-4480-b3f4-942b5c84c81c" - }, - { - "title": "dolor perferendis perferendis", - "url": "https://morgan.com", - "author": "Nathanial Leannon", - "num_comments": "12426", - "points": "8861", - "objectID": "a3abc0b2-4081-4dd4-8a77-ef382101fb5f" - } - ] -} diff --git a/cypress/integration/hackerStories.spec.js b/cypress/integration/hackerStories.spec.js index f3f5c90..b90a32c 100644 --- a/cypress/integration/hackerStories.spec.js +++ b/cypress/integration/hackerStories.spec.js @@ -1,15 +1,15 @@ describe('Hacker Stories', () => { beforeEach(() => { - cy.generateFixture() + cy.generateNStories(20).then(stories => { + cy.intercept( + 'GET', + '**/search?query=React&page=0', + { body: stories } + ).as('getStories') - cy.intercept( - 'GET', - '**/search?query=React&page=0', - { fixture: 'stories' } - ).as('getStories') - - cy.visit('/') - cy.wait('@getStories') + cy.visit('/') + cy.wait('@getStories') + }) }) it('renders 20 stories, then 19 when dismissing one', () => { cy.get('.item').should('have.length', 20) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 36b2a39..0182c01 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -1,8 +1,8 @@ -Cypress.Commands.add('generateFixture', () => { +Cypress.Commands.add('generateNStories', n => { const faker = require('faker') - cy.writeFile('cypress/fixtures/stories.json', { - 'hits': Cypress._.times(20, () => { + return { + 'hits': Cypress._.times(n, () => { return { 'title': `${faker.lorem.words(3)}`, 'url': `${faker.internet.url()}`, @@ -12,5 +12,5 @@ Cypress.Commands.add('generateFixture', () => { 'objectID': `${faker.datatype.uuid()}`, } }) - }) + } })