Skip to content

Commit

Permalink
TD-1 Add Cypress for testing locally and in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
brianzelip committed Sep 2, 2024
1 parent 4ca372a commit 7ef0095
Show file tree
Hide file tree
Showing 9 changed files with 2,110 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Cypress tests

on:
pull_request:
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true # runs 'bundle install'

- name: Set up Node.js
uses: actions/[email protected]
with:
node-version: '20'

- name: Cypress run
uses: cypress-io/github-action@v6 # runs 'npm ci'
with:
start: npm start
wait-on: 'http://localhost:4000'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/*/.DS_Store
_site
.jekyll-cache
node_modules
9 changes: 9 additions & 0 deletions cypress.config.js
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
}
}
});
41 changes: 41 additions & 0 deletions cypress/e2e/feedback.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const editBaseUrl = 'https://github.com/archivesspace/tech-docs/edit/master/';
const issueBaseUrl =
'https://github.com/archivesspace/tech-docs/issues/new?title=Problem+on+';

describe('Feedback', () => {
it('includes an edit this page on GitHub link on every page', () => {
let file = 'README.md';
cy.visit('http://localhost:4000/');
cy.get('a')
.contains('Edit this page on GitHub')
.should('have.attr', 'href', `${editBaseUrl}${file}`)
.children()
.should('have.text', file);

file = 'readme_develop.md';
cy.visit('http://localhost:4000/readme_develop');
cy.get('a')
.contains('Edit this page on GitHub')
.should('have.attr', 'href', `${editBaseUrl}${file}`)
.children()
.should('have.text', file);
});

it('includes a report issue on GitHub link on every page', () => {
let file = 'README.md';
cy.visit('http://localhost:4000/');
cy.get('a')
.contains('Report issue on GitHub')
.should('have.attr', 'href', `${issueBaseUrl}${file}`)
.children()
.should('have.text', file);

file = 'readme_develop.md';
cy.visit('http://localhost:4000/readme_develop');
cy.get('a')
.contains('Report issue on GitHub')
.should('have.attr', 'href', `${issueBaseUrl}${file}`)
.children()
.should('have.text', file);
});
});
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"
}
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 7ef0095

Please sign in to comment.