-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up Cypress and configure local test environment (#829)
* Testing : Intial cypress setup * Added test for card component * Added dummy e2e tests * setup cypress code coverage * Improved code coverage for card component to 100% * updated eslint & fixes error after merge conflict * cleanup(ci.yml): removed build job from ci.yml * Add test and coverage job
- Loading branch information
Showing
15 changed files
with
2,204 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
|
||
# testing | ||
/coverage | ||
/.nyc_output | ||
coverage.json | ||
|
||
# next.js | ||
/.next/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { defineConfig } from 'cypress'; | ||
|
||
export default defineConfig({ | ||
component: { | ||
devServer: { | ||
framework: 'next', | ||
bundler: 'webpack', | ||
}, | ||
specPattern: 'cypress/components/**/*.cy.{js,jsx,ts,tsx}', | ||
setupNodeEvents(on, config) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('@cypress/code-coverage/task')(on, config); | ||
return config; | ||
}, | ||
}, | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('@cypress/code-coverage/task')(on, config); | ||
return config; | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
import Card from '../../components/Card'; | ||
import { CardProps } from '../../components/Card'; | ||
|
||
const RoadmapProps: CardProps = { | ||
icon: '/icons/roadmap.svg', | ||
title: 'Roadmap', | ||
body: 'Explore our exciting plans and upcoming milestones. 🚀', | ||
headerSize: 'large', | ||
bodyTextSize: 'medium', | ||
link: 'https://github.com/orgs/json-schema-org/discussions/427', | ||
}; | ||
|
||
describe('Card Component', () => { | ||
// Render the Roadmap Card with default RoadmapProps | ||
it('should render Roadmap Card correctly', () => { | ||
cy.mount(<Card {...RoadmapProps} />); | ||
cy.get('[data-test="card-image"]').should('not.exist'); | ||
cy.get('[data-test="card-icon"]').should( | ||
'have.attr', | ||
'src', | ||
RoadmapProps.icon, | ||
); | ||
cy.get('[data-test="card-title"]').should('have.text', RoadmapProps.title); | ||
cy.get('[data-test="card-body"]').should('have.text', RoadmapProps.body); | ||
cy.get('[data-test="card-read-more"]').should('have.text', 'Read More'); | ||
cy.get('[data-test="card-link"]').should( | ||
'have.attr', | ||
'href', | ||
RoadmapProps.link, | ||
); | ||
cy.get('[data-test="card-title"]').should('have.class', 'text-[2rem]'); | ||
cy.get('[data-test="card-body"]').should('have.class', 'text-[1rem]'); | ||
}); | ||
|
||
// Render the Roadmap card with default header and body sizes | ||
it('should render Roadmap card with default header and body sizes', () => { | ||
const missingSizes = { | ||
...RoadmapProps, | ||
headerSize: undefined, | ||
bodyTextSize: undefined, | ||
}; | ||
cy.mount(<Card {...missingSizes} />); | ||
cy.get('[data-test="card-title"]').should('have.class', 'text-[1.3rem]'); | ||
cy.get('[data-test="card-body"]').should('have.class', 'text-[1rem]'); | ||
}); | ||
|
||
// Render the Roadmap card with extended body text | ||
it('should render Roadmap card with extended body text', () => { | ||
const extendedBody = { ...RoadmapProps, extended: true }; | ||
cy.mount(<Card {...extendedBody} />); | ||
cy.get('[data-test="card-body"]').find('span').should('exist'); | ||
}); | ||
|
||
// Render the Roadmap card with image | ||
it('should render Roadmap card with image', () => { | ||
const imageProps = { ...RoadmapProps, image: '/icons/roadmap.svg' }; | ||
cy.mount(<Card {...imageProps} />); | ||
cy.get('[data-test="card-image"]').should( | ||
'have.attr', | ||
'src', | ||
imageProps.image, | ||
); | ||
}); | ||
|
||
// Render the Roadmap Card with some missing props | ||
it('should render Roadmap card with some missing props correctly', () => { | ||
const missingProps = { ...RoadmapProps, icon: undefined, link: undefined }; | ||
cy.mount(<Card {...missingProps} />); | ||
cy.get('[data-test="card-icon"]').should('not.exist'); | ||
cy.get('[data-test="card-link"]').should('not.exist'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// describe('Homepage', () => { | ||
// it('should contains - Build more. Break less. Empower others.', () => { | ||
// cy.viewport(1280, 720); | ||
// cy.visit('http://localhost:3000'); | ||
// cy.contains(/Build more. Break less. Empower others./i); | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<title>Components App</title> | ||
<!-- Used by Next.js to inject CSS. --> | ||
<div id="__next_css__DO_NOT_USE__"></div> | ||
</head> | ||
<body> | ||
<div data-cy-root></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// *********************************************************** | ||
// This example support/component.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'; | ||
import '@cypress/code-coverage/support'; | ||
import { mount } from 'cypress/react18'; | ||
import '../../styles/globals.css'; | ||
|
||
// Augment the Cypress namespace to include type definitions for | ||
// your custom command. | ||
// Alternatively, can be defined in cypress/support/component.d.ts | ||
// with a <reference path="./component" /> at the top of your spec. | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace Cypress { | ||
interface Chainable { | ||
mount: typeof mount; | ||
} | ||
} | ||
} | ||
|
||
Cypress.Commands.add('mount', mount); | ||
|
||
// Example use: | ||
// cy.mount(<MyComponent />) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// *********************************************************** | ||
// 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'; | ||
import '@cypress/code-coverage/support'; |
Oops, something went wrong.