Skip to content

Commit

Permalink
Add cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkxf committed Jun 25, 2024
1 parent 672c77b commit 4b4e26c
Show file tree
Hide file tree
Showing 10 changed files with 1,641 additions and 10 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.pull_request.url }}
cancel-in-progress: true

jobs:
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Cypress run
uses: cypress-io/github-action@v6

with:
browser: "chrome"
build: npm run build
start: npm run start
wait-on: "http://localhost:3000"
9 changes: 9 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
30 changes: 30 additions & 0 deletions cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe("spec", () => {
it("subscribes to a custom feed", () => {
cy.visit("http://localhost:3000");
cy.contains("New feed").click({ force: true });

cy.contains("Subscribe");
cy.get("#url").type("https://www.mikefrancis.dev/rss.xml");
cy.get("button").contains("Subscribe").click({ force: true });
cy.get("#feed-items li", { timeout: 10000 }).first().click({ force: true });
});

it("subscribes to a random feed", () => {
cy.visit("http://localhost:3000");
cy.contains("New feed").click({ force: true });

cy.contains("Subscribe");
cy.get("button").contains("Add random feed").click({ force: true });
cy.get("#feed-items li", { timeout: 10000 }).first().click({ force: true });
});

it("displays an error when trying to subscribe to an invalid feed", () => {
cy.visit("http://localhost:3000");
cy.contains("New feed").click({ force: true });

cy.contains("Subscribe");
cy.get("#url").type("lol");
cy.get("button").contains("Subscribe").click({ force: true });
cy.contains("Error", { timeout: 10000 });
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts 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) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts 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 4b4e26c

Please sign in to comment.