You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Migrate codebase from JavaScript to TypeScript (#255)
* Migrate codebase from JavaScript to TypeScript
- Convert all 7 source files (utils, parse, parseXml, junitXml, multiFiles, index, cli) to TypeScript
- Add shared type definitions in src/types.d.ts
- Add 91 unit tests using Vitest with V8 coverage (~91% statement coverage)
- Add CI workflow for format, lint, build, test and coverage badge
- Configure TypeScript, ESLint, Vitest, Prettier for TypeScript
- Bump version to 1.6.0
- Update dev dependencies to latest compatible versions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Address code review findings from Copilot, Cubic, and CodeRabbit
- Fix env var restoration in test (delete when originally undefined)
- Fix vacuous test assertions (parseXml skip-covered, parse branch coverage)
- Log xml2js parse errors instead of silently ignoring them
- Add testsuites structure guard to prevent crash on malformed XML
- Add permissions block to CI workflow
- Fix package.json main field to point to dist/index.js
- Fix onlyChnaged typo in parse.ts
- Remove redundant noImplicitAny from tsconfig (covered by strict)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CLAUDE.md
+52-14Lines changed: 52 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,50 +9,85 @@ pytest-coverage-comment is a GitHub Action that comments on pull requests with p
9
9
## Development Commands
10
10
11
11
### Build and Bundle
12
+
12
13
```bash
13
-
npm run build # Bundle the action with ncc into dist/index.js
14
-
npm run all # Run lint, format, and build in sequence
14
+
npm run build # Bundle the action with ncc (compiles TS + bundles) into dist/index.js
15
+
npm run all # Run typecheck, lint, format, test, and build in sequence
15
16
```
16
17
17
-
### Code Quality
18
+
### Type Checking and Code Quality
19
+
18
20
```bash
19
-
npm run lint # Run ESLint on src/**/*.js
21
+
npm run typecheck # Run tsc --noEmit (type-check only, no output)
22
+
npm run lint # Run ESLint on src/**/*.ts
20
23
npm run format # Format code with Prettier
21
24
npm run format-check # Check formatting without changing files
22
25
```
23
26
27
+
### Testing
28
+
29
+
```bash
30
+
npm test# Run Vitest tests (vitest run)
31
+
npm run test:watch # Run Vitest in watch mode
32
+
npm run test:coverage # Run tests with V8 coverage
33
+
```
34
+
24
35
### Version Management
36
+
25
37
```bash
26
38
npm run bump-version # Increment patch version
27
39
```
28
40
29
41
### Local Testing
30
-
The `src/cli.js` file contains a CLI tool for local testing of coverage parsing functionality. It can be run directly to test coverage report generation without GitHub Actions.
42
+
43
+
The `src/cli.ts` file contains a CLI tool for local testing of coverage parsing functionality. It can be run directly to test coverage report generation without GitHub Actions.
31
44
32
45
## Architecture Overview
33
46
34
-
The codebase is a Node.js GitHub Action with the following key components:
47
+
The codebase is a TypeScript GitHub Action with the following key components:
35
48
36
49
### Entry Points
37
-
-**src/index.js**: Main GitHub Action entry point that orchestrates the entire workflow
38
-
-**src/cli.js**: CLI utility for local testing and development
50
+
51
+
-**src/index.ts**: Main GitHub Action entry point that orchestrates the entire workflow
52
+
-**src/cli.ts**: CLI utility for local testing and development
53
+
54
+
### Type Definitions
55
+
56
+
-**src/types.d.ts**: All shared TypeScript interfaces (Options, CoverageLine, TotalLine, etc.)
39
57
40
58
### Core Parsing Modules
41
-
-**src/parse.js**: Parses pytest text coverage output (e.g., from `pytest --cov`)
42
-
-**src/parseXml.js**: Parses XML coverage reports (e.g., from `pytest --cov-report=xml`)
43
-
-**src/junitXml.js**: Parses JUnit XML test results for test statistics
59
+
60
+
-**src/parse.ts**: Parses pytest text coverage output (e.g., from `pytest --cov`)
61
+
-**src/parseXml.ts**: Parses XML coverage reports (e.g., from `pytest --cov-report=xml`)
62
+
-**src/junitXml.ts**: Parses JUnit XML test results for test statistics
44
63
45
64
### Supporting Modules
46
-
-**src/multiFiles.js**: Handles multiple coverage files (useful for monorepos)
47
-
-**src/utils.js**: Shared utilities for file operations, color determination, and GitHub API interactions
65
+
66
+
-**src/multiFiles.ts**: Handles multiple coverage files (useful for monorepos)
67
+
-**src/utils.ts**: Shared utilities for file operations, color determination, and GitHub API interactions
68
+
69
+
### Test Infrastructure
70
+
71
+
-**\_\_tests\_\_/setup.ts**: Global test setup with `spyCore` mocks for `@actions/core`
72
+
-**\_\_tests\_\_/\*.test.ts**: Vitest unit tests for each module (91 tests total)
73
+
- Uses `exportedForTesting` pattern to expose internal functions for testing
74
+
- Test fixtures in `data/` directory (pytest coverage txt, coverage xml, junit xml)
75
+
76
+
### Build System
77
+
78
+
- TypeScript is used for type-checking only (`noEmit: true` in tsconfig)
79
+
-`@vercel/ncc` compiles TS and bundles directly to `dist/index.js` in a single step
80
+
- No intermediate `lib/` or `outDir` needed
48
81
49
82
### Data Flow
83
+
50
84
1. Action receives coverage files (txt/xml) and JUnit XML as inputs
51
85
2. Parsers extract coverage percentages, file details, and test statistics
52
86
3. HTML report is generated with file links pointing to the repository
53
87
4. Comment is created/updated on PR using GitHub API with coverage badge and collapsible report
54
88
55
89
### GitHub Integration
90
+
56
91
- Uses `@actions/core` for input/output handling
57
92
- Uses `@actions/github` for API interactions (creating/updating PR comments)
58
93
- Supports comment watermarking to update existing comments instead of creating duplicates
@@ -63,4 +98,7 @@ The codebase is a Node.js GitHub Action with the following key components:
63
98
- Maximum comment length: 65,536 characters (GitHub limit)
64
99
- Supports filtering to show only changed files in the current commit
65
100
- Can skip files with 100% coverage from XML reports
66
-
- Handles both absolute and relative file paths for coverage inputs
101
+
- Handles both absolute and relative file paths for coverage inputs
102
+
- xml2js `parseString` is used synchronously via callback pattern (not async)
103
+
-`@actions/github` has ESM/CJS compatibility issues in test context — mock it with `vi.mock()` in tests
104
+
-`@actions/core` v3+ and `@actions/github` v9+ are pure ESM — incompatible with ncc's webpack CJS bundling. Must stay on `@actions/core` v2.x and `@actions/github` v8.x until ncc supports ESM or the project switches bundlers
0 commit comments