Skip to content

Commit d13d9c0

Browse files
committed
Fix Vite configuration and add regression tests
This commit addresses code review feedback and adds comprehensive tests: ## Vite Configuration Fixes 1. Remove redundant vite-env.d.ts - Already have vite/client in tsconfig.json types 2. Fix HTML file locations and asset paths - Move all entry point HTML files to frontend root - Update script paths to point to src/ - Ensures Vite outputs HTML to dist root, not dist/src/ 3. Use Vite's publicDir instead of custom plugin - Move (not copy) assets/ to public/assets/ - Move src/static/ contents to public/ - Move manifest.xml to public/ - Remove complex file-moving plugin - Configure publicDir: 'public' 4. Simplify vite.config.ts - Remove copyStaticAssets plugin - Keep only manifestPlugin for transformation ## Regression Tests Added Added comprehensive test suites to prevent build issues: ### test-build-output.mjs - Verifies HTML files at dist root (not subdirectories) - Checks asset paths use absolute paths (/assets/) - Validates static files copied correctly - Tests manifest.xml transformation ### test-dev-server.mjs - Tests all HTML entry points accessible - Verifies static file serving - Checks asset file accessibility - Validates 404s for non-existent paths ### Test Commands - npm run test:build - Test build output - npm run test:dev-server - Test dev server (requires server running) - npm run test:vite - Full build + test See TESTING.md for detailed documentation. All tests passing ✅
1 parent 8dfb2db commit d13d9c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+396
-98
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This is a writing tools application consisting of two main components:
2020
- Build: `npm run build` (production) or `npm run build:dev` (development)
2121
- Lint: `npm run lint` or `npm run lint:fix`
2222
- Format: `npm run format` or `npm run style:fix` (lint + format)
23-
- Test: `npm run test`
23+
- Test: `npm run test` (Jest) or `npm run test:vite` (Vite build regression tests)
2424

2525
### Backend (`/backend`)
2626
- **Use `uv`** - NOT pip

frontend/TESTING.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Vite Build Regression Tests
2+
3+
This directory contains regression tests for the Vite build configuration to prevent issues that were caught during code review.
4+
5+
## Test Suites
6+
7+
### 1. Build Output Tests (`test-build-output.mjs`)
8+
9+
Tests the production build output to ensure:
10+
- ✅ HTML files are at `dist/` root (not `dist/src/`)
11+
- ✅ No HTML files remain in subdirectories
12+
- ✅ Asset paths in HTML use absolute paths (`/assets/...`)
13+
- ✅ Static files from `public/` are copied to `dist/` root
14+
- ✅ Assets directory structure is correct
15+
-`manifest.xml` exists and is properly transformed
16+
17+
**Run:** `npm run test:build`
18+
19+
**When to run:** After any changes to `vite.config.ts` or build process
20+
21+
### 2. Dev Server Tests (`test-dev-server.mjs`)
22+
23+
Tests the development server to ensure:
24+
- ✅ HTML entry points are accessible at root paths
25+
- ✅ Static files from `public/` are served correctly
26+
- ✅ Asset files are accessible at `/assets/`
27+
- ✅ Non-existent paths return 404
28+
- ✅ Files that should NOT exist (like `/src/taskpane.html`) return 404
29+
30+
**Run:** `npm run test:dev-server`
31+
32+
**Prerequisites:** Dev server must be running (`npm run dev-server`)
33+
34+
### 3. Combined Test (`test:vite`)
35+
36+
Runs a full build and tests the output.
37+
38+
**Run:** `npm run test:vite`
39+
40+
## Issues These Tests Prevent
41+
42+
### Issue 1: HTML Files in Wrong Location
43+
**Problem:** HTML files were output to `dist/src/` instead of `dist/` root, causing 404s.
44+
45+
**Test:** Build Output Test #1, #2
46+
47+
**How:** Verifies all HTML files exist at dist root and no HTML files exist in subdirectories.
48+
49+
### Issue 2: Broken Asset Paths
50+
**Problem:** When HTML files were manually moved, relative asset paths broke (e.g., `../assets/...` became incorrect).
51+
52+
**Test:** Build Output Test #3
53+
54+
**How:** Parses HTML files to verify asset paths use absolute paths (`/assets/...`).
55+
56+
### Issue 3: Static Files Not Copied
57+
**Problem:** Before using `publicDir`, static files weren't copied correctly.
58+
59+
**Test:** Build Output Test #4
60+
61+
**How:** Verifies all static files from `public/` exist in `dist/`.
62+
63+
### Issue 4: Dev Server Path Issues
64+
**Problem:** Dev server wasn't serving files at expected paths.
65+
66+
**Test:** Dev Server Tests #1-4
67+
68+
**How:** Makes HTTP requests to verify all endpoints return correct status codes.
69+
70+
## CI Integration
71+
72+
Add to your CI pipeline:
73+
74+
```yaml
75+
- name: Build and Test
76+
run: |
77+
cd frontend
78+
npm install
79+
npm run test:vite
80+
```
81+
82+
## Local Development
83+
84+
Before committing changes to Vite config:
85+
86+
```bash
87+
# Build and test
88+
npm run test:vite
89+
90+
# Or test individually
91+
npm run build
92+
npm run test:build
93+
94+
# For dev server tests (in separate terminal)
95+
npm run dev-server
96+
npm run test:dev-server
97+
```
98+
99+
## Adding New Tests
100+
101+
When adding new entry points or changing the build structure:
102+
103+
1. Add new test cases to `test-build-output.mjs` or `test-dev-server.mjs`
104+
2. Run tests to verify they fail without your changes
105+
3. Implement your changes
106+
4. Verify tests pass
107+
5. Commit both changes and updated tests
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
</head>
1818

1919
<body>
20-
<script type="module" src="./commands.ts"></script>
20+
<script type="module" src="./src/commands/commands.ts"></script>
2121
</body>
2222
</html>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323

2424
<body>
2525
<div id="container"></div>
26-
<script type="module" src="./index.tsx"></script>
26+
<script type="module" src="./src/editor/index.tsx"></script>
2727
</body>
2828
</html>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
<body>
1313
<div id="container"></div>
14-
<script type="module" src="./index.tsx"></script>
14+
<script type="module" src="./src/logs/index.tsx"></script>
1515
</body>
1616
</html>

frontend/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
"style": "npm run lint && npm run format:check",
4040
"style:fix": "npm run lint:fix && npm run format",
4141
"prepare": "husky",
42-
"test": "jest"
42+
"test": "jest",
43+
"test:build": "node test-build-output.mjs",
44+
"test:dev-server": "node test-dev-server.mjs",
45+
"test:vite": "npm run build && npm run test:build"
4346
},
4447
"dependencies": {
4548
"@auth0/auth0-react": "^2.2.4",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<body class="ms-font-m ms-Fabric">
2020
<div id="container"></div>
21-
<script type="module" src="./popup.tsx"></script>
21+
<script type="module" src="./src/popup.tsx"></script>
2222
</body>
2323

2424
</html>
File renamed without changes.

0 commit comments

Comments
 (0)