Skip to content

Commit

Permalink
feat: added cypress tests and ci (#14)
Browse files Browse the repository at this point in the history
* test: cypress setup and dropdown test

* test: cypress testing branch

* fix: update cypress version

remove error:
```
TSError: ⨯ Unable to compile TypeScript:
error TS5095: Option 'bundler' can only be used when 'module' is set to 'es2015' or later.
```

* fix: rebuild pnpm.lock

* chore: updated dependencies

* ci: updated ci to include cypress tests

* ci: fix for prettier step in lint job

---------

Co-authored-by: Pratik Borole <borolepratik@gmail.com>
  • Loading branch information
Lombardoc4 and borolepratik committed Jun 10, 2024
1 parent 5118975 commit 839d5b3
Show file tree
Hide file tree
Showing 16 changed files with 1,210 additions and 717 deletions.
16 changes: 15 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ module.exports = {
es2021: true,
node: true,
},
plugins: ['@typescript-eslint', 'simple-import-sort', 'unused-imports'],
plugins: [
'@typescript-eslint',
'simple-import-sort',
'unused-imports',
'cypress',
],
extends: [
'eslint:recommended',
'next',
Expand Down Expand Up @@ -77,6 +82,15 @@ module.exports = {
},
],
//#endregion //*======== Import Sort ===========

// #region //*========= Cypress files =========
'@typescript-eslint/no-namespace': [
'error',
{
allowDeclarations: true,
},
],
// #endregion //*========= Cypress files =========
},
globals: {
React: true,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

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

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Code Check
name: Code Lint and Test

on:
push:
Expand All @@ -8,19 +8,19 @@ on:

jobs:
lint:
name: ⬣ ESLint, ʦ TypeScript, 💅 Prettier
name: ⬣ ESLint, ʦ TypeScript, 💅 Prettier, ✅ Cypress
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: ⎔ Setup node
uses: actions/setup-node@v4
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8
with:
node-version: 21

- uses: pnpm/action-setup@v2
name: Install pnpm
- name: Install pnpm
uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598
with:
version: 8
run_install: true
Expand All @@ -33,3 +33,12 @@ jobs:

- name: 💅 Prettier check
run: pnpm format:check

- name: ✅ Cypress tests
uses: cypress-io/github-action@1b70233146622b69e789ccdd4f9452adc638d25a
with:
browser: chrome
build: pnpm build
component: true
start: pnpm start
wait-on: 'http://localhost:3000'
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.tabSize": 2,

"python.terminal.activateEnvironment": false,
// Tailwind CSS Autocomplete, add more if used in projects
"tailwindCSS.classAttributes": [
Expand Down
193 changes: 0 additions & 193 deletions .vscode/typescriptreact.code-snippets

This file was deleted.

13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,21 @@ This project is using [conventional commits](https://www.conventionalcommits.org

// TODO [cypress](https://www.cypress.io/)

> [!WARNING]
> Cypress does not officially support Next v14. If you enncounter any errors or issues please report them [here](https://github.com/Slick-Telemetry/frontend/issues)
- **Background**

- Cypress uses chai based assertions

- **Running Cypress**

- `pnpm run cypress:open`

## Deployment

// TODO [vercel](https://vercel.com/)

## Resources

Key tools in use: `daisy-ui`, `tailwindcss`, `react`, `nextjs`, `pnpm`
Key tools in use: `daisy-ui`, `tailwindcss`, `react`, `nextjs`, `pnpm`, `cypress`
10 changes: 10 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'cypress';

export default defineConfig({
component: {
devServer: {
framework: 'next',
bundler: 'webpack',
},
},
});
38 changes: 38 additions & 0 deletions cypress/component/Dropdown.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// /* eslint-disable simple-import-sort/imports */

import '@/app/globals.css';

import { Dropdown } from '@/app/ui/Dropdown';

describe('Dropdown.cy.tsx', () => {
const initialVal = 'Initial Val';
const options = ['Option 1', 'Options2'];

it('dropdown selects first option', () => {
const action = cy.spy().as('onDropdownChange');
cy.mount(<Dropdown value={initialVal} items={options} action={action} />);
cy.get('[data-cy="dropdown"]').click();
cy.get('[data-cy="dropdown-item"]').first().click();
cy.get('@onDropdownChange').should('have.been.calledWith', options[0]);
});

it('dropdown selects second option', () => {
const action = cy.spy().as('onDropdownChange');
cy.mount(<Dropdown value={initialVal} items={options} action={action} />);
cy.get('[data-cy="dropdown"]').click();
cy.get('[data-cy="dropdown-item"]').first().next().click();
cy.get('@onDropdownChange').should('have.been.calledWith', options[1]);
});

it('dropdown with no items and close dropdown', () => {
const action = cy.spy().as('onDropdownChange');
cy.mount(<Dropdown value={initialVal} items={[]} action={action} />);
cy.get('[data-cy="dropdown"]').click();
cy.get('[data-cy="dropdown-item"]').should('not.exist');
cy.get('@onDropdownChange').should('not.have.been.calledWith', options[0]);
cy.get('@onDropdownChange').should('not.have.been.calledWith', options[1]);

// Outside click
cy.get('body').click();
});
});
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": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Loading

0 comments on commit 839d5b3

Please sign in to comment.