Skip to content

Commit d69dc95

Browse files
committed
add unit/integration/e2e testing
1 parent 9faebcf commit d69dc95

25 files changed

+9263
-2834
lines changed

.github/workflows/ui-development.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,35 @@ jobs:
4141
run: |
4242
cd ui
4343
npx husky run pre-commit
44+
45+
unit-tests:
46+
permissions:
47+
contents: "read"
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Check out code
51+
uses: actions/checkout@v3
52+
53+
- name: Install dependencies
54+
run: |
55+
cd ui
56+
npm ci
57+
58+
- name: Run unit tests
59+
run: make test-unit
60+
61+
integration-tests:
62+
permissions:
63+
contents: "read"
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Check out code
67+
uses: actions/checkout@v3
68+
69+
- name: Install dependencies
70+
run: |
71+
cd ui
72+
npm ci
73+
74+
- name: Run integration tests
75+
run: make test-integration

ui/.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
.vscode
2+
.vscode
3+
cypress.config.ts

ui/.eslintrc.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"env": {
33
"browser": true,
4-
"es6": true
4+
"es6": true,
5+
"jest": true
56
},
67
"extends": [
78
"eslint:recommended",
@@ -11,7 +12,7 @@
1112
"plugin:@typescript-eslint/recommended",
1213
"plugin:prettier/recommended"
1314
],
14-
"ignorePatterns": [".vscode"],
15+
"ignorePatterns": [".vscode", "jest.config.js"],
1516
"overrides": [
1617
{
1718
"files": ["*.mjs"],
@@ -30,7 +31,7 @@
3031
"project": "./tsconfig.json",
3132
"sourceType": "module"
3233
},
33-
"plugins": ["@typescript-eslint", "import", "no-secrets", "react"],
34+
"plugins": ["@typescript-eslint", "import", "jest", "no-secrets", "react"],
3435
"root": true,
3536
"rules": {
3637
"complexity": ["warn", { "max": 8 }],

ui/Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@ quality:
1313
style:
1414
@echo "Running styling";
1515
@# Auto fix any eslint issues
16-
npx eslint --fix $(CHECKDIRS)
16+
npx eslint --fix $(CHECKDIRS)
17+
18+
test-unit:
19+
@echo "Running unit tests";
20+
@# Run react tests
21+
npm run test:unit
22+
23+
test-integration:
24+
@echo "Running integration tests";
25+
@# Run react tests
26+
npm run test:integration

ui/cypress.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "cypress";
2+
3+
export default defineConfig({
4+
e2e: {
5+
setupNodeEvents(on, config) {
6+
// implement node event listeners here
7+
},
8+
},
9+
});

ui/cypress/e2e/homepage.cy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe('Check if text exists on the page', () => {
2+
it('should find the text on the page', () => {
3+
cy.visit('http://localhost:3000');
4+
cy.contains('GuideLLM').should('exist');
5+
});
6+
});

ui/cypress/support/commands.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }

ui/cypress/support/e2e.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands';
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

ui/jest.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const nextJest = require('next/jest');
2+
3+
const createJestConfig = nextJest({
4+
dir: './',
5+
});
6+
7+
const customJestConfig = {
8+
collectCoverage: false,
9+
collectCoverageFrom: ['src'],
10+
coverageDirectory: './.meta',
11+
coverageReporters: ['json-summary'],
12+
moduleFileExtensions: ['ts', 'tsx', 'js'],
13+
moduleNameMapper: {
14+
'^@/(.*)$': '<rootDir>/src/$1',
15+
},
16+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
17+
testEnvironment: 'jest-environment-jsdom',
18+
transform: {
19+
'^.+\\.(ts|tsx)$': 'ts-jest',
20+
},
21+
};
22+
23+
module.exports = createJestConfig(customJestConfig);

ui/jest.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

0 commit comments

Comments
 (0)