diff --git a/cypress.config.js b/cypress.config.js new file mode 100644 index 00000000..97f47c41 --- /dev/null +++ b/cypress.config.js @@ -0,0 +1,9 @@ +const { defineConfig } = require("cypress"); + +module.exports = defineConfig({ + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, +}); diff --git a/cypress/e2e/welcome.cy.js b/cypress/e2e/welcome.cy.js new file mode 100644 index 00000000..b661c0d2 --- /dev/null +++ b/cypress/e2e/welcome.cy.js @@ -0,0 +1,44 @@ +/* eslint-disable no-undef */ +describe('modal loads', () => { + it('passes', () => { + cy.visit('http://localhost:5173') + cy.get('.welcomeContent').should('be.visible') + }) +}) + +describe('discord link works', () => { + it('passes', () => { + cy.visit('http://localhost:5173') + cy.get('.welcomeNotice a').eq(0).invoke('removeAttr', 'target').click() + cy.url().then((url) => { + expect(url).to.include('discord.com') + }) + }) +}) + +describe('contribute link works', () => { + it('passes', () => { + cy.visit('http://localhost:5173') + cy.get('.welcomeNotice a').eq(1).invoke('removeAttr', 'target').click() + cy.url().then(url => { + expect(url).to.include('github.com') + }) + }) +}) + +describe('preview function works', () => { + it('passes', () => { + cy.visit('http://localhost:5173') + // does the preview button exist? + cy.get('.welcomeButtons button').eq(0).click() + + // did preview load correctly? + cy.get('.preview-mode').should('be.visible') + + // go back + cy.get('.preview-mode button').click() + + // are we back? + cy.get('.welcomeContent').should('be.visible') + }) +}) \ No newline at end of file diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 00000000..02e42543 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/support/commands.js b/cypress/support/commands.js new file mode 100644 index 00000000..66ea16ef --- /dev/null +++ b/cypress/support/commands.js @@ -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) => { ... }) \ No newline at end of file diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js new file mode 100644 index 00000000..3eaffffa --- /dev/null +++ b/cypress/support/e2e.js @@ -0,0 +1,17 @@ +// *********************************************************** +// 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' \ No newline at end of file diff --git a/package.json b/package.json index 66fb3a15..3de4fbc9 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@vitejs/plugin-react-swc": "^3.7.1", "adm-zip": "^0.5.16", "autoprefixer": "^10.4.20", + "cypress": "^13.17.0", "eslint": "^8.57.1", "eslint-config-prettier": "^9.1.0", "eslint-config-react-app": "^7.0.1", @@ -64,12 +65,13 @@ "yaml": "^2.5.1" }, "scripts": { + "build": "vite build", + "cy:open": "cypress open", "dev": "vite", "dev:host": "vite --host", - "build": "vite build", - "pretty": "prettier --write \"./**/*.{js,jsx,json,scss,css}\"", "lint": "eslint \"./src/**/*.{js,jsx}\" && stylelint \"./src/**/*.{scss,css}\"", "lint:fix": "eslint \"./src/**/*.{js,jsx}\" --fix && stylelint \"./src/**/*.{scss,css}\" --fix", - "postinstall": "husky" + "postinstall": "husky", + "pretty": "prettier --write \"./**/*.{js,jsx,json,scss,css}\"" } }