Skip to content

Commit 8ced984

Browse files
DaltheCowmarkurtz
andauthored
Testing tooling (#160)
Set up unit/integration/e2e testing with test coverage for unit/integration. Test coverage is not used, but can be pulled into a GH workflow when/if desired. Currently as there are very few tests written there is no threshold set in this repo. --------- Co-authored-by: Mark Kurtz <mark.j.kurtz@gmail.com>
1 parent db7b534 commit 8ced984

28 files changed

+9815
-3024
lines changed

src/ui/.eslintrc.json renamed to .eslintrc.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"env": {
33
"browser": true,
44
"es2024": true,
5+
"jest": true,
56
"node": true
67
},
78
"extends": [
@@ -12,25 +13,16 @@
1213
"plugin:@typescript-eslint/recommended",
1314
"plugin:prettier/recommended"
1415
],
15-
"ignorePatterns": [".vscode"],
16-
"overrides": [
17-
{
18-
"files": ["*.mjs"],
19-
"parser": "espree", // Use the default JavaScript parser for `.mjs` files
20-
"parserOptions": {
21-
"sourceType": "module"
22-
}
23-
}
24-
],
2516
"parser": "@typescript-eslint/parser",
2617
"parserOptions": {
2718
"ecmaFeatures": {
2819
"jsx": true
2920
},
3021
"ecmaVersion": 2024,
22+
"project": ["src/ui/tsconfig.json", "tsconfig.test.json", "tsconfig.cypress.json"],
3123
"sourceType": "module"
3224
},
33-
"plugins": ["@typescript-eslint", "import", "no-secrets", "react"],
25+
"plugins": ["@typescript-eslint", "import", "jest", "no-secrets", "react"],
3426
"root": true,
3527
"rules": {
3628
"complexity": ["warn", { "max": 8 }],
@@ -45,5 +37,5 @@
4537
"import/no-extraneous-dependencies": ["error"],
4638
"no-secrets/no-secrets": ["error", { "additionalRegexes": {}, "ignoreContent": [] }]
4739
},
48-
"settings": { "next": { "rootDir": ["src/ui/"] } }
40+
"settings": { "next": { "rootDir": ["src/ui/", "tests/ui/"] } }
4941
}

.github/workflows/development.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ jobs:
3131

3232
- name: Install dependencies
3333
run: npm ci
34-
working-directory: src/ui
3534

3635
- name: Run quality and typing checks
3736
run: npm run lint
38-
working-directory: src/ui
3937

4038
type-checks:
4139
runs-on: ubuntu-latest
@@ -63,11 +61,9 @@ jobs:
6361

6462
- name: Install dependencies
6563
run: npm ci
66-
working-directory: src/ui
6764

6865
- name: Run quality and typing checks
6966
run: npm run type-check
70-
working-directory: src/ui
7167

7268
precommit-checks:
7369
runs-on: ubuntu-latest
@@ -94,12 +90,10 @@ jobs:
9490
uses: actions/checkout@v3
9591

9692
- name: Install dependencies
97-
working-directory: src/ui
9893
run: npm ci
9994

10095
- name: Run pre-commit checks
10196
run: npx husky run pre-commit
102-
working-directory: src/ui
10397

10498
unit-tests:
10599
runs-on: ubuntu-latest
@@ -117,6 +111,20 @@ jobs:
117111
- name: Run unit tests
118112
run: tox -e test-unit -- -m "smoke or sanity"
119113

114+
ui-unit-tests:
115+
permissions:
116+
contents: "read"
117+
runs-on: ubuntu-latest
118+
steps:
119+
- name: Check out code
120+
uses: actions/checkout@v3
121+
122+
- name: Install dependencies
123+
run: npm ci
124+
125+
- name: Run unit tests
126+
run: npm run test:unit
127+
120128
integration-tests:
121129
runs-on: ubuntu-latest
122130
strategy:
@@ -133,6 +141,20 @@ jobs:
133141
- name: Run integration tests
134142
run: tox -e test-integration -- -m smoke
135143

144+
ui-integration-tests:
145+
permissions:
146+
contents: "read"
147+
runs-on: ubuntu-latest
148+
steps:
149+
- name: Check out code
150+
uses: actions/checkout@v3
151+
152+
- name: Install dependencies
153+
run: npm ci
154+
155+
- name: Run integration tests
156+
run: npm run test:integration
157+
136158
build:
137159
runs-on: ubuntu-latest
138160
strategy:

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,13 @@ yarn-error.log*
214214
src/ui/.vercel
215215

216216
# typescript
217-
src/ui/*.tsbuildinfo
217+
*.tsbuildinfo
218218
src/ui/next-env.d.ts
219219

220220
# Root-level UI config files that should be tracked
221221
!package.json
222222
!package-lock.json
223223
!.eslintrc.json
224224
!tsconfig.json
225+
!tsconfig.*.json
226+
!src/ui/public/manifest.json

.prettierignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# === Don't touch ===
2+
*.md
3+
*.mdx
4+
*.yaml
5+
*.yml
6+
7+
# === Skip all JSON …
8+
*.json
9+
10+
# === include relevant json ===
11+
!src/ui/**/*.json
12+
!tests/ui/**/*.json
13+
14+
# Root-level configs to format
15+
!/.eslintrc.json
16+
!/tsconfig*.json
17+
!/*.config.{js,ts}
18+
!/jest.setup.ts
File renamed without changes.

DEVELOPING.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,68 @@ Review the coverage report to confirm that your new code is adequately tested.
179179

180180
3. **Address Feedback**: Respond to any feedback from reviewers and make necessary changes.
181181

182+
## Developing the Web UI
183+
184+
The GuideLLM project includes a frontend UI located in `src/ui`, built using [Next.js](https://nextjs.org/). This section provides instructions for working on the UI.
185+
186+
### Getting Started
187+
188+
To start the local development server:
189+
190+
```bash
191+
npm run dev
192+
```
193+
194+
Then open [http://localhost:3000](http://localhost:3000) in your browser.
195+
196+
### Building for Production
197+
198+
To build the app for production (output in the `out` directory):
199+
200+
```bash
201+
npm run build
202+
```
203+
204+
### Running UI Tests
205+
206+
- **Unit tests**:
207+
208+
```bash
209+
npm run test:unit
210+
```
211+
212+
- **Integration tests**:
213+
214+
```bash
215+
npm run test:integration
216+
```
217+
218+
- **End-to-end tests** (using Cypress, ensure live dev server):
219+
220+
```bash
221+
npm run test:e2e
222+
```
223+
224+
### Code Quality and Styling
225+
226+
- **Fix styling issues**:
227+
228+
```bash
229+
npm run format
230+
```
231+
232+
- **Run ESLint checks**:
233+
234+
```bash
235+
npm run lint
236+
```
237+
238+
- **Run TS type checks**:
239+
240+
```bash
241+
npm run type-checks
242+
```
243+
182244
## Additional Resources
183245

184246
- [CONTRIBUTING.md](https://github.com/neuralmagic/guidellm/blob/main/CONTRIBUTING.md): Guidelines for contributing to the project.

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+
specPattern: 'tests/ui/cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
6+
supportFile: 'tests/ui/cypress/support/e2e.ts',
7+
baseUrl: 'http://localhost:3000', // optional, but good practice
8+
},
9+
});

jest.config.js

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

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)